Monday, January 16, 2023

How are Sling Models resolved to a specific implementation?

 

Sling Models are annotation-driven Java "POJO's" (Plain Old Java Objects) that facilitate the mapping of data from the JCR to Java variables and provide several other niceties when developing in the context of AEM. When you adapt to a sling model, the model factory returns the specific model implementation; the returned model implementation is selected through the model pickers.

Photo by Clément Hélardot on Unsplash

In this post, let us dive deep into how this model picking works internally.

The Sling Model Framework has the Implementation Picker to select the specific model implementation.

The Implementation Picker interface can be referred to here — ImplementationPicker (Apache Sling 8 API); the picker interface is enabled with a picker method responsible for selecting a specific model implementation.

The Sling Framework, by default, has the below picker implementations.

First Implementation Picker:

This is the default picker implementation; it picks the first implementation from the list alphabetically ordered by class name. If there are multiple implementations of the specific models, this one selects the first one and returns it to the requestor. First Implementation Picker will be used if no other implementations support picking the model implementation.

The service ranking is set to the highest (Integer.MAX_VALUE) to support more custom picker implementations.

Resource Type-Based Resource Picker:

This picks the specific model implementation based on the resource type. This picker's ranking is 0 to ensure this comes before First Implementation Picker.

The AEM core components have their picker implementation to pick the latest version of a model implementation for a specific model.

Latest Version Implementation Picker:

This picks the specific model implementation based on the resource type and the model version —Picks the latest model version of a core component model based on the version information in the package name. The ranking for this picker is specified as 1 to ensure this comes after the Resource Type Based Resource Picker.

All the core components reference the model interface directly — com.adobe.cq.wcm.core.components.models.Carousel; the model implementations are always enabled with a specific version, so the Resource Type Based Resource Picker will not pick any model implementation, and the picking is delegated to the Latest Version Implementation Picker, and this always returns the latest model implementation based on the version number — e.g., com.adobe.cq.wcm.core.components.internal.models.v1.CarouselImpl).

The External models that implement Core Component interfaces have precedence over internal models, allowing us to enable model delegation for the core components.

The custom picker implementation can be enabled by implementing the org.apache.sling.models.spi.ImplementationPicker interface and picker method with your custom model picker logic; the ranking should be enabled accordingly to ensure the default implementations are not impacted.



Friday, November 24, 2017

Rewrite Rules with PT(Pass Through) Flag is not working in AEM Dispatchers - Adobe Experience Manager(AEM)

Rewrite Rules with PT(Pass Through) Flag is not working in AEM Dispatchers - Adobe Experience Manager(AEM)

How to define SEO/User friendly URL's in Adobe Experience Manager(AEM)


The Rewrite Rules with PT Flag helps us to define the SEO/User friendly URL's by hiding the internal URL's.

Let consider a scenario - The product URL should be rewritten to SEO/User friendly URL.

The internal product URL is - /en/test/pdp/book.html?id=123, this URL is not SEO/User friendly as the title of the the product is not part of the URL

The URL should be rewritten to /en/test/Sample_Book/book/pdp.html?id=123 internally without changing the Browser URL

Rewrite_Rule_with_PT_flag



Sunday, November 5, 2017

java.lang.ClassCastException for the same class com.sample.test.Test cannot be cast to com.sample.test.Test - Adobe Experience Manager(AEM)

java.lang.ClassCastException for the same class com.sample.test.Test cannot be cast to com.sample.test.Test - Adobe Experience Manager(AEM)

We were facing a strange ClassCastException - ClassCastException pointing to the same class in Adobe Experience Manager(AEM)

java.lang.ClassCastException: com.sample.test.Test cannot be cast to com.sample.test.Test

While analyzing through depfinder - http://localhost:4502/system/console/depfinder, there is two version of the same class available from two different packages.

