Category: Uncategorized

Restrict access to links in Global navigation panel

We often have to tighten the link access in AEM to limit user access to only few links, like only Sites, Experience fragments.

 

For AEM 6.3 touch UI, if you wish to revoke access on a link in Global Navigation Panel, you will have to follow 2 steps:

  1. Revoke access on the icon that displays the link on Global Navigation Panel
  2. Revoke access on the link resource, so that you cannot access the URL from browser directly.

The following table lists both the icon path and resource that renders a link (Example: Sites, Projects, Screens etc). You would have to revoke read access on relevant paths to meet the customer needs.

Column details:

  • “Browser URL in AEM” is the URL that AEM redirects you to, when you click an item in Global navigation panel
  • “Node rendering the menu link”: Revoking read access on these nodes will assure that you cannot directly access the corresponding “Browser URL in AEM”
  • “Global Navigation Panel Icon”: Revoking read access on these nodes will assure that you cannot access the Menu item in Global Navigation Panel

Navigation Tab

Link Browser URL in AEM Node rendering the menu link Global Navigation Panel Icon
Projects /projects.html/content/projects /libs/cq/core/content/projects /libs/cq/core/content/nav/projects
Sites /sites.html/content /libs/wcm/core/content/sites /libs/cq/core/content/nav/sites
Experience fragments /aem/experience-fragments.html/content/experience-fragments /libs/cq/experience-fragments/content/experience-fragments /libs/cq/core/content/nav/experiencefragments
Screens /screens.html/content/screens /libs/screens/dcc/content/main /libs/cq/core/content/nav/screens
Assets
Files /assets.html/content/dam /libs/dam/gui/content/assets /libs/cq/core/content/nav/assets/files
Collections /libs/dam/gui/content/collections.html/content/dam/collections /libs/dam/gui/content/collections /libs/cq/core/content/nav/assets/collections
Shared links /libs/dam/gui/content/assets/mylinkshares.html /libs/dam/gui/content/assets/mylinkshares /libs/cq/core/content/nav/assets/links
Templates /libs/dam/gui/content/idsprint/templates.html/content/dam/templates /libs/dam/gui/content/idsprint/templates /libs/cq/core/content/nav/assets/templates
Catalogs /libs/dam/gui/content/idsprint/catalogs.html/content/dam/catalogs /libs/dam/gui/content/idsprint/catalogs /libs/cq/core/content/nav/assets/catalogs
Content Services
Apps /aem/apps.html/content/mobileapps /libs/mobileapps/admin/content/catalog /libs/cq/core/content/nav/contentservices/apps
Forms
Forms & documents /aem/forms.html/content/dam/formsanddocuments /libs/fd/fm/gui/content/forms /libs/cq/core/content/nav/forms/formsanddocuments
Themes /aem/forms.html/content/dam/formsanddocuments-themes /libs/fd/fm/gui/content/forms /libs/cq/core/content/nav/forms/themes
Personalization
Activities /libs/cq/personalization/touch-ui/content/activities.html /libs/cq/personalization/touch-ui/content/activities /libs/cq/core/content/nav/personalization/activities
Offers /libs/cq/personalization/touch-ui/content/offers.html /libs/cq/personalization/touch-ui/content/offers /libs/cq/core/content/nav/personalization/offers
Audiences /libs/cq/personalization/touch-ui/content/audiences.html /libs/cq/personalization/touch-ui/content/audiences /libs/cq/core/content/nav/personalization/audiences
Commerce
Catalogs /aem/catalogs.html/content/catalogs /libs/commerce/gui/content/catalogs /libs/cq/core/content/nav/commerce/catalogs
Products /aem/products.html/etc/commerce/products /libs/commerce/gui/content/products /libs/cq/core/content/nav/commerce/products
Collections /aem/collections.html/etc/commerce/collections /libs/commerce/gui/content/collections /libs/cq/core/content/nav/commerce/collections
Orders /aem/orders.html/etc/commerce/orders /libs/commerce/gui/content/orders /libs/cq/core/content/nav/commerce/orders
Communities
Sites /communities/sites /libs/social/console/content-shell3/sites /libs/cq/core/content/nav/communities/sites
Moderation /communities/moderation.html/content/sites /libs/social/moderation/content-shell3/admindashboard /libs/cq/core/content/nav/communities/moderation
Reports /communities/reports /libs/social/reporting/content-shell3/reports$1 /libs/cq/core/content/nav/communities/reports
Resources /communities/resources /libs/social/enablement/content-shell3/enablement-sites /libs/cq/core/content/nav/communities/resources
Groups /communities/groups.html/content /libs/social/members/content-shell3/groups /libs/cq/core/content/nav/communities/groups
Members /communities/members.html/content /libs/social/members/content-shell3/members /libs/cq/core/content/nav/communities/members

