Java Code Examples for org.apache.sling.api.resource.ResourceResolverFactory#getServiceResourceResolver()

The following examples show how to use org.apache.sling.api.resource.ResourceResolverFactory#getServiceResourceResolver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlingHelper.java    From APM with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new session for specified user (impersonating).
 */
public static ResourceResolver getResourceResolverForUser(ResourceResolverFactory factory, String userId)
    throws LoginException {
  ResourceResolver resolver;
  if (userId != null) {
    Map<String, Object> authenticationInfo = Maps.newHashMap();
    authenticationInfo.put(ResourceResolverFactory.USER_IMPERSONATION, userId);
    resolver = factory.getAdministrativeResourceResolver(authenticationInfo);
  } else {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put(ResourceResolverFactory.SUBSERVICE, SUBSERVICE_NAME);
    resolver = factory.getServiceResourceResolver(parameters);
  }

  return resolver;
}
 
Example 2
Source File: SampleServlet.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new session for specified user (impersonating).
 */
public static ResourceResolver getResourceResolverForUser(ResourceResolverFactory factory, String userId)
    throws LoginException {
    ResourceResolver resolver;
    if (userId != null) {
        Map<String, Object> authenticationInfo = new HashMap<>();
        authenticationInfo.put(ResourceResolverFactory.USER_IMPERSONATION, userId);
        resolver = factory.getServiceResourceResolver(authenticationInfo);
    } else {
        resolver = factory.getServiceResourceResolver(null);
    }
    return resolver;
}
 
Example 3
Source File: SampleServlet.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
public static ResourceResolver getResourceResolverForUserInit(ResourceResolverFactory factory)
    throws LoginException {
    ResourceResolver resolver = factory.getServiceResourceResolver(null);
    return resolver;
}