But this class is only defined in one of the package and referred in the other package, after analyzing the Sling class loading is little different - If one of the class com.sample.test.Test is referred from different package, Sling copies the classes locally to the target package and if the target package export the same package(<Export-Package>) -  com.sample.* then Sling export the classes copied from other package that matches the export pattern, in this case our target package is already exporting com.sample.* so two version of same class is available now. This will lead to the ClassCastException specified above.

To fix this issue, we can change the target package pom.xml file to restrict the export of referred classes from other package.

<Export-Package>com.sample.*,!com.sample.test</Export-Package>

Please make sure the restricted package - !com.sample.test is kept after the wider package - com.sample.*

Now only one version of the class from source package is available for reference.


Wednesday, July 5, 2017

Exposing the AEM resources through OAuth - Adobe Experience Manager(AEM)

Exposing the AEM resources through OAuth - Adobe Experience Manager(AEM)

This post will explain the approach to expose the resources through OAuth in Adobe Experience Manager(AEM).

Refer https://www.albinsblog.com/2017/05/how-to-get-basic-profile-details-of-user-through-oauth.html for the basic configurations to expose the the resources thorough OAuth.

Exposing /etc/designs/geometrixx/static.css through OAuth

Configure the "Allowed Scope" as "/etc/designs/geometrixx"(based on the resource that should be exposed) in "Adobe Granite OAuth Resource Server"


The OAuth Authentication handler is not enabled by default and it looks to be an product defect.




Monday, May 29, 2017

How to expose Regex based rest service in Adobe Experience Manager( AEM)

How to expose Regex based rest service in Adobe Experience Manager(AEM)

This post will explain the approach to expose the regex based rest service in Adobe Experience Manager(AEM). By default OSGI will not support exposing regex based rest services and it will only support the services based on the specified Path or Resource Type.

Install OSGI JAX-RS connector:

Install(/system/console/bundles) jersey-all, publisher, provider-security and other required bundles e.g. provider-gson for JSON support and make sure the bundles are in Active state.

The bundles(jar) can be downloaded from following URL - http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.eclipsesource.jaxrs%22

com.eclipsesource.jaxrs-bundles

Develop the Servlet with required path mapping:

>=AEM 6.2

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import org.osgi.service.component.annotations.Component;

@Component(service = RegexServlet.class)
@Path("/{catagroy}/{title}/p/{code : \\d{5}}")
public class RegexServlet {

  @GET
  @Produces({MediaType.TEXT_PLAIN})
  public String getProductDetails(@Context HttpServletRequest request, @Context HttpServletResponse response,@PathParam("catagroy") String catagroy,@PathParam("title") String title,@PathParam("code") String code) {

    return "code="+code+";catagroy="+catagroy+";title="+title;

    }
}

< AEM 6.2

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import javax.ws.rs.Path;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Service(RegexServlet.class)
@Component(metatype = false)
@Path("/{catagroy}/{title}/p/{code : \\d{5}}")
public class RegexServlet {

 @GET
 @Produces({MediaType.TEXT_PLAIN})
public String getProductDetails(@Context HttpServletRequest request, @Context HttpServletResponse response,@PathParam("catagroy") String catagroy,@PathParam("title") String title,@PathParam("code") String code) {

   return "code="+code+";catagroy="+catagroy+";title="+title;

    }
}

Add the following dependency in POM.xml

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0</version>
</dependency>

Install the package and make sure the core bundle status is active.

Verify whether the RegexServlet service is registered in system console

JAX-RS_Servlet

The servlet will accept the request with matching pattern - the servlet path should be starting with /services

The Path Regex pattern specified in the servlet will match for the following URL  - localhost:4502/services/categoryTest/Sampletitle/p/12345 (Code should be 5 digit)

Download the sample code -https://gitlab.com/albinsblog-data/RegexServlet/tree/master (Refer com.regex.servlet.core.RegexServlet.java in core module)
The sample code is tested in AEM 6.3 but it should be working in 6.2


