Search in sources :

Example 86 with LoginException

use of org.apache.sling.api.resource.LoginException in project acs-aem-commons by Adobe-Consulting-Services.

the class ReviewTaskAssetMoverHandler method handleEvent.

@Override
public void handleEvent(Event event) {
    ResourceResolver resourceResolver = null;
    try {
        resourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO);
        final String path = (String) event.getProperty("TaskId");
        final Resource taskResource = resourceResolver.getResource(path);
        if (taskResource != null) {
            final ValueMap taskProperties = taskResource.getValueMap();
            // Perform a fast check to see if this project has the required properties to perform the asset moving
            if (StringUtils.startsWith(taskProperties.get(PN_ON_APPROVE, String.class), PATH_CONTENT_DAM) || StringUtils.startsWith(taskProperties.get(PN_ON_REJECT, String.class), PATH_CONTENT_DAM)) {
                log.debug("Handling event (creating a Job) for Assets Review Task @ [ {} ]", path);
                ScheduleOptions options = scheduler.NOW();
                String jobName = this.getClass().getSimpleName().toString().replace(".", "/") + "/" + path;
                options.name(jobName);
                options.canRunConcurrently(false);
                scheduler.schedule(new ImmediateJob(path), options);
            }
        }
    } catch (LoginException e) {
        log.error("Could not get resource resolver", e);
    } finally {
        // Always close resource resolvers you open
        if (resourceResolver != null) {
            resourceResolver.close();
        }
    }
}
Also used : ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) ValueMap(org.apache.sling.api.resource.ValueMap) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) LoginException(org.apache.sling.api.resource.LoginException)

Example 87 with LoginException

use of org.apache.sling.api.resource.LoginException in project acs-aem-commons by Adobe-Consulting-Services.

the class EmailServiceImpl method getMailTemplate.

private MailTemplate getMailTemplate(String templatePath) throws IllegalArgumentException {
    MailTemplate mailTemplate = null;
    ResourceResolver resourceResolver = null;
    try {
        Map<String, Object> authInfo = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_NAME);
        resourceResolver = resourceResolverFactory.getServiceResourceResolver(authInfo);
        mailTemplate = MailTemplate.create(templatePath, resourceResolver.adaptTo(Session.class));
        if (mailTemplate == null) {
            throw new IllegalArgumentException("Mail template path [ " + templatePath + " ] could not resolve to a valid template");
        }
    } catch (LoginException e) {
        log.error("Unable to obtain an administrative resource resolver to get the Mail Template at [ " + templatePath + " ]", e);
    } finally {
        if (resourceResolver != null) {
            resourceResolver.close();
        }
    }
    return mailTemplate;
}
Also used : MailTemplate(com.day.cq.commons.mail.MailTemplate) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) LoginException(org.apache.sling.api.resource.LoginException)

Example 88 with LoginException

use of org.apache.sling.api.resource.LoginException in project APM by Cognifide.

the class CheckPermissions method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    try {
        final Authorizable authorizable = context.getAuthorizableManager().getAuthorizable(authorizableId);
        final Set<Principal> authorizablesToCheck = getAuthorizablesToCheck(authorizable, context);
        final CqActions actions = new CqActions(context.getSession());
        final List<String> privilegesToCheck = preparePrivilegesToCheck();
        if (StringUtils.isBlank(glob)) {
            if (checkPermissionsForPath(authorizablesToCheck, actions, privilegesToCheck, path)) {
                logFailure(execute, actionResult, authorizable, path);
            } else {
                actionResult.logMessage("All required privileges are set for " + authorizable.getID() + " on " + path);
            }
        } else {
            checkPermissionsForGlob(context.getSession(), execute, actionResult, authorizable, authorizablesToCheck, actions, privilegesToCheck);
        }
    } catch (final PathNotFoundException e) {
        actionResult.logError("Path " + path + " not found");
    } catch (RepositoryException | ActionExecutionException | LoginException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : ActionResult(com.cognifide.apm.api.actions.ActionResult) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) CqActions(com.day.cq.security.util.CqActions) LoginException(org.apache.sling.api.resource.LoginException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException) Principal(java.security.Principal)

Aggregations

LoginException (org.apache.sling.api.resource.LoginException)88 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)70 Resource (org.apache.sling.api.resource.Resource)47 PersistenceException (org.apache.sling.api.resource.PersistenceException)31 HashMap (java.util.HashMap)17 RepositoryException (javax.jcr.RepositoryException)13 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)11 ArrayList (java.util.ArrayList)7 ValueMap (org.apache.sling.api.resource.ValueMap)6 HashSet (java.util.HashSet)5 Map (java.util.Map)5 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)5 IOException (java.io.IOException)4 Calendar (java.util.Calendar)4 JsonException (javax.json.JsonException)4 ServletException (javax.servlet.ServletException)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4 LinkedHashMap (java.util.LinkedHashMap)3 InstanceDescription (org.apache.sling.discovery.InstanceDescription)3 Bundle (org.osgi.framework.Bundle)3