Monday, June 2, 2025

Context-Aware Configuration (CAConfig) in AEM with WCM-IO – A Practical Guide

 

Context-Aware Configuration (CAConfig) in AEM with WCM-IO – A Practical Guide


context-aware configuration in aem


When building multi-language or multi-site Adobe Experience Manager (AEM) websites, you often need to apply site-specific or language-specific configurations.

For example, imagine you have an English site and an Arabic site. You may want different authentication settings, API keys, or UI labels based on which site the user visits. This is where Context-Aware Configuration (CAConfig) in AEM becomes incredibly useful.

It allows you to define configuration values at the site, language, or page level, and AEM automatically picks the correct values based on the page context.


Why Use Context-Aware Configuration in AEM?

CAConfig makes your code:

  • Flexible – define different settings for different sites or pages
  • Clean & Secure – no hardcoding values
  • Maintainable – easier for teams to update settings in /conf


Getting Started with CAConfig in AEM

  • Navigate to your core module in the AEM Maven project, and optionally create a config package (e.g., com.myproject.core.config).

  • Then create a Java interface, for example: MsalConfig.java.

 package com.adobe.aem.guides.inowate.core.config;

import org.apache.sling.caconfig.annotation.Configuration;
import org.apache.sling.caconfig.annotation.Property;

@Configuration(
label = "Inowate - Context Aware Configuration for MSAL",
description = "Context Aware Configuration for Inowate AEM Project"
)
public @interface MsalCaConfig {

@Property(     label = "Configuration Name",     description = "Name of the configuration context")
String configName() default "configName:";

@Property(     label = "Entra ID",     description = "Unique identifier for the application")
String entraID() default "entraID:";

@Property(     label = "Authority",     description = "Authorization server or token issuer URL")
String authority() default "authority:";
}

How to Use Context-Aware Configuration in Your AEM Component

Once your configuration interface is ready, the next step is to use it in your component where it’s needed.