Monday, May 8, 2017

Issue while integrating Adobe Experience Manager(AEM) with Dynamic Tag Management(DTM) through HTTP Proxy

Issue while integrating Adobe Experience Manager(AEM) with Dynamic Tag Management(DTM) through HTTP Proxy

The below exception is thrown while integrating Adobe Experience Manager(AEM) with Dynamic Tag Management(DTM)


08.05.2017 14:06:35.894 *ERROR* [10.208.56.253 [1494270332788] POST /etc/cloudservices/dynamictagmanagement/test/jcr:content.companies.json HTTP/1.1] com.adobe.cq.dtm.impl.util.DTMConfigurationUtil Failed to obtain a response from the DTM API Server.
org.apache.http.conn.ConnectTimeoutException: Connect to api.omniture.com:443 [api.omniture.com/192.243.232.77] failed: Connection timed out
        at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138)
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
        at com.adobe.cq.dtm.impl.util.DTMConfigurationUtil.callDTMApi(DTMConfigurationUtil.java:210)
        at com.adobe.cq.dtm.impl.servlets.DTMCompaniesServlet.doPost(DTMCompaniesServlet.java:58)

Caused by: java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:579)
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:239)
        at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
        ... 138 common frames omitted

Based on the analysis the Dynamic Tag Management(DTM) cloud connector is not using the the proxy server details configured to establish the connection.
This is the defect with the connector, raise a ticket with Adobe support team to  receive the fix.

As a temporary fix update DTMConfigurationUtil.java in bundle - /libs/cq/cloudservices/install/cq-dtm-0.1.8.jar to support proxy server while establishing the connectivity.

DTMConfigurationUtil.java - callDTMApi

 HttpHost proxy = new HttpHost("proxy.com",80);
 RequestConfig config = RequestConfig.custom().setProxy(proxy).build();   
 apiRequest.setConfig(config);

Refer the following post for updating the java class in a bundle - https://www.albinsblog.com/2017/04/updating-salesforce-connector-jarcq-mcm-salesforce-adobe-cq5-aem.html https://www.albinsblog.com/2017/04/updating-salesforce-connector-jarcq-mcm-salesforce-adobe-cq5-aem.html

This post is written based on the AEM version AEM 6.1 SP1.


Sunday, May 7, 2017

How to get the basic profile details of a user in external clients through OAuth - Adobe Experience Manager(AEM)

How to get the basic profile details of a user in external clients through OAuth - Adobe Experience Manager(AEM)

This post will explain the approach to get the basic profile details of a user through OAuth - AEM/Adobe CQ5

Configure the OAuth client - Adobe Experience Manager(AEM):

Login to AEM through Admin credential
Access - http://localhost:4502/libs/granite/oauth/content/clients.html and click on "Create a new app" or "Add New Client"


Enter Client ID and "Redirect URI" - The URL to which the user will be redirected after successful authorization(external client URL)




Saturday, April 15, 2017

how to include custom meta tag headers fromAdobe Experience Manager(AEM) Tags

how to include custom meta tag headers from Adobe Experience Manager(AEM) Tags

This post explains the approach to include custom meta tag headers from Adobe Experience Manager(AEM)/CQ5 Tags.

Customize the page properties dialog:

Customize the page properties dialog to add the field to select custom tags

Copy /libs/foundation/components/page/dialog and /libs/foundation/components/page/tab_basic under custom page rendering component e.g. /apps/training/components/page-content/

Create a node of type cq:widget under tab_basic with the following properties

Name Type Value
allowBlank Boolean true
fieldLabel String Page Type
name String ./page-type
namespaces String[] page-type
xtype String tags

Refer https://www.albinsblog.com/2017/03/how-to-customize-page-properties-dialog-dynamic-dropdownlist-aem-cq5-in-touchui-classicui.html for more details on customizing the page properties dialog.



Thursday, April 13, 2017