Tools Tab

Link Browser URL in AEM Node rendering the menu link Global Navigation Panel Icon
General
CRXDE Lite /crx/de/index.jsp /libs/cq/core/content/nav/tools/general/crxdelite
Search Forms /libs/cq/core/content/tools/customsearch/searchfacetformlister.html /libs/cq/core/content/tools/customsearch/searchfacetformlister /libs/cq/core/content/nav/tools/general/customsearchfacets
Tagging /libs/cq/tagging/gui/content/tags.html/etc/tags /libs/cq/tagging/gui/content/tags/etc/tags /libs/cq/core/content/nav/tools/general/tagging
Templates /libs/wcm/core/content/sites/templates.html/conf /libs/wcm/core/content/sites/templates /libs/cq/core/content/nav/tools/general/templates
Translation Configuration /libs/cq/translation/translationrules/contexts.html /libs/cq/translation/translationrules/contexts /libs/cq/core/content/nav/tools/general/translationRules
Components /libs/wcm/core/content/sites/components.html /libs/wcm/core/content/sites/components /libs/cq/core/content/nav/tools/general/components
Configuration Browser /libs/granite/configurations/content/view.html/conf /libs/granite/configurations/content/view/conf /libs/cq/core/content/nav/tools/general/configuration-browser
Workflow
Models /libs/cq/workflow/admin/console/content/models.html/etc/workflow/models /libs/cq/workflow/admin/console/content/models/etc/workflow/models /libs/cq/core/content/nav/tools/workflow/models
Instances /libs/cq/workflow/admin/console/content/instances.html /libs/cq/workflow/admin/console/content/instances /libs/cq/core/content/nav/tools/workflow/instances
Launchers /libs/cq/workflow/admin/console/content/launchers.html /libs/cq/workflow/admin/console/content/launchers /libs/cq/core/content/nav/tools/workflow/launchers
Archive /libs/cq/workflow/admin/console/content/archive.html /libs/cq/workflow/admin/console/content/archive /libs/cq/core/content/nav/tools/workflow/archive
Failures /libs/cq/workflow/admin/console/content/failures.html /libs/cq/workflow/admin/console/content/failures /libs/cq/core/content/nav/tools/workflow/failures
Operations
Web Console /system/console/configMgr Please use the steps on following link to provide access:
https://sling.apache.org/documentation/bundles/web-console-extensions.html
/libs/cq/core/content/nav/tools/operations/webconsole
Testing /libs/granite/testing/hobbes.html /libs/granite/testing/hobbes /libs/cq/core/content/nav/tools/operations/testing
Configuration /miscadmin /libs/wcm/core/content/misc /libs/cq/core/content/nav/tools/operations/configuration
Backup /libs/granite/backup/content/admin.html /libs/granite/backup/content/admin /libs/cq/core/content/nav/tools/operations/backup
Maintenance /libs/granite/operations/content/maintenance.html /libs/granite/operations/content/maintenance /libs/cq/core/content/nav/tools/operations/maintenance
Health Reports /libs/granite/operations/content/healthreports/healthreportlist.html /libs/granite/operations/content/healthreports/healthreportlist /libs/cq/core/content/nav/tools/operations/healthreports
Monitoring /libs/granite/operations/content/monitoring/page.html /libs/granite/operations/content/monitoring/page /libs/cq/core/content/nav/tools/operations/monitoring
Diagnosis /libs/granite/operations/content/diagnosis.html /libs/granite/operations/content/diagnosis /libs/cq/core/content/nav/tools/operations/diagnosis
Sites
Blueprints /libs/wcm/msm/gui/content/blueprintconfig.html /libs/wcm/msm/gui/content/blueprintconfig /libs/cq/core/content/nav/tools/sites/blueprints
Launches /libs/launches/content/launches.html /libs/launches/content/launches /libs/cq/core/content/nav/tools/sites/launches
ContextHub /etc/cloudsettings.html /etc/cloudsettings /libs/cq/core/content/nav/tools/sites/contexthub
Assets
Assets in left menu /libs/cq/core/content/nav/tools/assets
Metadata Profiles /libs/dam/gui/content/processingprofilepage/metadataprofiles.html /libs/dam/gui/content/processingprofilepage/metadataprofiles /libs/dam/gui/content/nav/tools/assets/metadata
Asset Reports /libs/dam/gui/content/reports/reportspage.html /libs/dam/gui/content/reports/reportspage /libs/dam/gui/content/nav/tools/assets/assetreports
Metadata Schemas /libs/dam/gui/content/metadataschemaeditor/schemalist.html /libs/dam/gui/content/metadataschemaeditor/schemalist /libs/dam/gui/content/nav/tools/assets/metadataschemas
Desktop Tools for AEM http://www.adobe.com/go/desktop-tools-for-aem /libs/dam/gui/content/nav/tools/assets/desktop-tools
Insights Configuration /libs/dam/gui/content/assetinsights/wizard/configure.html /libs/dam/gui/content/assetinsights/wizard/configure /libs/dam/gui/content/nav/tools/assets/configwizard
Resources
Documentation https://www.adobe.com/go/aem6_3_docs_en /libs/cq/core/content/nav/tools/resources/documentation
Developer Resources https://www.adobe.com/go/aem6_3_dev_en /libs/cq/core/content/nav/tools/resources/dev
Deployment
Replication /etc/replication.html /etc/replication /libs/cq/core/content/nav/tools/deployment/replication
Distribution /libs/granite/distribution/content/distribution.html /libs/granite/distribution/content/distribution /libs/cq/core/content/nav/tools/deployment/distribution
Packages /crx/packmgr Please use the steps on following link to revoke access:
https://helpx.adobe.com/experience-manager/kb/LimitAccessCRXandCRXDE.html
/libs/cq/core/content/nav/tools/deployment/packages
Package Share /crx/packageshare Please use the steps on following link to revoke access:
https://helpx.adobe.com/experience-manager/kb/LimitAccessCRXandCRXDE.html
/libs/cq/core/content/nav/tools/deployment/packageshare
Topology /libs/granite/topology/content/view.html /libs/granite/topology/content/view /libs/cq/core/content/nav/tools/deployment/topology
Offloading /libs/granite/offloading/content/view.html /libs/granite/offloading/content/view /libs/cq/core/content/nav/tools/deployment/offloading
Cloud Services /libs/cq/core/content/tools/cloudservices.html /libs/cq/core/content/tools/cloudservices /libs/cq/core/content/nav/tools/deployment/cloudservices
Security
Users /libs/granite/security/content/useradmin.html /libs/granite/security/content/useradmin /libs/cq/core/content/nav/tools/security/users
Groups /libs/granite/security/content/groupadmin.html /libs/granite/security/content/groupadmin /libs/cq/core/content/nav/tools/security/groups
OAuth Clients /libs/granite/oauth/content/clients.html /libs/granite/oauth/content/clients /libs/cq/core/content/nav/tools/security/oauth
Permissions /useradmin /libs/cq/security/content/admin /libs/cq/core/content/nav/tools/security/permissions
Commerce
Payment Methods /libs/commerce/gui/content/paymentmethods.html/etc/commerce/payment-methods /libs/commerce/gui/content/paymentmethods/etc/commerce/payment-methods /libs/cq/core/content/nav/tools/commerce/payment-methods
Shipping Methods /libs/commerce/gui/content/shippingmethods.html/etc/commerce/shipping-methods /libs/commerce/gui/content/shippingmethods/etc/commerce/shipping-methods /libs/cq/core/content/nav/tools/commerce/shipping-methods
Communities
Storage Configuration /communities/admin/defaultsrp /libs/social/console/content-shell3/defaultSrpConfig /libs/cq/core/content/nav/tools/communities/storageconfig
Component Guide /editor.html/content/community-components/en.html /content/community-components/en /libs/cq/core/content/nav/tools/communities/componentguide
Community Functions /communities/communityfunctions /libs/social/console/content-shell3/communityfunctions /libs/cq/core/content/nav/tools/communities/communityfunctions
Group Templates /communities/communitygrouptemplates /libs/social/console/content-shell3/communitygrouptemplates /libs/cq/core/content/nav/tools/communities/communitygrouptemplates
Community Badges /communities/badges /libs/social/gamification/content-shell3/badges /libs/cq/core/content/nav/tools/communities/badges
Sites Templates /communities/communitysitetemplates /libs/social/console/content-shell3/communitysitetemplates /libs/cq/core/content/nav/tools/communities/communitysitetemplates
Advertisements

