Menu

Showing posts with label AEM. Show all posts
Showing posts with label AEM. Show all posts

Getting forbidden response for AEM login page

If  you are facing problem to access the AEM login page; /libs/granite/core/content/login.html and getting HTTPERROR 403, FORBIDDEN and in log you are getting below error message. Its means somehow you have updated the SlingAuthenticator configuration.

*INFO* [0:0:0:0:0:0:0:1 [1402592178132] GET / HTTP/1.1] org.apache.sling.auth.core.impl.SlingAuthenticator getAnonymousResolver: Anonymous access not allowed by configuration - requesting credentials
*INFO* [0:0:0:0:0:0:0:1 [1402592178132] GET / HTTP/1.1] org.apache.sling.auth.core.impl.SlingAuthenticator handleLoginFailure: Unable to authenticate anonymous user: Login Failure: all modules ignored

AEM login page forbidden error, http error 403
AEM login page forbidden

Resolution:


Step 1: Under the configuration "Apache Sling Authentication Serviceverify the entry of login page in property Authentication Requirements (sling.auth.requirements) set with minus symbol [-/libs/granite/core/content/login]. If you found the correct entry then check the second step.

Step 2: We have another property sling.auth.anonymous.user under the same configuration. Somehow this property has been updated hence system is unable to open the login page which should be accessible to anonymous user. 

Explanation of sling.auth.anonymous.user property; it defines which user name to assume for anonymous requests, that is requests not providing credentials supported by any of the registered authentication handlers. If this property is missing or empty, the default is assumed which depends on the resource provider(s). Otherwise anonymous requests are handled with this user name. If the configured user name does not exist or is not allowed to access the resource data, anonymous requests may still be blocked. If anonymous access is not allowed, this property is ignored.



To fix this issue, go to AEM config manager [/system/console/configMgr] and search for "Apache Sling Authentication Service" or go directly using this link in your local AEM instance 
http://localhost:4502/system/console/configMgr/org.apache.sling.engine.impl.auth.SlingAuthenticator

But since, we are unable to login into the AEM, and without login we cant access the felix console(config manager). Hence we will upadte the config from crx-quickstart repository. The same config file we will find in our crx-quickstart folder under directory launchpad
\crx-quickstart\launchpad\config\org\apache\sling\engine\impl\auth
in this file if you see there is some value assign to property sling.auth.anonymous.user then make it empty like sling.auth.anonymous.user=""

Sample SlingAuthenticator.config file



What is experience fragment in AEM?


  • Experience fragment is a kind of page or content.
  • Experience fragment is reusable content, we could use same content in multiple pages.
  • Experience fragment is fully responsive, and support and fit in almost all the screen size.
  • Experience fragment have variations for omni-channel delivery.
  • Experience fragment is based on template design, we have to create a template of the content before creating a experience fragment. In template we specify the layout of our content.
  • We can use experience fragment as a page.
  • Using experience fragment we can create a post or page for social media and other channels(using template) and feed or publish your post or page directly on those channels from AEM (adobe experience manager).
  • Experience fragment is more innovative version of  content fragment in AEM.
  • Experience fragment feature comes in AEM 6.3.
  • Experience fragment can have content fragment into it.

See also:

Execute a query in AEM

Execute SQL query with the help of QueryManger interface in Adobe Experience Manager(AEM) using Java.

QueryManager interface encapsulates methods for the management of search queries. Provides methods for the creation and retrieval of search queries.

Method used: createQuery

In this sample program we have created a sling servlet and register that servlet on paths. When browser make the request to registered path then a serch query will get executed and find the all nodes which contains resourceType "granite/ui/components/foundation/form/textfield" under path "/apps/myproject/components/config".
 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;

@SlingServlet(paths ="/bin/private/addMissingProperties", methods = "GET", selectors="", extensions="html", metatype=true)
public class AddDialogProperties extends SlingAllMethodsServlet{
 /**
  *
  */
 private static final long serialVersionUID = 1L;
 Logger LOGGER=org.slf4j.LoggerFactory.getLogger(AddDialogProperties.class);

 protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
  String queryStatement = "SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/apps/myproject/components/config]) AND [sling:resourceType] = \"granite/ui/components/foundation/form/textfield\"";
  ResourceResolver resourceResolver=request.getResourceResolver();
  javax.jcr.Session session=resourceResolver.adaptTo(javax.jcr.Session.class);
  QueryManager queryManager;
  try {
   queryManager = session.getWorkspace().getQueryManager();
   Query query = queryManager.createQuery(queryStatement, Query.JCR_SQL2);
   QueryResult result = query.execute();
   NodeIterator nodes;
   nodes = result.getNodes();
   while (nodes.hasNext()) {
    Node node = nodes.nextNode();
    ModifiableValueMap mvp=resourceResolver.getResource(node.getPath()).adaptTo(ModifiableValueMap.class);
    mvp.put("value", " ");
    resourceResolver.commit();
   }
  } catch (Exception e) {
   LOGGER.error("Exception occured in class AddDialogProperties {}" ,e);
  }
 }

}

What is Sling and why have multiple scripts/renderers for a Component?


Apache Sling is one of the technology stack of AEM/CQ5 CMS on which AEM is built on. Sling is a Web application framework based on REST principles that provides easy development of content-oriented applications. In general terms we can say Sling is used to resolve the resources or URI in our application. Sling uses a JCR repository, such as Apache Jackrabbit or Day's CRX, as its data  store.
Sling maps HTTP request URLs to content resources based on the request's path, extension and selectors.

The Resource is one of the central parts of Sling. Extending from JCR, Everything is Content, and Sling assumes that Everything is a Resource.

Apache Sling is included in the installation of CQ5. Sling has since been contributed to the Apache Software Foundation - further information can be found at Apache Sling.
Using Apache Sling, the type of content to be rendered is not the first processing consideration. Instead the main consideration is whether the URL resolves to a content object for which a script can then be found to perform the rendering. This provides excellent support for Web content authors to build
Pages which are easily customized to their requirements.
The advantages of this flexibility are apparent in applications with a wide range of different content elements, or when you need Pages that can be easily customized/viewed differently.


How sling used to resolve a URL (Resource) in AEM? and How sling works internally?

The following diagram explains the Sling script resolution. It shows how to get from HTTP request to content node, from content node to resource type, from resource type to script and what scripting variables are available.

how sling resolve a resource in AEM. Adobe CQ, AEM sling resource resolver, how sling works.
Sling Resource resolver


The following diagram explains all the hidden, but powerful request parameters you can use when dealing with the SlingPostServlet, the default handler for all POST requests that gives you endless options for creating, modifying, deleting, copying and moving nodes in the repository.

We will now see how sling resolve a URL by using the above resolution diagram.

1. Actual URL get divided into the following chunks. e.g. we have a URL " www.rashidjorvee.blogspot.com/blog/post/aboutrashid.print.html/printable?height=400,width=200" and now we will see how sling will resolve my URL.
  • Request Method: This information comes in request header.
  • Content Path: [/blog/post/aboutrashid] 
  • Seletor: [print]
  • Extension: [html]
  • Suffix:
  • Query parameter : [height=400,width=200]
2. Sling will go to the requested content path.

3. Then it will check whether that content path or component has property sling:resourceSuperType or sling:resourceType. If request found any of these property in that node then sling request move to that path which is present in the sling:resourceType or sling:resourceSuperType.


sling:resourceType is used to render to script files.

sling:resourceSuperType is used to overload or inherit a existing component.



4. Then render to the path given in resourceType and resourceSuperType property to load the script or inherit the functionality. To resolve this first sling will find the path under apps directory, in case that content path is not available in apps then request will move under libs directory. 


5.  In this step sling will look for script name and try to match with the exact request URL with requested selector and extension. There is a set of rules which sling follow to match the selector and extension. Following are the rules:

  • Folders (i.e. nodes of type nt:folder) take precedence over jsp file names when resolving using selectors, at least for the first selector.
  • Only one selector in a file name has any effect - any files with names containing two selectors don't ever get selected, but names of folders can be used to match the selectors in the request.
  • Scripts with HTTP method names (e.g.,GET.jsp) is selected as a last resort, (after the default script: jobs.jsp, in this case).
  • Scripts with names that include HTTP methods in addition to another selector or extension in a .jsp file name are never selected.