Integration of Adobe Experience Manager(AEM) with Salesforce - Part4

Integration of Adobe Experience Manager(AEM) with Salesforce - Part4

This post will explain the approach to extend the basic Adobe Experience Manager(AEM) Salesforce connector to create/update the Salesforce objects.

Refer the following post for details on integrating Salesforce with Adobe Experience Manager(AEM)
https://www.albinsblog.com/2017/03/integrationofaemcq5withsalesforcepart1.html
https://www.albinsblog.com/2017/04/integrationofaemcq5withsalesforcepart2.html
https://www.albinsblog.com/2017/04/integration-of-aem-with-salesforce-part3.html

Prerequisite  - Configure the Salesforce cloud connection, refer the above mentioned post for more details.
Enable the Salesforce cloud configuration for the Home page of the websites.


Dependency:

Add the below Maven dependency to the project
For 6.0 and 6.1
<dependency>
    <groupId>com.adobe.aem</groupId>
    <artifactId>aem-api</artifactId>
    <version>6.0.0.1</version>
    <scope>provided</scope>
</dependency>

For 6.2
<dependency>
    <groupId>com.adobe.aem</groupId>
    <artifactId>uber-jar</artifactId>
    <version>6.2.0</version>
    <classifier>apis</classifier>
    <scope>provided</scope>
</dependency>



Tuesday, April 11, 2017

Integration of Adobe Experience Manager(AEM) with Salesforce - Part3

Integration of Adobe Experience Manager(AEM) with Salesforce - Part3

This post will explain the approach to extend the basic Adobe Experience Manager(AEM) Salesforce connector to search for the Salesforce objects other than Lead/Contact.

Refer the following post for details on integrating Salesforce with Adobe Experience Manager(AEM)
 https://www.albinsblog.com/2017/03/integrationofaemcq5withsalesforcepart1.html
https://www.albinsblog.com/2017/04/integrationofaemcq5withsalesforcepart2.html

Prerequisite  - Configure the Salesforce cloud connection, refer the above mentioned post for more details.
Enable the Salesforce cloud configuration for the Home page of the websites.

Dependency:

Add the below Maven dependency to the project
For 6.0 and 6.1
<dependency>
    <groupId>com.adobe.aem</groupId>
    <artifactId>aem-api</artifactId>
    <version>6.0.0.1</version>
    <scope>provided</scope>
</dependency>

For 6.2
<dependency>
    <groupId>com.adobe.aem</groupId>
    <artifactId>uber-jar</artifactId>
    <version>6.2.0</version>
    <classifier>apis</classifier>
    <scope>provided</scope>
</dependency>



Saturday, April 8, 2017

In place upgrade of Adobe Experience Manager(AEM) to 6.2 version

In place upgrade of Adobe Experience Manager(AEM) to 6.2 version

This post will explain the steps to in place upgrade of Adobe Experience Manager(AEM) server to 6.2 version
  • Backup the current Adobe Experience Manager(AEM) instance
  • Copy aem-quickstart-6.2.0.jar next to current Adobe Experience Manager(AEM) crx-quickstart
  • Perform regular maintenance activities - including workflow purge
  • Run the Traversal check and Data store consistency check one by one - http://localhost:4502/system/console/repositorycheck
  • Disable custom login moduels if any - make sure the default login module is configured as below in crx-quickstart/repository/repository.xml
        <LoginModule class="com.day.crx.core.CRXLoginModule">
            <param name="anonymousId" value="anonymous"/>
            <param name="adminId" value="admin"/>
            <param name="disableNTLMAuth" value="true"/>
            <param name="tokenExpiration" value="43200000"/>
            <!-- param name="trust_credentials_attribute" value="d5b9167e95dad6e7d3b5d6fa8df48af8"/ -->