cURL execution from Java program

cURL is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNETand TFTP). The command is designed to work without user interaction.

With AEM, you can use cURL commands to modify repository, download json, access OSGi information etc.

Snippet to download a json file via cURL:

While majority of the AEM’s content information can be downloaded via HTTP connection,  cURL command can be used to download information from AEM’s OSGi console.

In the shared example, we have used cURL to get information about all the bundles installed in AEM.

Snippet to execute a cURL command:

The follwoing snippet contains acURL command that has been converted in a format to be used in Java snippet.

The cURL command used here is meant to lock page “/content/geometrixx/en/toolbar/contacts” :

curl -u admin:admin -X POST -F cmd=”lockPage” -F path=”/content/geometrixx/en/toolbar/contacts” -F “_charset_”=”utf-8” http://localhost:4502/bin/wcmcommand

For more samples of cURL commands, please refer to:

AEM Template Editor – Design configuration via policies

In template editors, policies are used to configure component design. Example: component’s design configurations,  allowed components for a container, mapping asset into components etc.

Configuring a template-editor’s policy is similar to a Static template’s design dialog. Following are the steps to define and access a new policy:

Step 1: Create policy configuration dialog

A component’s policy dialog is defined by adding a cq:design_dialog to the component. Example:

Capture1.PNG

