@dinu_arya
You can follow and can extend the login-token expiration time programmatically in AEM by updating the cq.authTokenValidity property in the TokenAuthenticationHandler OSGi configuration. Here are the steps:
- Navigate to the AEM Web Console at http://localhost:4502/system/console/configMgr.
- Locate the Apache Sling Authentication Service - Token Authentication Handler configuration and click on it.
- Scroll down to the cq.authTokenValidity property and note its current value. This value specifies the time in seconds that a login token is valid.
- Create a new OSGi configuration with the Apache Sling Authentication Service - Token Authentication Handler factory configuration factory name.
- In the new configuration, set the cq.authTokenValidity property to the new expiration time that you want to set in seconds.
- Save the new configuration.
you can programmatically update the cq.authTokenValidity property using the org.osgi.service.cm.ConfigurationAdmin OSGi service. Here is an example code snippet that demonstrates how to update the cq.authTokenValidity property:
@Component
@Service
public class TokenExpirationTimeUpdater {
@Reference
private ConfigurationAdmin configAdmin;
public void updateTokenExpirationTime(int newExpirationTimeInSeconds) {
try {
Configuration config = configAdmin.getFactoryConfiguration("org.apache.sling.auth.core.impl.TokenAuthenticationHandler", null);
Dictionary<String, Object> properties = config.getProperties();
properties.put("cq.authTokenValidity", newExpirationTimeInSeconds);
config.update(properties);
} catch (IOException e) {
// Handle exception
}
}
}
This code creates a new OSGi configuration for the TokenAuthenticationHandler with the new expiration time specified in the cq.authTokenValidity property. The ConfigurationAdmin service is used to retrieve and update the configuration. Note that you will need to have the appropriate permissions to update the OSGi configuration programmatically.