</LoginModule>
  • Stop the Adobe Experience Manager(AEM) server
  • Remove all log files under crx-quickstart/logs
  • chown -R aem:aem crx-quickstart(this command is required if AEM is running with different user)
  • su aem(this commad is required if AEM is running with diffrent user)
  • If you are migrating from AEM 5.x or AEM 6.0 with a CRX2 backend then follow URL - https://www.albinsblog.com/2015/09/upgrading-aemadobe-cq5-5.6.1-to-aemadobe-cq5-6.1.html
  • If you are migrating from AEM 6.0 with a oak backend or 6.1 then execute java -jar aem-quickstart-6.2.0.jar -r author,crx3,crx3tar
  • Monitor error.log and stderr.log – Once the migration is completed stderr.log will show the following message                                                                                                                           
          “Opening browser using cmd=x-www-browser "http://localhost:4502/"  || gnome-open                       "http://localhost:4502/"  || firefox "http://localhost:4502/"  || mozilla "http://localhost:4502/"               || konqueror "http://localhost:4502/"  || netscape "http://localhost:4502/"  || chromium-browser           "http://localhost:4502/"  || opera "http://localhost:4502/"  || links "http://localhost:4502/"  ||                lynx "http://localhost:4502/"
           Startup time:442 seconds
           http://localhost:4502/
           Quickstart started”

URL to check the version - http://localhost:4502/system/console/productinfo

Check the bundles in Installed state, most of the obsolete bundles will be removed after upgrade but some cases some of  the obsolete bundles will not be uninstalled - This can be ignored or uninstalled manually (better to compare the bundles with fresh 6.2 installation).Refer the following URL for details on obsolete bundles https://docs.adobe.com/docs/en/aem/6-2/deploy/upgrade/obsolete-bundles.html

Custom core bundles may not start due to the dependency issues. Refer the following URL for API difference between 6.1 and 6.2 - https://docs.adobe.com/docs/en/aem/6-2/develop/ref/diff-previous/changes/changes-summary.html

Update the maven dependency with correct version by identifying the version through depfinder -
http://localhost:4502/system/console/depfinder




Tuesday, April 4, 2017

Integration of Adobe Experience Manager(AEM) with Salesforce - Part2

Integration of Adobe Experience Manager(AEM) with Salesforce - Part2

This post will explain the common issues faced while integrating Salesforce with Adobe Experience Manager(AEM).

Refer https://www.albinsblog.com/2017/03/integrationofaemcq5withsalesforcepart1.html for details on integrating Salesforce with Adobe Experience Manager(AEM)

redirect_mismatch: 

The redirect_mismatch error will be displayed if the calback URL configured in the Salesforce connected app and the redirect_uri send by the Adobe Experience Manager(AEM) Connector is not matching.



Verify the callback URL configured in the Salesforce connected app is same as the value send by AEM connector.
Make sure the AEM Salesforce connector is opened via https URL



Monday, April 3, 2017

Updating the Salesforce Connector jar(cq-mcm-salesforce) to support Proxy server and TLS 1.1 - Adobe CQ5/AEM

Updating the Salesforce Connector jar(cq-mcm-salesforce) to support Proxy server and TLS 1.1 - Adobe CQ5/AEM


Updating the Salesforce Connector jar(cq-mcm-salesforce) to support Proxy server and TLS 1.1 - Adobe CQ5/Adobe Experience Manager(AEM)

Steps to update Salesforce Connector jar(cq-mcm-salesforce) to support Proxy server and TLS 1.1

The AEM Salesforce connector is not supporting the Proxy Server and TLS 1.1 or TLS 1.2 versions:

This is the defect with AEM Salesforce Connector, the connector will not be able to connect to Salesforce server behind the proxy server. The SalesforceClient.java class in the connector should be changed to enable the proxy server.