Sample .content.xml for design dialog:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="My Title Component"
sling:resourceType="cq/gui/components/authoring/dialog">
    <content jcr:primaryType="nt:unstructured"
       sling:resourceType="granite/ui/components/coral/foundation/container">
        <items jcr:primaryType="nt:unstructured">
            <tabs jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/coral/foundation/tabs"
                maximized="{Boolean}true">
                <items jcr:primaryType="nt:unstructured">
                    <properties
                        jcr:primaryType="nt:unstructured"
                        jcr:title="Available Stage types"
                        sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"
                        margin="{Boolean}true">
                        <items jcr:primaryType="nt:unstructured">
                            <content
                                jcr:primaryType="nt:unstructured"
                                sling:resourceType="granite/ui/components/coral/foundation/container"
                                margin="{Boolean}false">
                                <items jcr:primaryType="nt:unstructured">
                                    <title
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
                                        fieldLabel="Title"
                                        name="./title"/>
                                </items>
                            </content>
                        </items>
                   </properties>
               </items>
            </tabs>
        </items>
    </content>
</jcr:root>

Step 2: Configuring policy

Once the design dialog is created:

  • Open the template in Structure mode.
  • Click on the component
  • Following button should now be available to configure the design properties.

Sprints.PNG

Policy Storage and sharing:

  • Policies are stored in following location by default:

/conf/project_name/settings/wcm/policies/component_name/policy_randomNumber

Policies can be also be stored in /apps or /libs folder. In this case the resource will be resolved in following preference order: /conf, /apps, /libs.

  • Please observe in the policy path, that policies are stored centrally for a project. This enables authors to share a design policy among multiple templates.
  • Template -> policy mapping is done by referring policy via:

cq:policy=/conf/project_name/settings/wcm/policies/component_name/policy_randomNumber

Capture.PNG

       At location:

    /conf/project_name/settings/wcm/templates/template-name/policies/jcr:content/root/component_name

Step 3: Accessing policy

A component’s policy configuration can be accessed by ContentPolicyManager. Sharing an example below:

import javax.annotation.PostConstruct;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import com.day.cq.wcm.api.policies.ContentPolicy;
import com.day.cq.wcm.api.policies.ContentPolicyManager;

@Model(adaptables = Resource.class)
public class StageModel {
    @SlingObject
    private ResourceResolver resourceResolver;

    /** The resource. */
    @Self
    protected Resource resource;

    private String title;

    @PostConstruct
    protected void constructStageType(){
        ContentPolicyManager policyManager = resourceResolver.adaptTo(ContentPolicyManager.class);
        if (policyManager != null) {
            ContentPolicy contentPolicy = policyManager.getPolicy(resource);
            if (contentPolicy != null) {
                title= (String) contentPolicy.getProperties().get("title");
            }
        }
    }

    /**
    * @return title
    */
    public String getTitle() {
        return title;
    }
}

AEM – Coral 2 multifield with acs-aem-commons JSON_STORE

In AEM component dialog, we often implement multifield which comprise of multiple widgets. Here we would cover  multifield which would store values in json format using:

STEP 1: Create a component.