For example, I have a component called TeamMember, and I want to access the configuration values defined via CAConfig and display them on the HTML output. For demonstration purposes, I’ll simply render the values in the 




 package com.adobe.aem.guides.inowate.core.models;
 import com.adobe.aem.guides.inowate.core.config.MsalCaConfig; //importing config here
 @Model(adaptables = { SlingHttpServletRequest.class,
Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class TeamMembersModel {

private static final Logger LOGGER =      LoggerFactory.getLogger(TeamMembersModel.class);

@SlingObject
private Resource currentResource;

private String configName; // local veriables will use for config
private String entraID; // local veriables will use for config
private String authority; // local veriables will use for config
    
    @PostConstruct
    protected void init() {
if (currentResource != null) {
ConfigurationBuilder configBuilder             = currentResource.adaptTo(ConfigurationBuilder.class);
if (configBuilder != null) {
MsalCaConfig caConfig = configBuilder.as(MsalCaConfig.class);
if (caConfig != null) {
configName = caConfig.configName();
entraID = caConfig.entraID();
authority = caConfig.authority();
LOGGER.info("Loaded CAC: configName={},                 entraID={}, authority={}", configName, entraID, authority);
} else {
LOGGER.warn("CAConfig is null");
}
} else {
LOGGER.warn("ConfigurationBuilder is null");
}
}
    }
    // functions that will return the configs values.

    public String getConfigName() {
    return configName;
    }

    public String getEntraID() {
    return entraID;
       }

    public String getAuthority() {
    return authority;
    }

    }



Here, I’m simply rendering the configuration values in the HTML file for demonstration purposes.



Also, add the following code in /core/pox.xml in the <bnd> tag, adjust the code according to. Your project classes
 
 <bnd><![CDATA[
-plugin: org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin,\
org.apache.sling.bnd.models.ModelsScannerPlugin
Sling-ContextAware-Configuration-Classes: \
com.adobe.aem.guides.inowate.core.config.MsalCaConfig
    Import-Package: javax.annotation;version=0.0.0,*

]]></bnd>

Deploying the Configuration

To deploy the configuration, run the following Maven commands:

  • mvn clean install -PautoInstallBundle -Padobe-public
  • mvn clean install -PautoInstallPackage -Padobe-public



Creating the Configuration in CRXDE Lite


  1. Navigate to /conf/projectname and create a folder named sling:configs. Make sure the folder’s primary type is set to sling:Folder.
  2. Inside sling:configs, create a new node with type nt:unstructured. Name this node exactly the same as your configuration interface file from the core module (for example, MsalConfig).

  3. Under this node, define the properties using the same field names as declared in your Java config interface. Assign appropriate values to these properties.

  4. To support multiple languages or sites (e.g., English and Arabic), create additional folders named en and ar, and copy the sling:configs structure into each. Then update the values based on the specific language or site requirements.

You can create as many language or site-specific folders as you need, based on your project requirements.

Refer to the screenshot below for a clear structure example.


/conf/inowate/sling:configs

sling:configs



/conf/inowate/en/sling:configs

sling:configs
/conf/inowate/ar/sling:configs

sling:configs

Linking Context-Aware Configuration to Your Sites

To apply your Context-Aware Configuration (CAConfig) to specific sites or pages, you'll need to set the sling:configRef property.

Navigate to the jcr:content node of the page where you want the configuration applied, and add the sling:configRef property. The value should be the path to the configuration you want to load.

In my setup:

  • I'm linking the general sling:configs to the language-masters site.
  • The /en configuration is linked to the English site.
  • The /ar configuration is linked to the Arabic site.

This allows AEM to automatically resolve and apply the correct configuration based on the context of the site or page being accessed.

Refer to the screenshots below for visual guidance.


For language-masters


For English site /content/inowate/language-masters/en

For Arabic site: /content/inowate/language-masters/en


So, when I load the English site page, AEM fetches the configuration from:

/conf/inowate/en/sling:configs

And when I load the Arabic site page, it pulls the configuration from:

/conf/inowate/ar/sling:configs

This ensures each language site uses its specific context-aware settings. Refer to the following screenshots for a clear example:

English Site Configuration Output:

Context-Aware Configurations


Arabic Site Configuration Output:
Context-Aware Configurations

Note: 

If you have another site, for example a German site, and you haven’t created specific Context-Aware Configurations for it, AEM will fall back to the default configuration located at: /conf/inowate/sling:configs

It won’t use the configurations from the en or ar folders, as those are specifically tied to the English and Arabic sites.



Context-Aware Configuration with WCM-IO Editor

Using the WCM-IO Editor, you can easily manage site-specific or page-specific Context-Aware Configurations (CA-Configs) in AEM. It simplifies the process of creating, updating, and maintaining CA-Configs through a user-friendly interface.

The initial steps remain the same as previously discussed. After that, you’ll need to install the WCM-IO package. This can be done by downloading the package and deploying it to AEM via CRXDE Lite.

Click here to download the WCM-IO package

Next, you’ll need to create a template, which will be used for creating your CA-Configuration page. You can create this template at the following path:

/apps/your-project/templates/template-name

Here’s the sample code for the template I’ll be using to create the CA-Configuration page:

 
 <?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"
jcr:primaryType="cq:Template"
jcr:title="CAConfig Editor Page"
jcr:description="Template to edit context-aware configurations"
allowedPaths="[/content(/.*)]"
ranking="{Long}100">

<jcr:content
jcr:primaryType="cq:PageContent"
sling:resourceType="wcm-io/caconfig/editor/components/page/editor"
jcr:title="CAConfig Editor Page"/>
</jcr:root>


Screenshot from the code:


 After creating the template, make sure to include its path in the src/main/content/META-INF/vault/filter.xml file by adding the following entry:

<filter root="/apps/projectName/templates"/>




Now, run the following command to deploy the template to your AEM instance:

mvn clean install -PautoInstallPackage -Padobe-public


On CRXDLITE: 


Once the deployment is complete, let's say you have a German site and want to create a site-specific configuration for it.

To do this, go to CRXDE Lite, create a new folder named de under /conf/your-project/, and add the sling:configs node inside that folder then at the page level of your German site add sling:configRef  and assign the path to its until de folder. This will link the site to its specific context-aware configuration. Refer to the screenshots below for guidance.




 

Next, add the sling:configRef property to the jcr:content node of the German website page.






Creating a CA Configuration Page for the German Site

  • Navigate to the German site in AEM.
  • Select the German main page and click on the create button.
  • Choose the Configuration Template.
  • Enter a name for the configuration page and click Create.
  • Open the newly created page.
  • Click on the Configuration option.
  • Add the site-specific values you want for the German page.
  • Go to your German site page and refresh it.

You’ll now see that German-specific CA configurations are applied only to the German site.


Selecting the German page to create the CA config page


Create site specific ca page

selecting template
select CA - template

Adding the name of a page
name of CA - Page

Clicking on configuration 
Click on configuration inside ca page


Adding values for German page


update  CA values



Final output

german page final output with ca



Benefits of Using Context-Aware Configuration (CAConfig) in AEM

Custom Configs for Each Site or Language

You can easily set up different configurations for each website or language version — like English, Arabic, or German — without mixing things up.

Applies Configs Based on Page Location

AEM automatically picks the right configuration based on where the content lives, so there’s no need to write extra code to handle it manually.

All Configurations in One Place

Everything stays organised under the /conf folder, making it easier to manage and reuse across different components and pages.

Less Code, More Clarity

Since the logic lives in configuration, your components don’t need as many if-else checks, keeping the code clean and easier to maintain.

Perfect for Multi-Site Projects

If you're building for multiple brands or clients under one AEM instance, CAConfig helps you keep each one separate with its own set of rules.

Built-in Fallback Support

If a specific configuration isn’t found, AEM will automatically fall back to a default one — like global settings — so your site stays functional.

Secure and Easy for Authors

Configuration is separate from content, and tools like the wcm.io editor make it easy for non-developers to update values when needed.

Flexible Down to the Page Level

You can even have different settings for individual pages if needed — for example, one page could show a different layout or title than another.

Scales Well as You Grow

Whether you’re adding new regions, languages, or brands, CAConfig makes it simple to scale your setup without a mess.


Difference Between OSGi Configuration and Context-Aware Configuration (CAConfig) in AEM
OSGi Configuration

System-Level Settings

OSGi configs are mostly used for backend services and bundles — like setting up a connection to an external API, defining timeouts, or toggling a feature flag globally.

Applies Globally

Once set, the values apply across the whole AEM instance unless you're using run modes to split them.

Managed via Felix Console or Files

You typically manage OSGi configs through the Felix console (/system/console/configMgr) or deploy them from files under /apps or /libs.

Developer-Oriented

Mostly handled by developers or DevOps teams, not authors. Not very user-friendly for content teams. 


 Context-Aware Configuration (CAConfig)

Content-Level Settings

CAConfig is used when you need site-specific or page-specific settings, like setting a site title, map coordinates, or theme per language/site.

Applies Based on Context

It automatically picks the correct config based on where the content lives (e.g., /content/site/en vs /content/site/ar).

Stored Under /conf

All configurations live neatly under the /conf folder and can be edited through CRXDE or even via UI tools like wcm.io editor.

Author-Friendly

Authors or content admins can manage CAConfigs easily without touching code. It’s made for flexibility on the content side.


Conculusion

Context-Aware Configuration in AEM makes managing site- and language-specific settings simple and efficient. It helps keep your code clean and lets authors update configs easily without developer help. This approach is perfect for scaling multi-site projects smoothly. If you want flexible and maintainable configs, CAConfig is the way to go! 


Monday, April 21, 2025

How to Create and Map a System User in AEM (Step-by-Step Guide)

 In Adobe Experience Manager (AEM), when you build services or backend logic, you often need to access JCR (Java Content Repository) securely. For this, you don’t use regular users—you use System Users.





System Users are special, non-login users used for service-level operations. They don’t have passwords and are safer to use than admin or normal users.

Let’s walk through the steps to create and map a system user in AEM.


Step 1: Create a System User

  • Go to AEM Web Console: http://localhost:4502/crx/explorer/index.jsp
  • Log in with admin credentials.
  • Click on User Administration tab.



  • Click Create System User, and fill:
  • User ID: inowate-test-user
  • Add path. Click Create.(Under /home/system, create a folder for your project if not already created (example: /home/system/myproject). else you can create directly in system)
Note:  I'm assigning permissions to this folder because my contact form submissions will be stored in the JCR under this location. In your case, you should grant permissions to the folder where you intend to read, write, update, delete, or modify JCR nodes, depending on your specific requirements.


Check following screenshot from my practical work




Step 2: Assign Required Permissions

  • http://localhost:4502/useradmin
  • Search your system user: inowate-test-user
  • Select the user, and assign read/write permissions to specific paths your service will access. For example: (/content/myproject, /var/contact-form-submission)

Avoid giving unnecessary permissions. Check the following screenshot



Step 3: Map the User with a Service

  • http://localhost:4502/system/console/configMgr
  • search (Apache Sling Service User Mapper Service Amendment)
  • Add an entry like the following screenshot.


User System user in code

Now we can use system user in our code in servlet or in service where it required as per need
@Reference
private ResourceResolverFactory resolverFactory;

private ResourceResolver getServiceResourceResolver() {
    Map<String, Object> param = new HashMap<>();
    param.put(ResourceResolverFactory.SUBSERVICE, "my-service-name");
    try {
        return resolverFactory.getServiceResourceResolver(param);
    } catch (LoginException e) {
        log.error("Failed to get service resource resolver", e);
    }
    return null;
}


Conclusion

System users make your AEM services secure and clean. Just remember:

  • Create under /home/system
  • Use mapper config correctly
  • Give minimum permissions
  • Use getServiceResourceResolver() in your code



Tuesday, December 24, 2024

Comparing AEM as Cloud Service and AEM 6.5 | AEM 6.5 vs. AEM as a Cloud Service

 AEM 6.5 vs. AEM as a Cloud Service: What You Need to Know

When it comes to enterprise content management, Adobe Experience Manager (AEM) is a leading solution. However, businesses often face a crucial decision: Should they choose AEM 6.5 or AEM as a Cloud Service? This guide provides a clear comparison to help you make an informed choice, focusing on features, benefits, and use cases for both.





What is AEM 6.5?

AEM 6.5 is the traditional on-premises version of Adobe Experience Manager. It allows businesses to deploy and manage their content management system (CMS) in a private or hybrid cloud environment.

Key Features:

  • Full control over infrastructure and deployment.
  • Customizable architecture tailored to specific business needs.
  • Extensive support for integrations with legacy systems.

Ideal For: Organizations that need strict standards or prefer on-premises infrastructure for more control.


What is AEM as a Cloud Service?

AEM as a Cloud Service is Adobe’s fully managed, cloud-native CMS. It offers continuous updates and scalability without the need for manual upgrades or maintenance.

Key Features:

  • Fully managed by Adobe with automatic updates.
  • Built-in scalability and high availability.
  • Faster time-to-market with modern cloud infrastructure.

Ideal For: Businesses looking for a scalable, low-maintenance CMS with access to the latest features.


Key Differences Between AEM 6.5 and AEM as a Cloud Service



Benefits of AEM 6.5

  1. Complete Control: You have full control over infrastructure and security.
  2. Custom Integrations: Ideal for businesses with unique integration needs.
  3. Requirement-ready: Meets strict data privacy and regulatory requirements.

Challenges:

  • Requires significant IT resources for management.
  • Manual upgrades can be time-consuming and costly.


Benefits of AEM as a Cloud Service

  1. Continuous Innovation: Always up-to-date with Adobe’s latest features and improvements.
  2. Scalability: Automatically adjusts to handle spikes in traffic.
  3. Lower Maintenance: No need for manual upgrades or server management.

Challenges:

  • Limited flexibility for highly customized use cases.
  • Relies on Adobe’s infrastructure, which may not meet specific compliance requirements.



When to Choose AEM 6.5

  • Your business requires full control over infrastructure and data.
  • You need deep customization for complex workflows.
  • Meeting strict rules is a top priority.

When to Choose AEM as a Cloud Service

  • Your focus is on scalability and faster time-to-market.
  • You want a low-maintenance CMS with continuous updates.
  • Your team prefers a subscription-based pricing model with predictable costs.

Conclusion

Choosing between AEM 6.5 and AEM as a Cloud Service depends on your business needs. If you require complete control and customization, AEM 6.5 is the right choice. However, if you prioritize scalability, reduced maintenance, and access to the latest features, AEM as a Cloud Service is the way forward. Both options are powerful solutions—the decision lies in your organization’s goals and resources.



Wednesday, April 24, 2024

Launches and Page Lock/Unlock Adobe AEM

 



Launches

Develop a launch mechanism facilitating updates for future activation of new versions of current web pages. Launches enable you to efficiently develop content for a future release. A launch is created to allow you to make changes ready for future publication (while maintaining your current pages). After editing and updating your launch pages you promote them back to the source, then activate the source pages (top-level). Promoting duplicates of the launch content back to the source pages can be done either manually or automatically (dependent on fields set when creating and editing the launch).


Create Launch

  • Select the page with the selection mode
  • click on the Create button then Selec Launch.




  • Add the title and select the options as per need (otherwise move forward with default options)
  • Click on the Create button


Access All Launches


  • Navigate to BASEURL/libs/launches/content/launches.html.(list of all created lunches)
  • Select your lunch, click on the edit button,



  • Select the page and click on the Save button
  • Click on the  Open Button, page will be ready for edit 



  • when all changes are done then click on the Promote button.



  1. then select options according to your need and click Next. it will be synced with the main page in the AEM Author site console. After this, you can publish the page to move content to the Publisher.





Page Lock / Unlock

Once the page is locked, no alterations can be made to its content, and replication of the page is prohibited until the user who locked it chooses to unlock it again.


How to lock the Page


  • Select the page with the selection mode
  • Select the lock icon.


  • so one can edit this page once it is locked.
  • if another person tries to unlock this page he will get an error popup



How to Unlock the Page


  • Select the page with the selection mode
  • Select the Unlock icon.




Saturday, December 16, 2023

Run Adobe AEM in Debug Mode | Debugger in AEM VsCode

 

Run AEM In Debug Mode









Using IntelliJ

Command 

Run the author instance in debug mode by executing the following command and Please make sure to replace aem-author-p4502.jar with the appropriate filename if necessary. This command starts the author instance with debugging enabled on port 8888.

java -Xmx2048M -agentlib:jdwp=transport=dt_socket,address=8888,
server=y,suspend=n -jar aem-author-p4502.jar

Configure IntelliJ for debugging:

  •  Open your project in IntelliJ.
  •  Navigate to the "Run" menu and select "Edit Configurations".
  •  Click on the "+" button to create a new configuration and choose "Remote JVM Debug" from the list.
  •  In the "Name" field, provide a name for your configuration (e.g., AEM Debug).
  •  In the "Debugger mode" section, select "Attach to remote JVM".
  •  Specify the following settings:
  • Host: The hostname or IP address of your Slack workspace's server where AEM is running.
  • Port: The port number where AEM is running in debug mode (in this case, 8888).
  • Optionally, you can configure other settings such as module filtering, breakpoints, etc., as per your requirements.
  • Click "OK" to save the configuration.


you can start a debugging session by selecting the created configuration and clicking the "Debug" button in IntelliJ.





Using VSCode

Command 

Run the author instance in debug mode by executing the following command and Please make sure to replace aem-author-p4502.jar with the appropriate filename if necessary. This command starts the author instance with debugging enabled on port 5000 (this port could be anything).

java -jar aem-author-p4502.jar -debug 5000

After running above command Now Configure VSCode for debugging
  • Click on  Debug Icon and make configuration in launch.json file according to project
Run your debugger by clicking on debugger green button debugger will be started




  • Now you can see debugger is telling you at which break point what is happening
  • Now you can see debugger is telling you at which break point what is happening
  • Now you can see debugger is telling you at which break point what is happening
  • Now you can see debugger is telling you at which break point what is happening
Add Breakpoints on any "sling model" that you want to debug. and after that refresh you page on aem author that is using this model.





Now Debugger is Telling you at which breakpoint what is happening





Saturday, August 19, 2023

AEM OSGI Configuration with Run Modes

 In this article we will learn about OSGI Configuration with run modes in Adobe Experience Manager 



Create OSGIConfiguration InterFace

Go to your maven project  > Core and create an Interface


Create OSGIConfiguration Implementation 

we will create a class here that will implement this interface

package sa.com.stc.core.services.Impl;
import org.osgi.service.metatype.annotations.*;
import sa.com.stc.core.services.CxpOsgiConfig;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;

@Component(service = CxpOsgiConfig.class,immediate = true)
@Designate(ocd = CxpOsgiConfigimpl.ServiceConfig.class )
public class CxpOsgiConfigimpl implements CxpOsgiConfig{

@ObjectClassDefinition(name="CXP - OSGi Configuration",
description = "OSGi Configuration demo.")
public @interface ServiceConfig {

@AttributeDefinition(
name = "Base Url",
description = "Enter Base Url.",
type = AttributeType.STRING)
public String baseURL() default "http://localhost:";

@AttributeDefinition(
name = "Port Number",
description = "Enter Port Number",
type = AttributeType.STRING)
public int portNumber() default 1234;
}

private String baseURL;
private int portNumber;

@Activate
protected void activate(ServiceConfig serviceConfig){
baseURL=serviceConfig.baseURL();
portNumber=serviceConfig.portNumber();
}

@Override
public String getBaseUrl() {
return baseURL;
}
@Override
public int getPort() {
return portNumber;
}
}



Annotations


@ObjectClassDefinition
In it we define the name of our OSGI Configuration with this name we can search this in aem console
http://localhost:4502/system/console/configMgr

Its is used create the fields on AEM instance 




@AttributeDefinition
it is used to define the type of type of field (it  will string or array or int) etc.



where it will save in CRXDLite

By default it will save in apps -> system -> config. and its values are coming from aem console.

but you can copy paste this in your project inside the different run mode folder also. if you not have run mode folders you can create them manually.
 


How you can run you instance with different run mode

stop your aem local server and type the mode in which you want to run it (no need to write author bcoz it is main run mode it will be auto selected)

java -jar aem-author.p4502.jar -r prod

you can check via bottom link which runmode is working



Important Points

when we will run simple author so it will use the OSGIConfiguration that you paste in author run mode
when we will run stage or other so it will come to  the OSGIConfiguration of author first, and will pick all values, then it will go to stage runmode, if it found here is some new values he will override only that value that is change here 

now you can use your osgi congiguration in backend in any module like (sling model , servlet etc)

How we can use OSGIConfiguration in sling model