diff --git a/taglibs/src/main/java/org/springframework/security/taglibs/TagLibConfig.java b/taglibs/src/main/java/org/springframework/security/taglibs/TagLibConfig.java
index dfbe370fde..64083a679a 100644
--- a/taglibs/src/main/java/org/springframework/security/taglibs/TagLibConfig.java
+++ b/taglibs/src/main/java/org/springframework/security/taglibs/TagLibConfig.java
@@ -33,19 +33,18 @@ public final class TagLibConfig {
static Log logger = LogFactory.getLog("spring-security-taglibs");
static final boolean DISABLE_UI_SECURITY;
+
static final String SECURED_UI_PREFIX;
+
static final String SECURED_UI_SUFFIX;
static {
String db = System.getProperty("spring.security.disableUISecurity");
String prefix = System.getProperty("spring.security.securedUIPrefix");
String suffix = System.getProperty("spring.security.securedUISuffix");
-
SECURED_UI_PREFIX = (prefix != null) ? prefix : "";
SECURED_UI_SUFFIX = (suffix != null) ? suffix : "";
-
DISABLE_UI_SECURITY = "true".equals(db);
-
if (DISABLE_UI_SECURITY) {
logger.warn("***** UI security is disabled. All unauthorized content will be displayed *****");
}
@@ -60,11 +59,7 @@ public final class TagLibConfig {
* @param authorized whether the user is authorized to see the content or not
*/
public static int evalOrSkip(boolean authorized) {
- if (authorized || DISABLE_UI_SECURITY) {
- return Tag.EVAL_BODY_INCLUDE;
- }
-
- return Tag.SKIP_BODY;
+ return (authorized || DISABLE_UI_SECURITY) ? Tag.EVAL_BODY_INCLUDE : Tag.SKIP_BODY;
}
public static boolean isUiSecurityDisabled() {
diff --git a/taglibs/src/main/java/org/springframework/security/taglibs/authz/AbstractAuthorizeTag.java b/taglibs/src/main/java/org/springframework/security/taglibs/authz/AbstractAuthorizeTag.java
index 803f569d89..95fb17928f 100644
--- a/taglibs/src/main/java/org/springframework/security/taglibs/authz/AbstractAuthorizeTag.java
+++ b/taglibs/src/main/java/org/springframework/security/taglibs/authz/AbstractAuthorizeTag.java
@@ -93,22 +93,13 @@ public abstract class AbstractAuthorizeTag {
* @throws IOException
*/
public boolean authorize() throws IOException {
- boolean isAuthorized;
-
if (StringUtils.hasText(getAccess())) {
- isAuthorized = authorizeUsingAccessExpression();
-
+ return authorizeUsingAccessExpression();
}
- else if (StringUtils.hasText(getUrl())) {
- isAuthorized = authorizeUsingUrlCheck();
-
+ if (StringUtils.hasText(getUrl())) {
+ return authorizeUsingUrlCheck();
}
- else {
- isAuthorized = false;
-
- }
-
- return isAuthorized;
+ return false;
}
/**
@@ -122,18 +113,14 @@ public abstract class AbstractAuthorizeTag {
if (SecurityContextHolder.getContext().getAuthentication() == null) {
return false;
}
-
SecurityExpressionHandler handler = getExpressionHandler();
-
Expression accessExpression;
try {
accessExpression = handler.getExpressionParser().parseExpression(getAccess());
-
}
catch (ParseException ex) {
throw new IOException(ex);
}
-
return ExpressionUtils.evaluateAsBoolean(accessExpression, createExpressionEvaluationContext(handler));
}
@@ -144,7 +131,6 @@ public abstract class AbstractAuthorizeTag {
FilterInvocation f = new FilterInvocation(getRequest(), getResponse(), (request, response) -> {
throw new UnsupportedOperationException();
});
-
return handler.createEvaluationContext(SecurityContextHolder.getContext().getAuthentication(), f);
}
@@ -184,21 +170,17 @@ public abstract class AbstractAuthorizeTag {
this.method = (method != null) ? method.toUpperCase() : null;
}
- /*------------- Private helper methods -----------------*/
-
@SuppressWarnings({ "unchecked", "rawtypes" })
private SecurityExpressionHandler getExpressionHandler() throws IOException {
ApplicationContext appContext = SecurityWebApplicationContextUtils
.findRequiredWebApplicationContext(getServletContext());
Map handlers = appContext.getBeansOfType(SecurityExpressionHandler.class);
-
- for (SecurityExpressionHandler h : handlers.values()) {
- if (FilterInvocation.class
- .equals(GenericTypeResolver.resolveTypeArgument(h.getClass(), SecurityExpressionHandler.class))) {
- return h;
+ for (SecurityExpressionHandler handler : handlers.values()) {
+ if (FilterInvocation.class.equals(
+ GenericTypeResolver.resolveTypeArgument(handler.getClass(), SecurityExpressionHandler.class))) {
+ return handler;
}
}
-
throw new IOException("No visible WebSecurityExpressionHandler instance could be found in the application "
+ "context. There must be at least one in order to support expressions in JSP 'authorize' tags.");
}
@@ -209,17 +191,14 @@ public abstract class AbstractAuthorizeTag {
if (privEvaluatorFromRequest != null) {
return privEvaluatorFromRequest;
}
-
ApplicationContext ctx = SecurityWebApplicationContextUtils
.findRequiredWebApplicationContext(getServletContext());
Map wipes = ctx.getBeansOfType(WebInvocationPrivilegeEvaluator.class);
-
if (wipes.size() == 0) {
throw new IOException(
"No visible WebInvocationPrivilegeEvaluator instance could be found in the application "
+ "context. There must be at least one in order to support the use of URL access checks in 'authorize' tags.");
}
-
return (WebInvocationPrivilegeEvaluator) wipes.values().toArray()[0];
}
diff --git a/taglibs/src/main/java/org/springframework/security/taglibs/authz/AccessControlListTag.java b/taglibs/src/main/java/org/springframework/security/taglibs/authz/AccessControlListTag.java
index 0b8ce61b4e..16904672a6 100644
--- a/taglibs/src/main/java/org/springframework/security/taglibs/authz/AccessControlListTag.java
+++ b/taglibs/src/main/java/org/springframework/security/taglibs/authz/AccessControlListTag.java
@@ -72,35 +72,23 @@ public class AccessControlListTag extends TagSupport {
if ((null == this.hasPermission) || "".equals(this.hasPermission)) {
return skipBody();
}
-
initializeIfRequired();
-
if (this.domainObject == null) {
- if (logger.isDebugEnabled()) {
- logger.debug("domainObject resolved to null, so including tag body");
- }
-
+ logger.debug("domainObject resolved to null, so including tag body");
// Of course they have access to a null object!
return evalBody();
}
-
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
- if (logger.isDebugEnabled()) {
- logger.debug(
- "SecurityContextHolder did not return a non-null Authentication object, so skipping tag body");
- }
-
+ logger.debug("SecurityContextHolder did not return a non-null Authentication object, so skipping tag body");
return skipBody();
}
-
List