The connector will not be able to connect to Salesforce server if the Adobe Experience Manager(AEM) server is ruuning with Jave version less than 1.8, Java versions less than 1.8 will not support TLS 1.1 or higher version by default but Salesforce expect TLS 1.1 or TLS 1.2 to establish the connectivity. The SalesforceClient.java class in the connector should be changed to support the TLS 1.1 or TLS 1.2, if the  AEM server is running with Java version less than 1.8

I have tested this in Adobe Experience Manager(AEM) 6.1 version, this should be the same case with 6.2 also. Raise an issue with Adobe to get the hotfix until the issue is permanently fixed.

The below is the quick fix to resolve the issue.

Download the /libs/mcm/salesforce/install/cq-mcm-salesforce-1.2.8.jar through package manager

Create a sample project -  mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=com.adobe.granite.archetypes -DarchetypeArtifactId=aem-project-archetype  -DarchetypeVersion=10 -DarchetypeCatalog=https://repo.adobe.com/nexus/content/groups/public/

              groupId=com.day.cq.mcm
              artifactId=cq-mcm-salesforce
              version=1.2.8
              package=com.adobe.cq.mcm.salesforce 
             Enter mcm for other values
 
Execute mvn eclipse:eclipse command in the parent folder of the project and load the project to eclipse

Extract the downloaded jar file and decompile the class files using JAD
Create all the java classes manually in core project with same package details and copy the content from decompiled classes
Replace the pom.xml of core project with the pom.xml content from the decompiled jar





Saturday, April 1, 2017

Generating the missing renditions for the Asset - Adobe CQ5/AEM

Generating the missing renditions for the Asset - Adobe CQ5/AEM

This post will explain the approach to generate the missing renditions for the asset(images) under a specific folder location in  Adobe Experience Manager(AEM)

Create a custom workflow with "Create Thumpnail" step


Edit "Create Thumpnail" step and configure the required renditions.


Servlet to re-generate the missing renditions:

Modify the workflow model path in the servlet with the actual path, the servlet is configured to handle the renditions 370.208 and 470.264(the same renditions are configured in the workflow). The code change is required to handle new renditions by the servlet.

Parameters:
path= the parent path of the assets(images) folder
test=true/false(true - Dry run, false - generate the renditions)



Wednesday, March 29, 2017

How to customize the page properties Dialog to include dynamic DropDownList in AEM/CQ5

How to customize the page properties Dialog to include dynamic DropDownList in AEM/CQ5

This post will explain the details to customize page properties Dialog in both Touch and Classic UI's, the version used for implementing this is Adobe Experience Manager(AEM) 6.1.

The basic page properties dialog will be displayed if the sling:resourceSuperType of the page rendering component is specified as foundation page component(wcm/foundation/components/page for Sightly and foundation/components/page for JSP)

Steps to customize the basic page properties and including dynamic DropDownList to the dialog.

/apps/training/components/page-content/ will be referred as the page rendering component path in the post.

Classic UI:

Copy /libs/foundation/components/page/dialog to /apps/training/components/page-content/
Rename the new node to required name e.g. custom

Copy /libs/foundation/components/page/tab_basic to /apps/training/components/page-content/
Rename /apps/training/components/page-content/tab_basic to required name e.g tab_custom

Remove all the nodes under  /apps/training/components/page-content/tab_custom/items

Change path value in the node /apps/training/components/page-content/dialog/items/tabs/items/custom to /apps/training/components/page-content/tab_custom.infinity.json

Change title property of the node /apps/training/components/page-content/tab_custom to required value e.g Custom

Save All configurations

