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();
}
}
}
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;
}
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;
}
Aggregations