<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Balaji Srinivasan on Medium]]></title>
        <description><![CDATA[Stories by Balaji Srinivasan on Medium]]></description>
        <link>https://medium.com/@balaji.srinivasan_84768?source=rss-935fd6621ced------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Balaji Srinivasan on Medium</title>
            <link>https://medium.com/@balaji.srinivasan_84768?source=rss-935fd6621ced------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 20:07:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@balaji.srinivasan_84768/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Asset Share Commons Login Integration]]></title>
            <link>https://medium.com/activate-aem/asset-share-commons-login-integration-8202df6fbf52?source=rss-935fd6621ced------2</link>
            <guid isPermaLink="false">https://medium.com/p/8202df6fbf52</guid>
            <category><![CDATA[aem-integration]]></category>
            <category><![CDATA[asclogin]]></category>
            <category><![CDATA[aem-assets]]></category>
            <category><![CDATA[aem]]></category>
            <category><![CDATA[asset-share-commons]]></category>
            <dc:creator><![CDATA[Balaji Srinivasan]]></dc:creator>
            <pubDate>Fri, 20 Dec 2024 12:02:28 GMT</pubDate>
            <atom:updated>2024-12-20T12:02:28.985Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yekEa3-WnKK0CuhozK_-UA.png" /></figure><p>Asset Share Commons (ASC) is a modern, open-source implementation for Asset Share, designed specifically for Adobe Experience Manager as a Cloud Service. Asset Share Commons enables users to search, view, download, and share assets. Built as a standard AEM site with an open-source implementation, it offers extensive integration and customization options to meet specific needs. For example, it can be tailored to allow sharing multiple renditions of assets and integrated with any authentication provider. You can learn more about Asset Share Commons and the features available in it from the <a href="https://opensource.adobe.com/asset-share-commons/">official documentation</a>. This article covers the integration of login functionality with ASC using the Curity Identity Server.</p><p>Curity Identity Server is a comprehensive identity and access management (IAM) solution designed to deliver secure authentication, authorization, and API protection for modern applications. It supports protocols like OAuth 2.0 and OpenID Connect, enabling features such as single sign-on (SSO) and multi-factor authentication (MFA). The server also includes user registration functionality, allowing new users to create accounts. Furthermore, it offers an HTML-Form Based Authenticator, which enables the creation of custom login forms, providing flexibility in the authentication process.</p><p>This article outlines the necessary configuration changes within Adobe Experience Manager (AEM) and the setup of a Curity sandbox environment to enable thorough end-to-end testing of the login process. Additionally, it covers the user group configuration and associated permissions to manage access to and restrictions on assets within the ASC.</p><p><strong>Curity IDP Setup:</strong></p><p>In Curity Sandbox, Go to Token Service and create a client for ASC.</p><figure><img alt="Clients available in Curity" src="https://cdn-images-1.medium.com/max/1024/1*Zs5ZlU12NTEKvZ22rqUUuQ.png" /></figure><p>Edit the ASC Client and Click on capabilities. Add Code Flow and click Next.</p><figure><img alt="Capabilities within a client in Curity" src="https://cdn-images-1.medium.com/max/800/1*3-ap6FRk5UvKP2nGi9me6A.jpeg" /></figure><p>Add the Redirect URIs to whitelist. Append /callback/j_security_check to the Page URL and add it to the Redirect URIs list.</p><figure><img alt="Redirect URIs for the Client" src="https://cdn-images-1.medium.com/max/1024/1*ELCRmUEneKeJX1XpHk61fA.png" /></figure><p>In the Authentication method, select secret and generate it. Copy the secret value and store it somewhere as this will be required in the AEM Configuration.</p><figure><img alt="Authentication Method for the Client" src="https://cdn-images-1.medium.com/max/1024/1*gjkMh1eaSJk7mEzT4i2NZw.png" /></figure><p>Select html-form as the User Authentication method.</p><figure><img alt="User Authentication method for the login" src="https://cdn-images-1.medium.com/max/1024/1*DTX1Bf3wTuDsVY9ywpYJMg.png" /></figure><p>Add the scopes under Authorization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j2fEE5zLcyvn0HUPVyNFmw.png" /></figure><p>Add the Client name (for example, ASC) and note it down as it is needed in AEM Configuration. Commit the changes.</p><p><strong>AEM Configurations:</strong></p><p>The integration process involves several key configurations within AEM, including the following:</p><ul><li>Configure the Service User</li><li>Setup Custom OAuth Provider</li><li>OSGi Configurations</li><li>Cloud Environment Variables</li></ul><p><strong>Configure the Service User:</strong></p><p>Create a service user and assign the required permissions to manage user creation. This can be accomplished by using the Repo Init script and configuring the service user mappings.</p><p>org.apache.sling.jcr.repoinit.RepositoryInitializer-service-user.cfg.json</p><pre>{ <br> &quot;scripts&quot;: [ <br> &quot;create service user oauth-service&quot;, <br> &quot;set ACL for oauth-service\n allow jcr:all on /home\nend&quot; <br> ] <br>}</pre><p>org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended~oauth-service.cfg.json</p><pre>{ <br> &quot;service.ranking&quot;:&quot;0&quot;, <br> &quot;user.mapping&quot;:[ <br> &quot;mycompany.core:oauth-service=oauth-service&quot; <br> ] <br>}</pre><p>mycompany.core should be the Symbolic name from core bundle.</p><p><strong>Setup Custom OAuth Provider:</strong></p><p>The implementation of a custom provider involves the following steps:</p><p>Create an Api class CurityOAuth2Api.java</p><pre>package com.mycompany.aem.platform.core.auth; <br><br>import com.mycompany.aem.platform.core.auth.impl.CurityOAuth2ServiceImpl; <br>import org.scribe.builder.api.DefaultApi20; <br>import org.scribe.extractors.AccessTokenExtractor; <br>import org.scribe.model.OAuthConfig; <br>import org.scribe.oauth.OAuthService; <br>import java.util.Map; <br>import java.util.concurrent.ConcurrentHashMap; <br><br>/** <br>* CurityOAuth2Api is a custom implementation of the OAuth 2.0 API for integrating with the Curity identity server. <br>* It provides methods for constructing the authorization URL, retrieving the access token endpoint, and extracting <br>* access tokens from OAuth responses. <br>* This class extends the DefaultApi20 class from the Scribe library to manage <br>* OAuth2 flows such as authorization code grant and token exchange. <br>*/ <br><br>public class CurityOAuth2Api extends DefaultApi20 { <br><br>    String baseUrl; <br>    private final Map&lt;String, String&gt; tokenAndVerifierMap = new ConcurrentHashMap&lt;&gt;(); <br><br>    public CurityOAuth2Api(String baseUrl) { <br>        this.baseUrl = baseUrl; <br>    } <br><br>    @Override <br>    public String getAccessTokenEndpoint() { <br>        return this.baseUrl + &quot;/oauth-token&quot;; <br>    }<br><br>    @Override <br>    public AccessTokenExtractor getAccessTokenExtractor() { <br>        return new CurityOauth2TokenExtractor(); <br>    } <br><br>    @Override <br>    public String getAuthorizationUrl(OAuthConfig oAuthConfig) { <br>        String endpoint = this.baseUrl +&quot;/oauth-authorize?client_id=%s&amp;scope=openid profile email phone&amp;response_type=code&amp;redirect_uri=%s&quot;; <br>        return  String.format(endpoint,oAuthConfig.getApiKey(), oAuthConfig.getCallback()) ; <br>    } <br><br>    public OAuthService createService(OAuthConfig config) { <br>        return new CurityOAuth2ServiceImpl(this, config); <br>    } <br><br>} </pre><p>Add a Service class to get the Access token CurityOAuth2ServiceImpl.java</p><pre>package com.mycompany.aem.platform.core.auth.impl; <br><br>import org.scribe.builder.api.DefaultApi20; <br>import org.scribe.model.OAuthConfig; <br>import org.scribe.model.OAuthConstants; <br>import org.scribe.model.OAuthRequest; <br>import org.scribe.model.Response; <br>import org.scribe.model.Token; <br>import org.scribe.model.Verb; <br>import org.scribe.model.Verifier; <br>import org.scribe.oauth.OAuthService; <br>import java.util.Base64; <br><br>/** <br>* CurityOAuth2ServiceImpl is an implementation of the OAuthService interface, specifically designed for OAuth 2.0  <br>* integration with the Curity identity server. This service handles OAuth 2.0 operations such as obtaining  <br>* access tokens, signing requests, and constructing authorization URLs. <br>* <br>* Key responsibilities: <br>* - Handling the exchange of authorization codes for access tokens using the &quot;authorization_code&quot; grant type. <br>* - Signing OAuth requests with the obtained access tokens to authenticate API calls. <br>* - Generating the authorization URL for redirecting users to the Curity platform for authentication. <br>*/ <br><br>public class CurityOAuth2ServiceImpl implements OAuthService { <br><br>    private static final String VERSION = &quot;2.0&quot;; <br>    private final DefaultApi20 api; <br>    private final OAuthConfig config; <br><br>    public CurityOAuth2ServiceImpl(DefaultApi20 api, OAuthConfig config) { <br>        this.api = api; <br>        this.config = config; <br>    } <br> <br>    @Override <br>    public Token getRequestToken() { <br>        throw new UnsupportedOperationException(&quot;Unsupported operation, please use &#39;getAuthorizationUrl&#39; and redirect your users there&quot;); <br>    }<br> <br>    @Override <br>    public Token getAccessToken(Token token, Verifier verifier) { <br>        OAuthRequest request = new OAuthRequest(Verb.POST, api.getAccessTokenEndpoint()); <br>        request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); <br>        request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); <br>        request.addBodyParameter(OAuthConstants.CODE, verifier.getValue()); <br>        request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); <br>        request.addBodyParameter(&quot;grant_type&quot;, &quot;authorization_code&quot;); <br>        String authenticationHeader = config.getApiKey()+&quot;:&quot;+config.getApiSecret(); <br>        request.addHeader(&quot;Authorization&quot;,&quot;Basic &quot; + Base64.getEncoder().encodeToString(authenticationHeader.getBytes())); <br>        Response response = request.send(); <br>        return api.getAccessTokenExtractor().extract(response.getBody()); <br>    } <br><br>    @Override <br>    public void signRequest(Token accessToken, OAuthRequest oAuthRequest) { <br>        oAuthRequest.addHeader(&quot;Authorization&quot;, &quot;Bearer &quot; + accessToken.getToken()); <br>    } <br><br>    @Override <br>    public String getVersion() { <br>        return VERSION; <br>    }<br> <br>    @Override <br>    public String getAuthorizationUrl(Token token) { <br>        return api.getAuthorizationUrl(config); <br>    } <br><br>}</pre><p>Add a token extractor class CurityOauth2TokenExtractor.java</p><pre>package com.mycompany.aem.platform.core.auth; <br><br>import org.scribe.exceptions.OAuthException; <br>import org.scribe.extractors.AccessTokenExtractor; <br>import org.scribe.model.Token; <br>import org.scribe.utils.OAuthEncoder; <br>import org.scribe.utils.Preconditions; <br>import java.util.regex.Matcher; <br>import java.util.regex.Pattern; <br> <br>/** <br>* IdentityServerOauth2TokenExtractor is a custom implementation of the AccessTokenExtractor interface,  <br>* responsible for extracting OAuth 2.0 access tokens from a JSON response body returned by an identity server. <br>* This class specifically parses the response to retrieve the access token using a regular expression. <br>*/ <br><br>public class CurityOauth2TokenExtractor implements AccessTokenExtractor { <br> <br>    private static final String TOKEN_REGEX = &quot;access_token\&quot;:\&quot;([^\&quot;]+)&quot;; <br>    private static final String EMPTY_SECRET = &quot;&quot;; <br><br>    @Override <br>    public Token extract(String response) { <br>        Preconditions.checkEmptyString(response, <br>                &quot;Response body is incorrect. Can&#39;t extract a token from an empty string&quot;); <br>        Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response); <br>        if (matcher.find()) { <br>            String token = OAuthEncoder.decode(matcher.group(1)); <br>            return new Token(token, EMPTY_SECRET, response); <br>        } else { <br>            throw new OAuthException(&quot;Response body is incorrect. Can&#39;t extract a token from this: &#39;&quot; + response + &quot;&#39;&quot;, <br>                    null); <br>        } <br>    } <br><br>} </pre><p>Create a Base Provider class</p><pre>package com.mycompany.aem.platform.core.auth.impl; <br><br>import com.adobe.granite.auth.oauth.Provider; <br>import com.adobe.granite.auth.oauth.ProviderType; <br>import com.adobe.granite.security.user.UserPropertiesService; <br>import com.google.gson.Gson; <br>import com.google.gson.JsonSyntaxException; <br>import org.apache.jackrabbit.api.security.user.Authorizable; <br>import org.apache.jackrabbit.api.security.user.User; <br>import org.apache.sling.api.SlingHttpServletRequest; <br>import org.apache.sling.api.resource.LoginException; <br>import org.apache.sling.api.resource.ResourceResolver; <br>import org.apache.sling.api.resource.ResourceResolverFactory; <br>import org.scribe.builder.api.Api; <br>import org.scribe.model.OAuthRequest; <br>import org.scribe.model.Response; <br>import org.scribe.model.Verb; <br>import org.slf4j.Logger; <br>import org.slf4j.LoggerFactory; <br><br>import javax.jcr.Node; <br>import javax.jcr.RepositoryException; <br>import javax.jcr.Session; <br>import java.io.IOException; <br>import java.util.HashMap; <br>import java.util.Map; <br> <br>/** <br>* OAuth2BaseProvider is an abstract implementation of the Provider interface for integrating OAuth 2.0-based authentication. <br>* It serves as a base class for specific OAuth2 providers, handling core <br>* OAuth operations like user creation, profile mapping, and access token management. <br>* <br>* Key responsibilities: <br>* - Provides methods for managing user profiles and extracting user details from OAuth2 responses. <br>* - Maps OAuth2 properties (such as given name, surname, email) to AEM user profile properties. <br>* - Facilitates retrieval of protected user data via OAuth2 requests. <br>* - Defines utility methods for handling OAuth tokens and user-related data, including custom mappings of OAuth <br>*   attributes to user profile paths. <br>*/ <br><br>abstract class OAuth2BaseProvider implements Provider  { <br><br>    private final Logger log = LoggerFactory.getLogger(getClass()); <br>    protected UserPropertiesService userPropertiesService;<br>    protected ResourceResolverFactory resourceResolverFactory; <br>    protected Api api;<br>    protected String id; <br>    protected String name; <br>    protected String profileUrl; <br>    public static final String USER_ADMIN = &quot;oauth-service&quot;; <br><br>    @Override <br>    public String getId() { <br>        return this.id; <br>    } <br><br>    @Override <br>    public String getName() { <br>        return this.name; <br>    } <br> <br>    @Override <br>    public ProviderType getType() { <br>        return ProviderType.OAUTH2; <br>    } <br><br>    @Override <br>    public Api getApi() { <br>        return this.api; <br>    } <br> <br>    //using token endpoint as the profile url <br>    @Override <br>    public String getDetailsURL() { <br>        return this.profileUrl; <br>    } <br><br>    @Override <br>    public String[] getExtendedDetailsURLs(String scope) { <br>        return new String[0]; <br>    } <br><br>    @Override <br>    public String[] getExtendedDetailsURLs(String scope, String userId, Map&lt;String, Object&gt; props) { <br>        return new String[0]; <br>    } <br><br>    public String mapProperty(String property) { <br>        if (&quot;http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname&quot;.equals(property)) <br>            return &quot;profile/givenName&quot;; <br>        if (&quot;http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname&quot;.equals(property)) <br>            return &quot;profile/familyName&quot;; <br>        if (&quot;http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress&quot;.equals(property)) <br>            return &quot;profile/email&quot;; <br>        return getPropertyPath(property); <br>    } <br><br>    @Override <br>    public String mapUserId(final String userId, final Map&lt;String, Object&gt; props) { <br>        return (String) props.get(getPropertyPath(&quot;name&quot;)); <br>    } <br><br>    /** <br>     * Called after a user is created by Granite <br>     * <br>     * @param user <br>     */ <br><br>    @Override <br>    public void onUserCreate(final User user) { <br>        Map&lt;String, Object&gt; serviceParams = new HashMap&lt;String, Object&gt;(); <br>        serviceParams.put(ResourceResolverFactory.SUBSERVICE, USER_ADMIN); <br>        try (ResourceResolver serviceUserResolver = this.resourceResolverFactory.getServiceResourceResolver(serviceParams)) { <br>            Session session = serviceUserResolver.adaptTo(Session.class); <br>            if (null != session) { <br>                getUserFromProps(user, session, userPropertiesService);<br>                if (session.isLive()) { <br>                    session.logout(); <br>                    session = null; <br>                } <br>            } <br>        } catch (final RepositoryException e) { <br>            log.error(&quot;onUserCreate: failed to copy profile properties to cq profile&quot;, e); <br>        } catch (LoginException e) { <br>            log.error(&quot;Unable to create service user resource resolver : &quot;, e); <br>        } <br>    } <br><br>    protected void getUserFromProps(User user, Session session, <br>                            UserPropertiesService userPropertiesService) throws RepositoryException { <br>        session.refresh(true); <br>        final Node userNode = session.getNode(userPropertiesService.getAuthorizablePath(user.getID())); <br>        final Node profNode = userNode.getNode(&quot;profile&quot;);<br> <br>        if (user.hasProperty(&quot;profile/givenName&quot;)) { <br>            String firstName = user.getProperty(&quot;profile/givenName&quot;)[0].getString(); <br>            profNode.setProperty(&quot;givenName&quot;, firstName); <br>        } <br><br>        if (user.hasProperty(&quot;profile/familyName&quot;)) { <br>            String lastName = user.getProperty(&quot;profile/familyName&quot;)[0].getString(); <br>            profNode.setProperty(&quot;familyName&quot;, lastName); <br>        } <br><br>        if (user.hasProperty(&quot;profile/email&quot;)) { <br>            String email = user.getProperty(&quot;profile/email&quot;)[0].getString(); <br>            profNode.setProperty(&quot;email&quot;, email); <br>        } <br>        session.save(); <br>        session.refresh(true); <br>    } <br><br>    protected String getPropertyPath(final String property) { <br>        return &quot;profile/&quot; + property; <br>    } <br><br>    @Override <br>    public String getUserFolderPath(String userId, String clientId, Map&lt;String, Object&gt; props) { <br>        StringBuilder sb = new StringBuilder(getId()); <br>        if (userId != null) <br>            sb.append(&quot;/&quot;).append(userId.substring(0, 4)); <br>        return sb.toString(); <br>    } <br><br>    @Override <br>    public String getAccessTokenPropertyPath(String clientId) { <br>        return &quot;profile/app-&quot; + clientId; <br>    } <br> <br>    @Override <br>    public User getCurrentUser(SlingHttpServletRequest request) { <br>        Authorizable authorizable = (Authorizable) request.adaptTo(Authorizable.class); <br>        if (authorizable != null &amp;&amp; !authorizable.isGroup()) <br>            return (User) authorizable; <br>        return null; <br>    } <br><br>    @Override <br>    public void onUserUpdate(User user) { <br>        onUserCreate(user); <br>    } <br> <br>    @Override <br>    public OAuthRequest getProtectedDataRequest(String url) { <br>        return new OAuthRequest(Verb.GET, url); <br>    } <br> <br>    @Override <br>    public Map&lt;String, String&gt; parseProfileDataResponse(Response response) throws IOException { <br>        try { <br>            Gson gson = new Gson(); <br>            log.error(&quot;Profile response - &quot; + response.getBody()); <br>            return gson.fromJson(response.getBody(), Map.class); <br>        } catch (JsonSyntaxException je) { <br>            throw new IOException(je); <br>        } <br>    } <br> <br>    @Override <br>    public Map&lt;String, Object&gt; mapProperties(String srcUrl, String clientId, Map&lt;String, Object&gt; existing, <br>                                             Map&lt;String, String&gt; newProperties) { <br>        Map&lt;String, Object&gt; mapped = new HashMap&lt;&gt;(); <br>        Gson gson = new Gson(); <br>        String jsonRep = gson.toJson(newProperties); <br>        Map&lt;String, Object&gt; mappedObject =  gson.fromJson(jsonRep, Map.class); <br>        Object roles = mappedObject.get(&quot;role&quot;); <br>        mapped.putAll(existing); <br>        for (Map.Entry&lt;String, String&gt; prop : newProperties.entrySet()) { <br>            mapped.put(mapProperty(prop.getKey()), prop.getValue()); <br>        } <br>        if (roles != null &amp;&amp; checkIfAuthorized(roles)) { <br>            mapped.put(&quot;profile/roles&quot;, roles); <br>            checkIfAuthorized(roles); <br>        } <br>        return mapped; <br>    } <br><br>    public String getUserIdProperty() { <br>        return &quot;name&quot;; <br>    } <br> <br>    public String getOAuthIdPropertyPath(String clientId) { <br>        return &quot;oauth/oauthid-&quot; + clientId; <br>    } <br><br>    public String getValidateTokenUrl(String clientId, String token) { <br>        this.log.info(&quot;This provider doesn&#39;t support the validation of a token&quot;); <br>        return null; <br>    } <br> <br>    public boolean checkIfAuthorized(Object roles) { <br>        return true; <br>    } <br> <br>    public boolean isValidToken(String responseBody, String clientId, String tokenType) { <br>        this.log.info(&quot;This provider doesn&#39;t support the validation of a token&quot;); <br>        return false; <br>    } <br> <br>    public String getUserIdFromValidateTokenResponseBody(String responseBody) { <br>        this.log.info(&quot;This provider doesn&#39;t support the validation of a token&quot;); <br>        return null; <br>    } <br> <br>    public String getErrorDescriptionFromValidateTokenResponseBody(String responseBody) { <br>        this.log.info(&quot;This provider doesn&#39;t support the validation of a token&quot;); <br>        return null; <br>    } <br><br>} </pre><p>Create CurityOAuth2ProviderImpl.java to support the authentication.</p><pre>package com.mycompany.aem.platform.core.auth.impl; <br><br>import com.adobe.granite.auth.oauth.Provider; <br>import com.adobe.granite.security.user.UserPropertiesService; <br>import com.mycompany.aem.platform.core.auth.CurityOAuth2Api; <br>import com.mycompany.aem.platform.core.auth.AscCurityProviderConfiguration; <br>import com.google.gson.Gson; <br>import com.google.gson.JsonSyntaxException; <br>import org.apache.sling.api.resource.ResourceResolverFactory; <br>import org.osgi.service.component.ComponentContext; <br>import org.osgi.service.component.annotations.*; <br>import org.osgi.service.metatype.annotations.Designate; <br>import org.scribe.model.Response; <br>import org.slf4j.Logger; <br>import org.slf4j.LoggerFactory; <br>import java.io.IOException; <br>import java.util.Map; <br><br>/** <br>* CurityOAuth2ProviderImpl is an implementation of the OAuth2 `Provider` interface that integrates with the Curity <br>* identity server for OAuth 2.0 authentication. This class handles the OAuth2 flow specific to Curity, including <br>* mapping user properties, retrieving user information, and managing user profiles within the AEM environment. <br>* It leverages the CurityOAuth2Api class to facilitate communication with Curity&#39;s OAuth2 endpoints. <br>* <br>* Key responsibilities: <br>* - Maps OAuth2 properties (such as given name, family name, and email) to AEM user profile fields. <br>* - Retrieves user profile data from Curity using OAuth2 access tokens and parses the response. <br>* - Manages user folders and profile paths for storing user-related data within AEM&#39;s repository. <br>* - Configures OAuth2 provider settings during activation using values from the CurityProviderConfiguration. <br>* - Defines a mechanism for user ID mapping based on OAuth2 claims (e.g., `sub` for subject ID). <br>*/ <br><br>@Component(service = Provider.class, <br>property = {&quot;oauth.provider.id=asccurity&quot;} ) <br>@Designate(ocd = CurityProviderConfiguration.class) <br>public class CurityOAuth2ProviderImpl extends OAuth2BaseProvider implements Provider { <br><br>    private final Logger log = LoggerFactory.getLogger(getClass()); <br>    private final String GIVEN_NAME = &quot;profile/givenName&quot;; <br>    private final String FAMILY_NAME = &quot;profile/familyName&quot;; <br>    private final String EMAIL = &quot;profile/email&quot;; <br>    private final String PROFILE_PATH = &quot;profile/&quot;; <br>    private final String SUB = &quot;sub&quot;; <br>    private final String OAUTH_USERINFO = &quot;/oauth-userinfo&quot;; <br><br>    @Reference <br>    private UserPropertiesService userPropertiesService; <br> <br>    @Reference(cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.STATIC) <br>    private ResourceResolverFactory resourceResolverFactory; <br><br>    public String mapProperty(String property) { <br>        if (&quot;given_name&quot;.equals(property)) <br>            return GIVEN_NAME; <br>        if (&quot;family_name&quot;.equals(property)) <br>            return FAMILY_NAME; <br>        if (&quot;email&quot;.equals(property)) <br>            return EMAIL; <br>        return getPropertyPath(property); <br>    } <br><br>    @Override <br>    public String mapUserId(final String userId, final Map&lt;String, Object&gt; props) { <br>        return (String) props.get(getPropertyPath(getUserIdProperty())); <br>    } <br><br>    protected String getPropertyPath(final String property) { <br>        return PROFILE_PATH + property; <br>    }<br> <br>    @Override <br>    public String getUserFolderPath(String userId, String clientId, Map&lt;String, Object&gt; props) { <br>        StringBuilder sb = new StringBuilder(getId()); <br>        if (userId != null) <br>            sb.append(&quot;/&quot;).append(userId.substring(0, 4)); <br>        return sb.toString(); <br>    }<br><br>    @Override <br>    public Map&lt;String, String&gt; parseProfileDataResponse(Response response) throws IOException { <br>        try { <br>            Gson gson = new Gson(); <br>            return gson.fromJson(response.getBody(), Map.class); <br>        } catch (JsonSyntaxException je) { <br>            throw new IOException(je); <br>        } <br>    } <br><br>    @Override <br>    public String getUserIdProperty() { <br>        return SUB; <br>    } <br> <br>    @Activate <br>    protected void activate(final CurityProviderConfiguration config) { <br>        super.name = getClass().getSimpleName(); <br>        super.id = config.providerId(); <br>        super.api = new CurityOAuth2Api(config.oAuthBaseURL()); <br>        super.profileUrl = config.oAuthBaseURL() + OAUTH_USERINFO; <br>        super.userPropertiesService = userPropertiesService; <br>        super.resourceResolverFactory = resourceResolverFactory; <br>    }<br><br>    @Deactivate <br>    protected void deactivate(final ComponentContext componentContext) { <br>        log.debug(&quot;deactivating provider id {}&quot;, id); <br>    } <br><br>} </pre><p>Create a Provider Configuration class — CurityProviderConfiguration.java</p><pre>package com.mycompany.aem.platform.core.auth; <br><br>import org.osgi.service.metatype.annotations.AttributeDefinition; <br>import org.osgi.service.metatype.annotations.ObjectClassDefinition; <br><br>/** <br>* CurityProviderConfiguration is an OSGi configuration interface used to define the settings for the Curity OAuth <br>* provider. It provides the configuration options required to integrate Curity&#39;s OAuth 2.0 service for authentication <br>* in an AEM environment. <br>* <br>* This configuration interface provides the below options: <br>* - `oauth.provider.id`: A unique identifier for the OAuth provider (default: &quot;asccurity&quot;). <br>* - `oAuthBaseURL`: The base URL for the Curity OAuth2 service, which is used to construct API endpoints for <br>*   authentication, authorization, and token exchange operations. <br>*/ <br><br>@ObjectClassDefinition(name = &quot;Curity Server Provider Configuration&quot;, <br>        description = &quot;Curity Server Provider Configuration&quot;) <br>public @interface CurityProviderConfiguration { <br><br>    @AttributeDefinition(name = &quot;oauth.provider.id&quot;, description = &quot;OAuth Provider ID&quot;) <br>    String providerId() default &quot;asccurity&quot;; <br><br>    @AttributeDefinition(name = &quot;oAuthBaseURL&quot;, description = &quot;base URL for the provider&quot;) <br>    String oAuthBaseURL(); <br><br>} </pre><p><strong>OSGi Configurations:</strong></p><p>Create a repository initialization script to set up the “asc-users” user group, which will be used for creating users upon successful authentication and configured in the Granite OAuth provider in the next step. Assume there are two folders: “marketing” and “designer”. The path for the marketing folder is “/content/dam/mycompany/marketing”, and the path for the designer folder is “/content/dam/mycompany/designer”. Consider a scenario where the logged-in user should only have access to the assets within the marketing folder and should not be able to access the assets in the designer folder. To achieve this, configure the permissions to grant access to the assets in the “marketing” folder while denying access to the assets in the “designer” folder for the “asc-users” group.</p><p>org.apache.sling.jcr.repoinit.RepositoryInitializer~asc-user-group.cfg.json</p><pre>{ <br>  &quot;scripts&quot;: [ <br>&quot;create path /content/dam/mycompany/marketing (sling:Folder)/jcr:content(nt:unstructured)&quot;, <br>&quot;create path /content/dam /mycompany/designer(sling:Folder)/jcr:content(nt:unstructured)&quot; <br>&quot;create group \&quot;asc-users\&quot;&quot;, <br>&quot;set ACL for \&quot;asc-users\&quot;\n allow jcr:all on /content/dam/mycompany/marketing\nend&quot;, <br>&quot;set ACL for \&quot;asc-users\&quot;\n deny jcr:all on /content/dam /mycompany/designer\nend&quot; <br>] <br>} </pre><p>Create a Granite OAuth Application and Provider configuration — com.adobe.granite.auth.oauth.provider~curity.cfg.json</p><pre>{ <br>  &quot;oauth.client.id&quot;:&quot;$[env:curityClientId]&quot;, <br>  &quot;oauth.redirect.request.params&quot;:true, <br>  &quot;oauth.access.token.persist.cookie&quot;:true, <br>  &quot;oauth.hash.userids&quot;:true, <br>  &quot;oauth.callBackUrl&quot;:&quot;$[env:curityCallbackUrl]&quot;, <br>  &quot;oauth.config.id&quot;:&quot;&lt;config-id&gt;&quot;, <br>  &quot;oauth.client.secret&quot;:&quot;$[secret:curityClientSecret]&quot;, <br>  &quot;oauth.create.users&quot;:true, <br>  &quot;oauth.create.users.groups&quot;:[ <br>    &quot;asc-users&quot; <br>  ], <br>  &quot;oauth.access.token.persist&quot;:true, <br>  &quot;oauth.scope&quot;:[ <br>    &quot;openid&quot; <br>  ], <br>  &quot;oauth.config.provider.id&quot;:&quot;asccurity&quot; <br>}</pre><p>&lt;config-id&gt; — Provide a unique to identify the above provider configuration. It will also be used in the login URL.</p><p>Create a Custom provider configuration — com.mycompany.aem.platform.core.auth.impl.CurityOAuth2ProviderImpl.cfg.json</p><pre>{<br>  &quot;oAuthProviderId&quot;:&quot;&lt;config-id&gt;&quot;, <br>  &quot;oAuthBaseURL&quot;:&quot;&lt;curity-base-url&gt;&quot; <br>} </pre><p>&lt;config-id&gt; — Provide the same config-id given in the Granite OAuth Provider configuration in the previous step.</p><p>&lt;curity-base-url&gt; — You can find this from info available in the client you created for ASC in Curity Sandbox. For example, it will be like <a href="https://login.mycompany.com/oauth/v2.">https://login.mycompany.com/oauth/v2.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*2lIWu_SnasBiU3nW5C3ZVw.png" /></figure><p><strong>Cloud Environment Variables:</strong></p><p>Create the following variables in the AEM Cloud Environment, which will be used in the OSGi configurations:</p><ol><li>curityClientId(Variable) - Add the Client name defined in the Curity setup</li><li>curityCallbackUrl(Variable) - Add the redirect URL whitelisted in the Curity setup</li><li>curityClientSecret(Secret) - Add the Client secret generated during the Curity setup</li></ol><p><strong>Login Integration Testing:</strong></p><p>Create a new login page that includes a login button. Configure the login URL as /j_security_check?configid=&lt;config-id&gt;. When the login button is clicked, users will be redirected to the Curity authentication page. New users can register, while existing users can log in directly.</p><p>Login:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*jaSIK-3w871b3XJ7c9pqBg.jpeg" /></figure><p>Sign Up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*PNnsJ9AtmFn57LKwlFx__w.png" /></figure><p>Upon successful authentication, the user will be redirected to the URL set in both Curity and AEM.</p><p><strong>Access Permission Testing:</strong></p><p>Additionally, users will only have access to assets within the marketing folder as specified in the permissions and will be restricted from accessing any assets in the designer folder.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8202df6fbf52" width="1" height="1" alt=""><hr><p><a href="https://medium.com/activate-aem/asset-share-commons-login-integration-8202df6fbf52">Asset Share Commons Login Integration</a> was originally published in <a href="https://medium.com/activate-aem">Activate AEM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AEP Use Case: Sending data from AEM to AEP through Web SDK:]]></title>
            <link>https://medium.com/activate-aem/aep-use-case-sending-data-from-aem-to-aep-through-web-sdk-bcaea6796d09?source=rss-935fd6621ced------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcaea6796d09</guid>
            <category><![CDATA[aem-developer]]></category>
            <category><![CDATA[aep]]></category>
            <category><![CDATA[adobe]]></category>
            <category><![CDATA[aem]]></category>
            <dc:creator><![CDATA[Balaji Srinivasan]]></dc:creator>
            <pubDate>Wed, 07 Feb 2024 04:48:39 GMT</pubDate>
            <atom:updated>2024-02-07T05:11:14.404Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>AEP Use Case: Sending data from AEM to AEP through Web SDK</strong></h3><p>Real time data is vital in providing personalized experiences to the end user. Adobe Experience Platform helps organize the customer data in a standard way. It can send and receive data from different systems. This article focuses on the steps required in sending data from AEM to AEP taking user email as an example.</p><p><strong>Pre-requisite:</strong></p><ul><li>User’s email address is available in the data layer object.</li></ul><p><strong>Steps Involved:</strong></p><ol><li>Create Schema and Dataset on Adobe Experience Platform</li><li>Configure Datastream on AEP Data Collection</li><li>Configure tag property on AEP Data Collection</li><li>Embed the JS library to the AEM page.</li></ol><p><strong>Creating Schema and Dataset:</strong></p><p>Ensure that you have the required permissions to Adobe Experience Platform and Adobe Experience Platform Data Collection Products.</p><p>Log into <a href="https://experience.adobe.com/">https://experience.adobe.com/</a>. Click on Experience Platform to open the Adobe Experience Platform Interface.</p><p>Click on the sandbox dropdown in the top right corner of the window and select the sandbox you are going to work with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/0*vqSq32ALBg9s-cXd" /></figure><p>A Schema defines the structure of the data. To create a schema, click Schemas option available on the left navigation. If you can’t find the option there, then you don’t have enough permissions to manage schemas. Check your permissions again and proceed to the next steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*u4BFjQuIQhZxe5zk6oz6yA.png" /></figure><p>Click on Create Schema in the top right corner. It will display three options.</p><ol><li>Individual Profile</li><li>Experience Event</li><li>Custom</li></ol><p>Through Web SDK, we can send data only to the Experience Event type dataset. So, you need to create a schema of Experience Event type.</p><p>Select Experience Event type and click Next. Enter the name for Schema and click Finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W3cSJ6mYjyTyax2N" /></figure><p>Add Personal Contact Details Field Group to the newly created schema. In the personal contact details field group, you can see a field for email under personalEmail -&gt; address. Save the changes.</p><p>Now, navigate to the Datasets section through the left rail. Click on Create dataset. You are provided with two options. Select Create dataset from schema.</p><p>Search for the schema created and select it. Click on Next. Enter the name for Dataset and click Finish.</p><p>Now you have successfully created the schema and dataset.</p><p><strong>Configure Datastream on AEP Data Collection:</strong></p><p>A datastream is required to let the Adobe Edge Network know where to forward the requested data. We need the data to be sent to Adobe Experience Platform. We will configure a datastream for AEP.</p><p>Navigate to the AEP Data Collection Interface through the link available on the top right corner or follow the link <a href="https://experience.adobe.com/launch/">https://experience.adobe.com/launch/</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/0*MyCxxI5B9IOW6vOl" /></figure><p>Navigate to Datastreams through left navigation. Click on New Datastream.</p><p>Give any name and select the sandbox created previously. Click Save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_xRyTKpjBeIjQRqr" /></figure><p>It would have created a new datastream and you must add AEP to that datastream.</p><p>Click Add Service. Select Adobe Experience Platform in the Service dropdown. Select the dataset created in the Event dataset dropdown. Then Click Save.</p><p>Now you have added AEP to the new Datastream which will forward the data to Experience Platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PB66Giz8q64AdAvz" /></figure><p><strong>Configure Tag Property:</strong></p><p>A Tag property will give a JS library that contains the rules required to collect the data from the webpage.</p><p>Go to Tags through left navigation. Click New Property on the right side. Give any name to the tag property and add your web domain. Click Save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/0*rPp4z26qGLa2yrOM" /></figure><p>From the list of tag properties, search for the property you created and click to open it.</p><p>Go to Extension through the left rail. Core Extension should be available by default. You need to add the AEP Web SDK extension to the tag property.</p><p>Click on Catalog Tab. Search for web sdk. Select the Adobe Experience Platform Web SDK extension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EUTZMrQcG7pTscAA" /></figure><p>Click Install. In the new window, select the sandbox you are using and the datastream which was created before for all the environments and save the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7zw3-0v2_BLEL4S-" /></figure><p>Now go to Rules. Click Create New Rule. Enter any name for the rule.</p><p>Click Add below the Events. Select Core in the Extension and Window Loaded as Event type. Save changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6juPniRXo8xl_KHa" /></figure><p>No need to add any conditions if you want the rule to fire on all pages.</p><p>Click Add below the Actions. Select Adobe Experience Platform Web SDK in the extension and Sent Event as Action type. Select ‘Web Webpagedetails Page Views’ as Type on the right side. Keep the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dRi_Lv6gvOpxcVNP" /></figure><p>Save the rule.</p><p>Go to the Publishing flow. Click Add Library. Give any name and select Development in the environment dropdown. Click Add All Changed Resources. You should see the rule added.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vhEpbrE_ky3KGKPg" /></figure><p>Click Save &amp; Build to Development. You should see the library as Active (Green Dot) in the Development Column.</p><p>Now you need to create data elements to collect the data from AEM. We are going to create one element for user email. Go to Data Elements and click Create New Data Element.</p><p>Give any name or Email. Select Core in the Extension and Java Script Variable as Data Element Type. Say there is a datalayer object called <strong>pageDataLayerObject</strong> like below (it can be different for you; it should be used).</p><pre>{<br>  &quot;properties&quot;: {<br>    &quot;@type&quot;: &quot;&lt;sample-project-base&gt;/components/structure/page/basepage&quot;,<br>    &quot;repo:modifyDate&quot;: &quot;2023–11–21T18:38:05Z&quot;,<br>    &quot;dc:title&quot;: &quot;Home Page&quot;,<br>    &quot;dc:description&quot;: &quot;Home Page&quot;,<br>    &quot;xdm:template&quot;: &quot;/conf/&lt;sample-project&gt;/settings/wcm/templates/freeform&quot;,<br>    &quot;xdm:language&quot;: &quot;en&quot;,<br>    &quot;xdm:tags&quot;: [],<br>    &quot;repo:path&quot;: &quot;/content/&lt;sample-project&gt;/language-masters/en.html&quot;,<br>    &quot;canonicalUrl&quot;: &quot;https://&lt;sample-project&gt;.com/language-masters/en.html&quot;,<br>    &quot;pageName&quot;: &quot;homepage&quot;,<br>    &quot;pageType&quot;: &quot;freeform&quot;,<br>    &quot;siteSection&quot;: &quot; homepage&quot;,<br>    &quot;localTimestamp&quot;: &quot;2024–01–16T13:08:39&quot;,<br>    &quot;user&quot;: {<br>      &quot;email&quot;: &quot;test-user@gmail.com&quot;<br>    }<br>  }<br>}</pre><p>Email can be accessed like this pageDataLayerObject.properties.user.email and the same can be provided to the Javascript variable name. Save the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n-efyOFWct24Q41N" /></figure><p>Now we have a data element which will hold the value of an email. But it should be mapped to the XDM schema field.</p><p>For that purpose, create another data element XDM Object. Select Adobe Experience Platform Web SDK in the extension and XDM Object as Data Element Type.</p><p>Select the Sandbox and schema. It will display the selected schema structure. Go to personalEmail &gt; address. For the value of the address field, select the data element where you have captured the user email address. Save the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c3-1nJ__sQr0o3Or" /></figure><p>Now the data is available in the XDM schema format through the XDM Object data element. And it must be sent to Adobe Experience Platform Dataset.</p><p>Go to Rules, Open the rule created and click the send event action. Map the XDM Object data element to the XDM field available on the right side. Keep the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2pkoak8IV6iExi8r" /></figure><p>Whenever there is a change in the rule, build it again. Select the library you created on the top. Click Save to Library dropdown and select Save to Library and Build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m8KaL4fQ1s1A4wQo" /></figure><p>You have successfully created the tag property.</p><p><strong>Embed the JS library:</strong></p><p>Tag property is a JavaScript library that can be embedded onto the AEM page. It gets triggered based on the rule set up in the tag property. To find the library, Go to Environments. In the Development Environment, select the option in the Install column. You can find the JS library there and embed it inside the head tag.</p><p>We can use the Adobe Experience Platform Debugger to validate the data ingestion.</p><p>Install the Adobe Experience Platform Debugger extension. Open the debugger and sign in. At the bottom, you can see the connected page.</p><p>If you want to connect to a different page, open the page in another tab and lock it in the debugger so the debugger is not switching to another page when the browser tab is changed and remains connected to the same page.</p><p>Now to include the JS library in the page, go to Experience Platform Tags in the debugger. Switch to Configuration Tab. Click Add new embed code under Injected Embed Codes.</p><p>Select the created Tag property from the dropdown. Select Development in the environment. Click Apply.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/0*9h26PYe553PiknGL" /></figure><p>Once it is applied, the library would have been embedded onto the page. Since the page is refreshed by this action and the window is loaded again, a request has been sent with the data. You can verify it using the Network tab in developer console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RkK9V8ftWlqtUAQ_" /></figure><p>Now the data will be available in the created dataset. It can take up to 15 minutes for the data to be available on the Adobe Experience platform.</p><p>Go to Datasets in AEP and open the dataset created. You can see that the data is ingested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Vp3IeSFTguMfsTbz" /></figure><p>Click Preview dataset to preview the data that has been ingested at the last run.</p><p>You have successfully sent the data from AEM Page to Experience platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcaea6796d09" width="1" height="1" alt=""><hr><p><a href="https://medium.com/activate-aem/aep-use-case-sending-data-from-aem-to-aep-through-web-sdk-bcaea6796d09">AEP Use Case: Sending data from AEM to AEP through Web SDK:</a> was originally published in <a href="https://medium.com/activate-aem">Activate AEM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>