Menu

add versioning with clientlibs files in aem

In this article we wil see how to add or remove versioning with clientlibs files(like JavaScript and Cascading Style Sheet (CSS)) in aem? 
ACS AEM Commons provide a Versioned ClientLibs tool to make serve the clientlibs files(JS and CSS) with postfix with a unique id that is know as long TTLs. Everytime you update your any JS and CSS file that unique id get updated for that and because of that AEM server always serve the latest clientlibs files to browser. It also helps to invalidate the caching at CDN and dispatcher level and ensure every request get served with latest and updated version of clientlibs file.

To make our clientlibs files versionable we need to do the following configurations in AEM.
Install latest ACS AEM Commons. Donwload link. This will help us to allow CSS and JavaScript served via AEM ClientLibs to be cached client-side with long TTLs.

Create a Rewriter Configuration Node  

Under project config folder [/apps/<project name>/config/] create a node rewriter with node type sling:Folder.
Now under the rewriter node, create a node versioned-clientlibs of node type nt:unstructured and add the following highlighted properties on versioned-clientlibs.
You may refer the default configuration of tranformer and versioned-clientlibs under path /libs/cq/config/rewriter/default. 
After adding all configurations xml file of versioned-clientlibs will look like this. /apps/<project name>/config/rewriter/versioned-clientlibs/.content.xml


You may verify the changes in sling rewriter rules. http://localhost:4502/system/console/status-slingrewriter

versioned-clientlibs configuration in sling rewriter
versioned-clientlibs configuration in sling rewriter

 Apache Configuration

We need to now configure the Apache to send the right header to set a long TTL with clientlibs (JavaScript and CSS) files:
SetEnvIf Request_URI "(\.min)?\.[a-f0-9]+\.js" long_expires=true
SetEnvIf Request_URI "(\.min)?\.[a-f0-9]+\.css" long_expires=true
Header set Cache-Control max-age=2592000 env=long_expires 

How to disable this versioning or TTL from clientlibs files

To disable this feature, in AEM config manager we have a configuration called "ACS AEM Commons - Versioned Clientlibs Transformer Factory".

Note:
This re-writer does NOT support with

  • URIs embedded in CSS or JavaScript, including: background-images, web fonts, etc.
  • Relative URIs, e.g. etc/clientlibs/mysite/styles.css
  • URIs including a scheme, e.g. http://example.com/etc/clientlibs/mysite/styles.css and //example.com/etc/clientlibs/mysite/styles.css
  • URIs to non-AEM HtmlClientLibrary resources, e.g. /etc/designs/mysite.css
  • Tags contained in conditional comments.
  • ClientLibs included by Javascript (e.g. when leveraging the property channels)

References


AEM user password violates password constraint

When we try to create a user in Adobe Experience Manager(AEM), then we receive below password violation error message. This message is not user friendly and because of that we keep struggling to set new password.
Here is the description of this exception; what does it means and what kind of password AEM is expecting from user.

ERROR javax.jcr.nodetype.ConstraintViolationException: Password violates password constraint ((?=.*\d.*)(?=.*[a-z].*)(?=.*[A-Z].*)(?=.*[@#%\*\-+=~\[\]{}<>\?].*).{12,}).

Description:

Your password should be minimum 12 characters, and should have at least one block letter, one small letter, one digit and one special character.
  1. One special character !@$%
  2. One digit 0-9
  3. One small and block letter a-z A-Z
  4. Minimum characters 12


You may also face this issue while migrating the users and groups. Please refer this document for resolution. https://helpx.adobe.com/in/experience-manager/kb/OakConstraint0027-error-when-migrating-users-and-groups-in-AEM.html


We also face issue while creating the user using useradmin console of AEM and didn't put the right password which matches the above regex. We submit the form of user creation and didn,t see any error message, and then we thought user has been successfully created in the system. But when we search that newly created user then we didn't find that user in system. This is all because the password which we have set for user is not valid, hence system rejected that user.

How to enable/disable or change the constraint?

In AEM config manager we have a configuration which helps us to enable or disable this service and also change the password constraint(regex). Below is the screenshot and detail of available options.

Configuration name: Apache Jackrabbit Oak AuthorizableActionProvider

Authorizable Actions:
PasswordValidationAction should checked to apply this constraint to AEM user's password.
Configure PasswordValidationAction/Password Constraint: A regular expression specifying the pattern that must be matched by a user's password.
 

 

How to create a new regex?

You may use any online tool to generate the regex pattern of password which you want to sent in the AEM users password policy and constraint. e.g. https://regex101.com/

Sling servlet cheat sheet

Apache Sling Servlet cheat sheet.


Apache Sling Servlet
Sling Servlet

You may learn more on Apache sling servlet on https://sling.apache.org/documentation/the-sling-engine/servlets.html