General refactoring of taglibs.
This commit is contained in:
parent
1b660d4d5b
commit
7a4a46cc7b
|
@ -37,6 +37,7 @@ import java.util.StringTokenizer;
|
|||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.PageContext;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
import javax.servlet.jsp.tagext.TagSupport;
|
||||
|
||||
|
@ -106,8 +107,6 @@ public class AclTag extends TagSupport {
|
|||
final String evaledPermissionsString = ExpressionEvaluationUtils
|
||||
.evaluateString("hasPermission", hasPermission, pageContext);
|
||||
|
||||
if ((null != evaledPermissionsString)
|
||||
&& !"".equals(evaledPermissionsString)) {
|
||||
Integer[] requiredIntegers = null;
|
||||
|
||||
try {
|
||||
|
@ -116,11 +115,6 @@ public class AclTag extends TagSupport {
|
|||
throw new JspException(nfe);
|
||||
}
|
||||
|
||||
if (requiredIntegers.length == 0) {
|
||||
throw new JspException(
|
||||
"A comma separate list of integers representing authorised permissions was NOT provided via the 'hasPermission' attribute");
|
||||
}
|
||||
|
||||
Object resolvedDomainObject = null;
|
||||
|
||||
if (domainObject instanceof String) {
|
||||
|
@ -142,8 +136,7 @@ public class AclTag extends TagSupport {
|
|||
|
||||
if ((ContextHolder.getContext() == null)
|
||||
|| !(ContextHolder.getContext() instanceof SecureContext)
|
||||
|| (((SecureContext) ContextHolder.getContext())
|
||||
.getAuthentication() == null)) {
|
||||
|| (((SecureContext) ContextHolder.getContext()).getAuthentication() == null)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"ContextHolder did not return a non-null Authentication object, so skipping tag body");
|
||||
|
@ -155,14 +148,7 @@ public class AclTag extends TagSupport {
|
|||
Authentication auth = ((SecureContext) ContextHolder.getContext())
|
||||
.getAuthentication();
|
||||
|
||||
ApplicationContext context = getContext(pageContext
|
||||
.getServletContext());
|
||||
|
||||
if (context == null) {
|
||||
throw new JspException(
|
||||
"applicationContext unavailable from servlet context");
|
||||
}
|
||||
|
||||
ApplicationContext context = getContext(pageContext);
|
||||
Map beans = context.getBeansOfType(AclManager.class, false, false);
|
||||
|
||||
if (beans.size() == 0) {
|
||||
|
@ -200,9 +186,8 @@ public class AclTag extends TagSupport {
|
|||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Including tag body as found permission: "
|
||||
+ requiredIntegers[y]
|
||||
+ " due to AclEntry: '" + processableAcl
|
||||
+ "'");
|
||||
+ requiredIntegers[y] + " due to AclEntry: '"
|
||||
+ processableAcl + "'");
|
||||
}
|
||||
|
||||
return Tag.EVAL_BODY_INCLUDE;
|
||||
|
@ -216,20 +201,19 @@ public class AclTag extends TagSupport {
|
|||
}
|
||||
|
||||
return Tag.SKIP_BODY;
|
||||
} else {
|
||||
throw new JspException("Unsupported use of auth:acl tag");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows test cases to override where application context obtained from.
|
||||
*
|
||||
* @param servletContext as required by Spring's
|
||||
* <code>WebApplicationContextUtils</code>
|
||||
* @param pageContext so the <code>ServletContext</code> can be accessed as
|
||||
* required by Spring's <code>WebApplicationContextUtils</code>
|
||||
*
|
||||
* @return the Spring application context
|
||||
* @return the Spring application context (never <code>null</code>)
|
||||
*/
|
||||
protected ApplicationContext getContext(ServletContext servletContext) {
|
||||
protected ApplicationContext getContext(PageContext pageContext) {
|
||||
ServletContext servletContext = pageContext.getServletContext();
|
||||
|
||||
return WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,10 @@ public class AuthenticationTag extends TagSupport {
|
|||
return Tag.SKIP_BODY;
|
||||
}
|
||||
|
||||
if (!OPERATION_PRINCIPAL.equalsIgnoreCase(operation)) {
|
||||
throw new JspException("Unsupported use of auth:authentication tag");
|
||||
}
|
||||
|
||||
if ((ContextHolder.getContext() == null)
|
||||
|| !(ContextHolder.getContext() instanceof SecureContext)
|
||||
|| (((SecureContext) ContextHolder.getContext()).getAuthentication() == null)) {
|
||||
|
@ -75,7 +79,6 @@ public class AuthenticationTag extends TagSupport {
|
|||
Authentication auth = ((SecureContext) ContextHolder.getContext())
|
||||
.getAuthentication();
|
||||
|
||||
if (OPERATION_PRINCIPAL.equalsIgnoreCase(operation)) {
|
||||
if (auth.getPrincipal() == null) {
|
||||
return Tag.SKIP_BODY;
|
||||
} else if (auth.getPrincipal() instanceof UserDetails) {
|
||||
|
@ -87,9 +90,6 @@ public class AuthenticationTag extends TagSupport {
|
|||
|
||||
return Tag.SKIP_BODY;
|
||||
}
|
||||
} else {
|
||||
throw new JspException("Unsupported use of auth:athentication tag");
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeMessage(String msg) throws JspException {
|
||||
|
|
Loading…
Reference in New Issue