How to change default start page in AEM?

Today we are going to learn about Day CQ Root Mapping configuration setting in AEM. 
This configuration is for default landing page of your AEM instance when you browse your AEM instance with URI http://localhost:4502 only and don't specify the any page name after that.

Steps to be follow to change the default landing page:
Step 1: Open http://localhost:4503
Step 2: Login with admin credentials.
Step 3: Go to http://localhost:4502/system/console/configMgr
Step 4: Go to find option [shortcut key Press Ctrl+f] then find for CQ Root Mapping
Step 5: Click on Day CQ Root Mapping configuration which will open a pop as showing in the below email.
Step 6: Change the target value with to new target page.

  • Default the value of this configuration will be : /projects.html 
  • Possible value: You can put any page name here which you want to open. e.g. if you want to open website site admin then put the value /siteadmin

Step 7: Save the settings and logout. Go for Login gain to verify the changes.


Below is the screen shot:

CQ Root Mapping


How to download AEM archetype project from Adobe repository?

Prerequisite 

Add this profile in maven settings.xml file to fetch the project structure content from Adobe repo.
<profile>
          <id>adobe-public</id>
          <activation>
                   <activeByDefault>true</activeByDefault>
          </activation>
          <repositories>
               <repository>
                  <id>adobe</id>
                  <name>Nexus Proxy Repository</name>
                  <url>http://repo.adobe.com/nexus/content/groups/public/</url>
                  <layout>default</layout>
             </repository>
          </repositories>
          <pluginRepositories>
                   <pluginRepository>
                          <id>adobe</id>
                          <name>Nexus Proxy Repository</name>
                          <url>http://repo.adobe.com/nexus/content/groups/public/</url>
                          <layout>default</layout>
                   </pluginRepository>
          </pluginRepositories>
</profile>
Step 1: Then go to your folder where you want to create your project (e.g. D:\Rashid\AEM\) and open command prompt cmd and run the following command.
mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=com.adobe.granite.archetypes -DarchetypeArtifactId=aem-project-archetype -DarchetypeVersion=11 -DarchetypeCatalog=https://repo.adobe.com/nexus/content/groups/public/ -DgroupId=myproject -DartifactId=myproject -Dversion=1.0-SNAPSHOT -Dpackage=com.aem.community -DappsFolderName=myproject -DartifactName="myproject" -DappsFolderName=myproject -DartifactName=myproject -DpackageGroup=myproject -DcontentFolderName="ui.content" -DsiteName="MyProject Site" -DcomponentGroupName="MyProject Components" -DcssId=myproject
Step 2: The above command will execute for a moment and then it will ask for parameter confirmation.


Confirm properties configuration:
groupId: myproject
artifactId: myproject
version: 1.0-SNAPSHOT
package: com.aem.community
appsFolderName: myproject
artifactName: myproject
componentGroupName: MyProject Components
contentFolderName: ui.content
cssId: myproject
packageGroup: myproject
siteName: MyProject Site
Y: :
Step 3: Confirm your parameters, type "Y" and hit enter. After that, your project is setup and available in your directory.

ClientLibs debugger [?debugClientLibs=true] in AEM

ClientLibs debugger [?debugClientLibs=true] in AEM


Today in this tutorial we are going to discuss how and what we can achieve this using debugClientLibs parameter in AEM.

What is debugClientLibs? What is the use of debugClientLibs?

AEM provides tools for debugging and debugClinetLibs is one of them. Using this we can see all the embedded client library files. By default, client libraries embed all your code in a single file when it is delivered to the browser. So when you want to see all the embedded files in separate at runtime append "?debugClinetLibs=true" in URL (this is something like passing a parameter with url). Then you will see the response return all of the individual script files that ClientLibs embed inside each clientLibs file.


e.g. URL: https://localhost:4502/content/jorvee/home.html?debugClientLibs=true

Benefits of using debugClientLibs:
  • You can detach your embedded script at runtime.
  • Helps you to identify and fix the JS/CSS issues.



