}
final ApplicationContext applicationContext =
WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
final AclService aclService = getBeanOfType(applicationContext, AclService.class);
if (authentication == null) {
// If authentication is null, authorization cannot be granted.
if (logger.isTraceEnabled()) {
logger.trace("[THYMELEAF][{}] Authentication object is null. Access is DENIED. ",
new Object[] {TemplateEngine.threadIndex()});
}
return false;
}
/*
* Initialize required objects
*/
SidRetrievalStrategy sidRetrievalStrategy = getBeanOfType(applicationContext, SidRetrievalStrategy.class);
if (sidRetrievalStrategy == null) {
sidRetrievalStrategy = new SidRetrievalStrategyImpl();
}
ObjectIdentityRetrievalStrategy objectIdentityRetrievalStrategy = getBeanOfType(applicationContext, ObjectIdentityRetrievalStrategy.class);
if (objectIdentityRetrievalStrategy == null) {
objectIdentityRetrievalStrategy = new ObjectIdentityRetrievalStrategyImpl();
}
/*
* Compute permissions
*/
if ((null == permissions) || permissions.isEmpty()) {
if (logger.isTraceEnabled()) {
logger.trace("[THYMELEAF][{}] Permissions are null or empty. Access is DENIED. ",
new Object[] {TemplateEngine.threadIndex()});
}
return false;
}
if (domainObject == null) {
if (logger.isTraceEnabled()) {
logger.trace("[THYMELEAF][{}] Domain object for resolved to null. Access by " +
"Access Control List is GRANTED.", new Object[] {TemplateEngine.threadIndex()});
}
// Access to null object is considered always true
return true;
}
final List<Sid> sids =
sidRetrievalStrategy.getSids(SecurityContextHolder.getContext().getAuthentication());
final ObjectIdentity oid =
objectIdentityRetrievalStrategy.getObjectIdentity(domainObject);
try {
final Acl acl = aclService.readAclById(oid, sids);
if (acl.isGranted(permissions, sids, false)) {
if (logger.isTraceEnabled()) {
logger.trace("[THYMELEAF][{}] Checked authorization using Access Control List for user \"{}\". " +