Friday, December 29, 2017

Restrict the access to SOA Composite Service based on the User Role (Authorization to the SOA Composite Service) – Oracle SOA Suite 12c

Restrict the access to SOA Composite Service based on the User Role (Authorization to the SOA Composite Service) – Oracle SOA Suite 12c

Sometimes we may need to restrict the access to the SOA composite service based on the user role.
HTTP basic authentication and an authorization policy can be used to ensure that access is only granted to users who are members of a particular role.

This blog will explain the steps to enable authorization to our composite service.

Configure the Users and Group:

  • Login to the Weblogic console ('http://<host>:<port>/console')
  • In the left menu select 'Security Realms'
  • Select the realm where you want to create the users and groups.  The default is 'myrealm'
  • At the top select the 'Users and Groups' tab
  • Select User tab and Click 'New' and enter your user name and pwd.  Here am creating the user albin and albin1, create as many users as you want
  • Select ‘Groups’ tab and create a new group.  Here I am creating  ‘IntegrationGroup’
  • Go back to the users and click on  'Albin'
  • Select the 'Groups' tab and add ‘IntegrationGroup’.  The user albin1 will not be part of this group.

Configure the Application Role:

  • Login to EM console
  • Click on Target Navigation - WebLogic Domain - Domain Name 
  • Click on Weblogic Domain - Select Security and Click on Application Roles
soa-infra_application_roles
  • Select Application Stripe as soa-infra
  • Click on 'Create' to configure a new Application Role


Friday, December 22, 2017

Approach to 301 redirect the internal URL's to dynamic SEO friendly URL - Adobe Experience Manager

Approach to 301 redirect the internal URL's to dynamic SEO friendly URL - Adobe Experience Manager

This post will explain the approach to 301 redirect the internal URL's to dynamic SEO friendly URL.

We had a scenario to display the SEO friendly URL to the user instead of displaying the internal URL for the PDP pages in eCommerce website - The SEO friendly URL is formed dynamically based on the product title and format from Hybris.

The internal product URL is - /en/test/pdp/book.html?id=123(Internal Publisher page that handle the request based on the product id)
New SEO friendly URL - /en/test/Sample_Book/book/pdp.html?id=123(Dynamic URL and should be rewritten to internal URL to process by publisher )

When ever user access the SEO specific URL(/en/test/Sample_Book/book/pdp.html?id=123) in the browser the user should be redirected to internal URL(/en/test/pdp/book.html?id=123) without changing the Browser URL.

Also, the user should be 301 redirected to SEO friendly URL while accessing the internal URL directly from the browser.

Redirect the internal URL to new Dynamic URL:


As the new URL is dynamic based on the product title and product format` from Hybris, the dispatcher rules cant be defined to handle the redirect from internal URL to new SEO friendly dynamic URL.

The alternative solution is define a Request filter that will form the dynamic URL by fetching the product tile from Hybris and 301 redirect to new URL.

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import org.apache.felix.scr.annotations.sling.SlingFilter;
import org.apache.felix.scr.annotations.sling.SlingFilterScope;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;

@SlingFilter(label = "301 URL redirector", description = "301 URL redirector", metatype = true, generateComponent = true, // True if you want to leverage activate/deactivate
generateService = true, order = 0, scope = SlingFilterScope.REQUEST)
public class Redirect301HandlerFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
String requestPath= slingRequest.getRequestURI();
String pid = slingRequest.getParameter("pid");
if (!requestPath.contains("/pdp/") || slingRequest.getParameter("isInternalRedirect")!=null) {
chain.doFilter(request, response);
return;
}

String title = "";// Get the product tile and product format from Hybris based on the pid
String format = "";//// Get the product tile and product format from Hybris based on the pid

String newURL = slingRequest.getScheme() + "://" + slingRequest.getServerName() + ":"+ slingRequest.getServerPort() + "/en/test/" + title + "/" + format + "/pdp.html?pid=" + pid;

slingResponse.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
slingResponse.setHeader("Location", newURL);
}

@Override
public void destroy() {
// TODO Auto-generated method stub
}
}

Rewrite the SEO friendly URL to internal URL:


The SEO friendly URL is not recognized by publisher so rewrite the SEO friendly URL to internal URL in dispatcher without changing browser URL.The below post provides the steps to rewrite the URL to internal URL without changing the browser URL.

https://www.albinsblog.com/2017/11/rewrite-rules-with-ptpass-through-flag-notwork-in-aem.html

Add a additional parameter isInternalRedirect while rewriting the SEO URL to internal URL from Dispatcher to avoid the redirect loop

RewriteCond %{QUERY_STRING} ^id=(.*) [NC]
RewriteRule ^/en/test/(.*)/(.*)/pdp.html$ /en/test/pdp/$2.html?isInternalRedirect=true&id=%1 [PT,L]


Monday, December 18, 2017

How to get the Inherited Properties in Adobe Experience Manager Servlet's or Filter's

How to get the Inherited Properties in Adobe Experience Manager Servlet's or Filter's

This post will explain the approach to get the inherited properties in AEM servlet's or Filter's.

Sample Filter - Retrieves the inherited page properties and component properties:


HierarchyNodeInheritanceValueMap - This will help to retrieve the inherited properties from parent pages.

While accessing the property prop1 from /content/site/en/test/jcr:content - /content/site/en/test/jcr:content/@prop1,the system searches in the following paths

/content/site/en/test/jcr:content/@prop1
/content/site/en/jcr:content/@prop1
/content/site/jcr:content/@prop1

If the prop1 is located in any of the above paths then the corresponding values is returned, if not it will return null value.

ComponentInheritanceValueMap - This will help to retrieve the inherited properties from parent components.

While accessing the prop2 property from /content/site/en/test/jcr:content/T01_region4/titletext_e8d0 - /content/site/en/test/jcr:content/T01_region4/titletext_e8d0/@prop2,the system searches in the following paths

/content/site/en/test/jcr:content/T01_region4/titletext_e8d0/@prop2
/content/site/en/test/jcr:content/T01_region4/@prop2
/content/site/en/test/jcr:content/@prop2

If the prop2 is located in any of the above paths then the corresponding values is returned, if not it will return null value.

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;

import org.apache.felix.scr.annotations.*;
import org.apache.felix.scr.annotations.sling.SlingFilter;
import org.apache.felix.scr.annotations.sling.SlingFilterScope;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;

import com.day.cq.commons.inherit.ComponentInheritanceValueMap;
import com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap;
import com.day.cq.commons.inherit.InheritanceValueMap;

@SlingFilter(label = "301 URL redirector", description = "301 URL redirector", metatype = true, generateComponent = true,
generateService = true, order = 0, scope = SlingFilterScope.REQUEST)
public class Redirect301HandlerFilter implements Filter {

@Override
public void init(FilterConfig filterConfig) throws ServletException {

}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
String resourcePathURL = slingRequest.getResource().getPath();

ResourceResolver resourceResolver = slingRequest.getResourceResolver();
String resourceContentPath = resourcePathURL.split(".html")[0] + "/jcr:content";
Resource res = resourceResolver.getResource(resourceContentPath);

InheritanceValueMap inheritedProp = new HierarchyNodeInheritanceValueMap(res);
String prop1 = inheritedProp.getInherited("prop1", String.class);

res = resourceResolver.getResource(resourceContentPath+"/T01_region4/titletext_e8d0");

InheritanceValueMap inheritedPropCom = new ComponentInheritanceValueMap(res);
String prop2 = inheritedPropCom.getInherited("prop2", String.class);

chain.doFilter(slingRequest, slingResponse);

}

@Override
public void destroy() {
// TODO Auto-generated method stub

}

}



Thursday, December 14, 2017

com.day.cq.searchpromote.Search ParseError at [row,col]:[1,1] Message: Content is not allowed in prolog - Adobe Search and Promote

com.day.cq.searchpromote.Search ParseError at [row,col]:[1,1] Message: Content is not allowed in prolog - Adobe Search and Promote

I was getting the below exception while searching the documents from Search&Promote in Adobe Experience Manager website.

14.12.2017 17:49:43.040 *ERROR* [10.204.139.58 [1513273782091] GET /content/test/en/search.html HTTP/1.1] com.day.cq.searchpromote.Search ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
        at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:596)
        at com.sun.xml.internal.stream.XMLEventReaderImpl.nextEvent(XMLEventReaderImpl.java:83)
        at com.day.cq.searchpromote.xml.result.ResultParser.getNextEvent(ResultParser.java:61)
        at com.day.cq.searchpromote.xml.result.ResultParser.parse(ResultParser.java:48)
        at com.day.cq.searchpromote.Search.parseResults(Search.java:526)
        at com.day.cq.searchpromote.Search.<init>(Search.java:154)
        at com.tr.openweb.ecommerce.sly.search.SearchInitializer.activate(SearchInitializer.java:69)
        at com.tr.openweb.ecommerce.sly.search.SearchBarPage.activate(SearchBarPage.java:19)
        at com.adobe.cq.sightly.WCMUsePojo.init(WCMUsePojo.java:84)
        at org.apache.sling.scripting.sightly.impl.engine.extension.use.JavaUseProvider.provide(JavaUseProvider.java:119)
        at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:84)
        at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.call(RenderContextImpl.java:66)
        at org.apache.sling.scripting.sightly.apps.test.components.search.searchBarPage.SightlyJava_searchBarPage.render(SightlyJava_searchBarPage.java:44

I was not able to identify any configuration issues with AEM  or Search&Promote.

It looks to be the issue was caused due to the renaming of existing Search-Promote cloud configuration in AEM, the renaming of the configuration created some internal issue and due that the search was failing with parsing error, the issue got resolved after deleting and recreating the Search-Promote cloud configuration.


IndexConnector prefetch failed - Adobe Search and Promote

IndexConnector prefetch failed - Adobe Search and Promote 

Index Connector can be used to define additional input sources for indexing XML pages or any kind of feed.

The  Index Connector is not enabled in the Search and Promote account by default, the  Index Connector can be only enabled by reaching out to Search and Promote consultant or support team.

Search_and_promote_index_connector

After enabling the Index Connector the regular indexing stopped working with the following exception.

1: 12/14 13:10:14 CST ======== Starting manual crawl of account spxxxxxx. ========
2: 12/14 13:10:14 CST ERROR: IndexConnector prefetch failed.
3: 12/14 13:10:15 CST Starting update of slice list.
4: 12/14 13:10:15 CST Skipping update of slice list - no change since last update.
5: 12/14 13:10:15 CST Refreshing auto-complete word list.
6: 12/14 13:10:15 CST Finished refreshing auto-complete word list.
7: 12/14 13:10:15 CST Creating GS config.
8: 12/14 13:10:15 CST Finished creating GS config.
9: 12/14 13:10:15 CST --------------------------------------------------------------------
10: 12/14 13:10:15 CST *** Crawl Summary ***
11: 12/14 13:10:15 CST Start Time: 12/14/2017 13:10:14 CST
12: 12/14 13:10:15 CST End Time: 12/14/2017 13:10:15 CST
13: 12/14 13:10:15 CST Elapsed Time: 1 second
14: 12/14 13:10:15 CST Pages Crawled: 0 pages
15: 12/14 13:10:15 CST Words/Bytes Indexed: 0 words/ 0 bytes
16: 12/14 13:10:15 CST Depth: 1
17: 12/14 13:10:15 CST Errors: 1
18: 12/14 13:10:15 CST Starting update of slice list.
19: 12/14 13:10:15 CST Skipping update of slice list - no change since last update.
20: 12/14 13:10:15 CST *** Index Summary ***
21: 12/14 13:10:15 CST Total Pages: 278
22: 12/14 13:10:15 CST --------------------------------------------------------------------
23: 12/14 13:10:15 CST ======== Finish manual crawl of account spxxxxx: Aborted. ========

This will be fixed after enabling at least one Index Connector configuration, if the actual Index Connector Configuration can't be created then create a dummy configuration with disabled status that will fix the indexing issue.
S&P_index_connector_configuration

S&P_index_connector_configuration