Open the page from site Admin(e.g. http://localhost:4502/cf#/content/training-site/en.html), now the new tab(Custom) will be added to the page properties with empty panel



Friday, March 24, 2017

Integration of Adobe Experience Manager(AEM) with Salesforce - Part1

Integration of Adobe Experience Manager(AEM) with Salesforce - Part1

Adobe Experience Manager(AEM) Salesforce cloud connector can be used to integrate to Salesforce via connected App configured in the Salesforce

The Adobe Experience Manager(AEM) Salesfore integration supports the following functionalities:
  • Lead Search
  • Contact Search
  • Export AEM user as Salesforce Lead
  • Associate an AEM user with a Salesforce "Contact" or "Lead"
The connector can be extended to support the additional functionalities.


Defining the connected App in Salesforce:

A connected app integrates an application with Salesforce using APIs
Connected apps use standard SAML and OAuth protocols to authenticate and provide tokens for use with Salesforce APIs. The required security policies can be set to control the connected Apps access.

Login to Salesforce - login.salesforce.com
Click on the user name- Setup- Click on Create then Apps
Create New connected App
Enter the name and Email address



Thursday, March 2, 2017

Time zone difference in Author/Publishers - Adobe CQ5/AEM

Time zone difference in Author/Publishers - Adobe CQ5/AEM

The timezone configured in the OS(Linux) level is CST but some time the log files displays the timezone in GMT

To fix the issue force the Adobe Experience Manager(AEM) server to use the required timezone in startup file(start.sh)
e.g.
CQ_JVM_OPTS='-server -Xmx1024m -XX:MaxPermSize=256M -Duser.timezone=US/Central -Djava.awt.headless=true'



Wednesday, March 1, 2017

How to protect the content from anonymous access through SAML based SSO - Adobe CQ5/AEM

How to protect the content from anonymous access through SAML based SSO - Adobe CQ5/AEM

How to enable SAML based SSO for publisher - Adobe CQ5/AEM
How to enable SAML based SSO in publisher to protect the content while accessing via dispatcher - Adobe CQ5/AEM

This post will explain the steps required to protect the published content from anonymous access through SAML based SSO while accessing via dispatcher/publisher - Adobe CQ5/AEM

Out of scope for this post - Configurations of IDP provider. Make sure the return URL configured in SAML provider is /saml_login

Enable Authentication for required content path:

Go to http://localhost:4503/system/console/configMgr(publisher)
Search for Apache Sling Authentication Service
Add the path that required the authentication to Authentication requirements in the following format +<<Content Path>> e.g. +/content/test


Configure the IDP certificate in Adobe Experience Manager(AEM):

Go to http://localhost:4503/system/console/configMgr(publisher)
Under /etc/key in the repository, create a node called "saml"(type nt:folder).
Inside this node, add a new binary property called  "idp_cert" for the public certificate of the IdP.
Upload the certificate file by double clicking on idp_cert property
Save All




Tuesday, February 28, 2017

How to generate sitemap for multi site environments? - Adobe CQ5/AEM

How to generate sitemap for multi site environments? - Adobe CQ5/AEM

This post will explain how to generate the sitemap for different sites(home pages) in multi site environment of Adobe Experience Manager(AEM).

The sitemap will be generated dynamically whenever user access the sitemap URL for particular site.

Factory servlet to generate the sitemap.xml:

import java.io.IOException;
import java.util.*;

import javax.servlet.ServletException;
import javax.xml.stream.*;

import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.felix.scr.annotations.*;
import org.apache.sling.api.*;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.cq.commons.Externalizer;
import com.day.cq.wcm.api.*;

@Component(metatype = true, label = "Site Map", description = "Site Map", configurationFactory = true)
@Service
@SuppressWarnings("serial")
@Properties({
@Property(name = "sling.servlet.resourceTypes", unbounded = PropertyUnbounded.ARRAY,
label = "Homepage Resource Type", description = "Sling Resource Type for Home Page component"),
@Property(name = "sling.servlet.selectors", value = "sitemap", propertyPrivate = true),
@Property(name = "sling.servlet.extensions", value = "xml", propertyPrivate = true),
@Property(name = "sling.servlet.methods", value = "GET", propertyPrivate = true),
@Property(name = "webconsole.configurationFactory.nameHint",
value = "Site Map on resource types: [{sling.servlet.resourceTypes}]") })
public final class SiteMapGeneratorServlet extends SlingSafeMethodsServlet {

private static final Logger LOG = LoggerFactory.getLogger(SiteMapGeneratorServlet.class);
private static final FastDateFormat DATE_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd");
private static final boolean INCLUDE_LAST_MODIFIED_DEFAULT_VALUE = false;

@Property(boolValue = INCLUDE_LAST_MODIFIED_DEFAULT_VALUE, label = "Include Last Modified Date",
description = "If checked, last modified value will be shown in sitemap.")
private static final String INCLUDE_LAST_MODIFIED_PROPERTY = "include.lastmod";

private static final String SITEMAP_NAMESPACE = "http://www.sitemaps.org/schemas/sitemap/0.9";

@Reference
private Externalizer externalizer;

private boolean incLastModified;

@Activate
protected void activate(Map<String, Object> properties) {
this.incLastModified = PropertiesUtil.toBoolean(properties.get(INCLUDE_LAST_MODIFIED_PROPERTY),
INCLUDE_LAST_MODIFIED_DEFAULT_VALUE);
}

@Override
protected void doGet(SlingHttpServletRequest slingRequest, SlingHttpServletResponse slingResponse)
throws ServletException, IOException {

slingResponse.setContentType(slingRequest.getResponseContentType());
ResourceResolver resourceResolver = slingRequest.getResourceResolver();
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
Page pageObj = pageManager.getContainingPage(slingRequest.getResource());

XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
try {
XMLStreamWriter stream = outputFactory.createXMLStreamWriter(slingResponse.getWriter());

stream.writeStartDocument("1.0");
stream.writeStartElement("", "urlset", SITEMAP_NAMESPACE);
stream.writeNamespace("", SITEMAP_NAMESPACE);

// Current page
writeXML(pageObj, stream, slingRequest);

for (Iterator<Page> children = pageObj.listChildren(new PageFilter(), true); children.hasNext();) {
Page childPage = (Page) children.next();
// If condition added to make sure the pages hidden in search in page properties do not show up in sitemap
if (null != childPage) {
if (!childPage.getProperties().containsKey("hideInSearch")
|| (childPage.getProperties().containsKey("hideInSearch")
&& childPage.getProperties().get("hideInSearch").equals("false"))
|| (childPage.getProperties().containsKey("hideInSearch")
&& childPage.getProperties().get("hideInSearch").equals("")))
writeXML(childPage, stream, slingRequest);
}
}

stream.writeEndElement();
stream.writeEndDocument();

} catch (XMLStreamException e) {
throw new IOException(e);
}
}

private void writeXML(Page pageObj, XMLStreamWriter xmlStream, SlingHttpServletRequest slingRequest)
throws XMLStreamException {
xmlStream.writeStartElement(SITEMAP_NAMESPACE, "url");

String protocolPort = "http";
if (slingRequest.isSecure())
protocolPort = "https";

String locPath = this.externalizer.absoluteLink(slingRequest, protocolPort,
String.format("%s.html", pageObj.getPath()));

writeXMLElement(xmlStream, "loc", locPath);

if (this.incLastModified) {
Calendar calendarObj = pageObj.getLastModified();
if (null != calendarObj) {
writeXMLElement(xmlStream, "lastmod", DATE_FORMAT.format(calendarObj));
}
}
xmlStream.writeEndElement();
}

private void writeXMLElement(final XMLStreamWriter xmlStream, final String elementName, final String xmlText)
throws XMLStreamException {
xmlStream.writeStartElement(SITEMAP_NAMESPACE, elementName);
xmlStream.writeCharacters(xmlText);
xmlStream.writeEndElement();
}

}

Create new servlet configuration from the factory through OSGI console by providing the following details

Home Page Resouce Type - add the Home page resource types that should be considered for generating sitemap.xml

Include Last Modified Date - If selected the last modified date of the page will be included as part of the sitemap.xml