Monday, May 6, 2019

AEM: Sling Job queue and Jobs

In this blog, we are going to see how we can create our own custom Sling job queue for a pool of job topics.

AEM provides a factory conguration which is responsible for this.
Go to your localhost:4502/system/console/configMgr and search for "Apache Sling Job Queue Configuration"

Provide the following field values:

Name: The name of the queue. If matching is used the token {0} can be used to substitute the real value.

Topics: This value is required and lists the topics processed by this queue. The value is a list of strings. If a string ends with a dot, all topics in exactly this package match. If the string ends with a star, all topics in this package and all subpackages match. If the string neither ends with a dot nor with a star, this is assumed to define an exact topic.

Type: The type of queue it can be parallel, ordered or Round Robin

Maximum Parallel Jobs: This will tell how many jobs can run in parallel. This value can be decided by the available number of processor

Maximum Retries: The maximum number of times a failed job slated for retries is actually retried. If a job has been retried this number of times and still fails, it is not rescheduled and assumed to have failed. The default value is 10.

Retry Delay: The number of milliseconds to sleep between two consecutive retries of a job which failed and was set to be retried. The default value is 2 seconds. This value is only relevant if there is a single failed job in the queue. If there are multiple failed jobs, each job is retried in turn without an intervening delay.

Keep History: If this option is enabled, successful finished jobs are kept to provide a complete history.

Please see the below screenshot for a sample configuration





Now Let's see an example by creating a sample Job using Sling Eventing.
To create a job we will implement JobExecutor. A job executor is a service processing a job. It registers itself as an OSGi service together with a property defining which topics this consumer can process. In place of JobExecutor, you can also use JobConsumer.

JobExecutor provides more functionality for the implementor (like tracking, logging, etc). JobConsumer is the preceding variant which allows you to implement a simpler interface if your implementation does not care about the additional features.




Internally the scheduled Jobs use the Commons Scheduler Service. But in addition, they are persisted (by default below /var/eventing/scheduled-jobs) and survive therefore even server restarts. When the scheduled time is reached, the job is automatically added as regular Sling Job through the JobManager.

If a job is in running state we can see it under var/eventing/jobs/assigned folder in AEM

If the job is failed it will move to var/eventing/jobs/canceled folder

if the job ran successfully it will move to var/eventing/jobs/finished folder



For any query and suggestion please comment or write us an email at rishabhy555@gmail.com 

Monday, April 29, 2019

AEM groovies that makes developer life easy

In this blog, I am writing some very useful groovy in AEM.

1. Groovy to export all the users and their associated groups n AEM.


2.  Groovy to export all the Groups and their members in AEM.



Very soon I am posting more useful  AEM groovy on this blog.


For any query and suggestion please comment or write us an email atrishabhy555@gmail.com 

Monday, April 15, 2019

AEM SSO using SAML

In this blog, we are going to see how to implement Single-sign on using Microsoft Azure AD.


AEM ships with a SAML authentication handler. This handler provides support for the SAML 2.0 Authentication Request Protocol (Web-SSO profile) using the HTTP POST binding.


Now let's see  what we have to do to configure SAML in AEM. 

This includes two major steps first is adding the identity provider(IDP) certificate to AEM truststore. And the second step is to configure  SAML authentication handler.


Step 1.  adding the identity provider(IDP) certificate to AEM truststore

  • Go to:  http://{server }: {port}/libs/granite/security/content/useradmin.html
  • Select any existing user or create new user because TrustStore is global to AEM
  • Upload the IdP certificate & make note of the certificate Alias and provide the cert alias in SAML authentication configuration
  • Create KeyStore by supplying the password for authentication-service user (default user provided by AEM )




Step 2: configure  SAML authentication handler.
  • Go to:  http://{server }:{port}/system/console/configMgr
  • Search for Adobe Granite SAML 2.0 Authentication Handler
  • Add the IDP URL
  • Add the IDP Certificate Alias which we got in step 1
  • Add Service Provider Entity ID()
  • Add Password of Key Store(to get this password Select authentication-service and create keystore by giving a password )
  • Check Autocreate CRX Users( if it checked it will create a user in crx automatically )
  • provide NameIDPolicy Format
  • provide Default Groups (A list of default CRX groups in which users are added to after successful authentication)
  • Add Synchronized Attributes(list of attribute mappings (in the format "attributename=path/relative/to/user/node") which should be stored in the repository on user-synchronization)




NOTE: Sometimes we have to configure Referrer filter also for SAML
To configure ReferrerFilter go  http://{server }:{port}/system/console/configMgr and search for 'Apache Sling Referrer Filter'
provide the hostname which will allow hosts for the referrer. 



for reference please visit below links:

for debugging we can use a plugin saml tracer in this we can see what is the SAML response coming


For any query and suggestion please comment or write us an email at rishabhy555@gmail.com 

AEm 6.2 show hide tabs in a component TOUCH UI

When we are developing AEM component we came up with a lot of situation where we want to show tabs on the basis of selection. And in selection also we have two scenarios.

Scenario 1: when we want to show a number of selected tabs. example if we select tab 6 from dropdown so our component will show 6 Tabs. for reference please see the screenshots below


To solve this scenario I am giving the sample code for cq_dialog.xml code and js code.

cq_dialog



showhidetabs.js
 for this create a clientlib and add categories as cq.authoring.dialog and paste the js file in clientlib folder. For reference see the screenshot below





Once you are done with those changes add other things like cq_editConfig and write the HTML code for the component and then the component will work perfectly.