STEP 2: Create component dialog with multifield comprising of:

  • textfield
  • pathbrowser

Add acs-commons-nested=”JSON_STORE” to the multifield

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"       jcr:primaryType="nt:unstructured"       jcr:title="Navigation"       sling:resourceType="cq/gui/components/authoring/dialog">
     <content jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/container">
         <items jcr:primaryType="nt:unstructured">
             <tabs jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/container">
                <layout jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/layouts/tabs" type="nav"/>
                    <items jcr:primaryType="nt:unstructured">
                        <navigationitems jcr:primaryType="nt:unstructured" jcr:title="Navigation Items" sling:resourceType="granite/ui/components/foundation/section">
                            <layout jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/layouts/fixedcolumns" margin="{Boolean}false"/>
                                <items jcr:primaryType="nt:unstructured">
                                    <column jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/container">
                                        <items jcr:primaryType="nt:unstructured">
                                            <navigationitems jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/multifield" class="full-width" fieldDescription="Click 'Add field' to add a new item" fieldLabel="Navigation Items">
                                                <field jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/fieldset" acs-commons-nested="JSON_STORE" name="./navigationItems">
                                                    <layout jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/layouts/fixedcolumns" method="absolute"/>
                                                        <items jcr:primaryType="nt:unstructured">
                                                           <column jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/container">
                                                               <items jcr:primaryType="nt:unstructured">
                                                                   <label jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/textfield" fieldLabel="Label" name="./linktext"/>
                                                                   			<link jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/pathbrowser" fieldLabel="Link" name="./linkURL" rootPath="/content"/>
                                                                </items>
                                                            </column>
                                                       </items>
                                            </field>
                                      </navigationitems>
                                 </items>
                             </column>
                         </items>
                     </navigationitems>
                 </items>
             </tabs>
         </items>
     </content>
</jcr:root>

STEP 3: Add dependencies to the pom.xml

Incase, the AEM doesn’t export javax.json.JsonObject API, then you would have to import the bundles in AEM.

<dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-json_1.0_spec</artifactId>
    <version>1.0-alpha-1</version>
</dependency>
<dependency>
    <groupId>org.apache.johnzon</groupId>
    <artifactId>johnzon-core</artifactId>
    <version>1.0.0</version>
</dependency>

STEP 4: Create Sling Model to access multifield values. The values returned as a List would be iterated in Component’s sightly to display links.

Bean to hold a link’s details:

/** * NavigationItem for Links. */
public class NavigationItem {
    private String linktext;
    private String linkURL;
    public NavigationItem(String linktext, String linkURL){
        this.linktext = linktext;
        this.linkURL = linkURL;
    }
    public String getLinktext() {
        return linktext;
    }
    public void setLinktext(String linktext) {
        this.linktext = linktext;
    }
    public String getLinkURL() {
        return linkURL;
    }
    public void setLinkURL(String linkURL) {
        this.linkURL = linkURL;
    }
}

Sling Model to gather details of all configured links:

package blog.techrevel.core.models;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Optional;

import blog.techrevel.NavigationItem;

/** * A model bean for the link component */
@Model(adaptables = Resource.class)
public class ProductNavigationModel {

   private static final String LINK_URL = "linkURL";
   private static final String LINK_TEXT = "linktext";

   @Inject
   @Optional
   private String[] navigationItems;
   private List<NavigationItem> list;

   @PostConstruct protected void init() {
       if (navigationItems != null) {
           this.list = new ArrayList<>();
           for (String linkJsonString : navigationItems) {
              try (StringReader stringReader = new StringReader(linkJsonString);
                  JsonReader jsonReader = Json.createReader(stringReader)) {
                  JsonObject linkJsonObject = jsonReader.readObject();
                  String linkPath = linkJsonObject.getString(LINK_URL);
                   list.add(new NavigationItem(linkJsonObject.getString(LINK_TEXT), linkPath));
              }
          }
       }
    }
    public List<NavigationItem> getList() {
        return list;
    }
}

STEP 5: Render links in Component’s sightly by accessing the Sling Model

<div data-sly-use.linkModel="blog.techrevel.core.models.ProductNavigationModel">
        <!--/*Links*/-->
        <sly data-sly-repeat.item="${linkModel.list}">
            <a href="${item.linkURL}"> ${item.linktext}</a>
        </sly>
        <sly data-sly-test="${!linkModel.list}">Navigation Component</sly></div>

Verified on AEM 6.3 with acs-aem-commons package version 3.9.0