Reference: 


  

How to find all client library files(JS and CSS) in AEM?

Today in this tutorial we are going to learn how to find all client library files (JS and CSS) in AEM? 

In AEM we have a console to find all the client libraries and their dependencies along with JS and CSS files. Using the below URL we can access that console.

http://localhost:4503/libs/granite/ui/content/dumplibs.html

We can also filter our library files on the basis of categories and templates.

  • If you want to see all the files belongs to particular categories then put the category name in the categories field and click on the search button.
  • If you want to see only JS or CSS files from particular categories then put the type JS for javascript files and CSS for cascading style sheet files and click on the search button.
  • Also, you can find the files based on the theme. Using this you will be able to identify what all library files are being used in this theme. To find the related files with theme simple put the name of the theme in the Theme section and click on the search button

Below is the screenshot where we have applied filter on the basis of categories and type:


/libs/granite/ui/content/dumplibs.html
List of client libraries in AEM 
There are two parts or sections of this report as you can see in the above screenshot.

  1. The result section will give you results based on the applied filter.
  2. and the second section has Libraries by Path which have information of the file. Here as you can see the first column has the name of the file along with its path, the second column will let you know the type of that file either JS, CSS or image, and the last column contains the information regarding its group (from where this file belongs) which we called categories in AEM.


For more about clientLibs please refer: http://blogs.adobe.com/experiencedelivers/experience-management/clientlibs-explained-example/

Check at how many places a component is being used in your site in AEM?

Today I am going to tell you guys a very powerful out of box component or tool of AEM. 
Component report a useful report to know about a particular component, using this you can check in your author instance that at how many places you are using a particular component. This check is only possible in author instance not in publish.
Questions can be like this as well: How to customize component report? What is component report? What is the purpose of component report? How to use component report? Find the component being used on page? What is rule and reports? 

To check a component:

1. Goto URL http://localhost:4502/etc/reports/compreport.html from your browser. This will open a new window which have no reports and nothing as showing is the below screen.




2. Select the edit option from the top left of the page below the on/off button or component report text. When you clicked on edit button a new popup will appear which will create a new report. As shown in the below screen shot.




a. Title: Give a title to your report.
b. Description: Give detail description to your report. 
c. Root path: Select the path under which you wants to check the component being used. this will let you select a path from dropdown.
d. Report processing: In report processing we can see there are two options one is automatic refresh and another is manual. Select as per your need.
e. Snapshots: Report snapshot have three options.

  1. No Data snapshot
  2. Daily data snapshot
  3. Hourly data snapshot 
3. Click on the OK button from the bottom of the dialog to save and run the report.


4. Then you will see a lots of data will appear on the component report screen. as showing in the below image. 


5. From the list sort component type with group name. To do so put your cursor at the end or the column Component Type, then a dropdown will appear with the sorting options. Select the option "Group by this column"



This report contains the 
  1. Page: It will show the name of page of number of pages.
  2. Component Type: Path of the component or name of teh component.
  3. Component Path: Path of the component or number of places this component is being used.
  4. Author: Name of the Author who did the authoring for this component at that page.
  5. Last Modified: Date and time of last modified.
In the above report you can see a component formname (second row) is being used at two places under the given directory.

How to set ReadLimits and terminate a slow query in AEM/CQ5

When we execute a query using query builder in AEM/CQ5 and for that query system is not able to return any output and you found that it is still executing. 
Then you went to error log file and find the error:"consider creating an index or changing the query [time stamp] *WARN* [qtp1617436028-18416] org.apache.jackrabbit.oak.spi.query.Cursors$TraversingCursor Traversed 987000 nodes with filter Filter(query=#)", it means your query is still running and will keep running till the time it completed maximum read limit. 
If you want to stop this query to run which is unnecessary consuming performance of your system then follow the following steps.


1. Go to http://localhost:4503/system/console/jmx 

2. Find the type "QueryEngineSettings" and name settings.
3. Open settings. 

4. Then change the ReadLimit to either 1 or 2.

5. save and refresh the page. Now go and check the error log file you will not find that query anymore in the execution.


For more detail you can read the following links: