Always use 'this.' when accessing fields

Apply an Eclipse cleanup rules to ensure that fields are always accessed
using `this.`. This aligns with the style used by Spring Framework and
helps users quickly see the difference between a local and member
variable.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-26 11:51:05 -07:00
committed by Rob Winch
parent 6894ff5d12
commit 8866fa6fb0
793 changed files with 8689 additions and 8459 deletions

View File

@@ -60,10 +60,10 @@ public class AbstractAuthorizeTagTests {
@Before
public void setup() {
tag = new AuthzTag();
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
servletContext = new MockServletContext();
this.tag = new AuthzTag();
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
this.servletContext = new MockServletContext();
}
@After
@@ -75,10 +75,10 @@ public class AbstractAuthorizeTagTests {
public void privilegeEvaluatorFromRequest() throws IOException {
String uri = "/something";
WebInvocationPrivilegeEvaluator expected = mock(WebInvocationPrivilegeEvaluator.class);
tag.setUrl(uri);
request.setAttribute(WebAttributes.WEB_INVOCATION_PRIVILEGE_EVALUATOR_ATTRIBUTE, expected);
this.tag.setUrl(uri);
this.request.setAttribute(WebAttributes.WEB_INVOCATION_PRIVILEGE_EVALUATOR_ATTRIBUTE, expected);
tag.authorizeUsingUrlCheck();
this.tag.authorizeUsingUrlCheck();
verify(expected).isAllowed(eq(""), eq(uri), eq("GET"), any());
}
@@ -87,13 +87,13 @@ public class AbstractAuthorizeTagTests {
public void privilegeEvaluatorFromChildContext() throws IOException {
String uri = "/something";
WebInvocationPrivilegeEvaluator expected = mock(WebInvocationPrivilegeEvaluator.class);
tag.setUrl(uri);
this.tag.setUrl(uri);
WebApplicationContext wac = mock(WebApplicationContext.class);
when(wac.getBeansOfType(WebInvocationPrivilegeEvaluator.class))
.thenReturn(Collections.singletonMap("wipe", expected));
servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
this.servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
tag.authorizeUsingUrlCheck();
this.tag.authorizeUsingUrlCheck();
verify(expected).isAllowed(eq(""), eq(uri), eq("GET"), any());
}
@@ -103,30 +103,30 @@ public class AbstractAuthorizeTagTests {
public void expressionFromChildContext() throws IOException {
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "pass", "USER"));
DefaultWebSecurityExpressionHandler expected = new DefaultWebSecurityExpressionHandler();
tag.setAccess("permitAll");
this.tag.setAccess("permitAll");
WebApplicationContext wac = mock(WebApplicationContext.class);
when(wac.getBeansOfType(SecurityExpressionHandler.class))
.thenReturn(Collections.<String, SecurityExpressionHandler>singletonMap("wipe", expected));
servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
this.servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
assertThat(tag.authorize()).isTrue();
assertThat(this.tag.authorize()).isTrue();
}
private class AuthzTag extends AbstractAuthorizeTag {
@Override
protected ServletRequest getRequest() {
return request;
return AbstractAuthorizeTagTests.this.request;
}
@Override
protected ServletResponse getResponse() {
return response;
return AbstractAuthorizeTagTests.this.response;
}
@Override
protected ServletContext getServletContext() {
return servletContext;
return AbstractAuthorizeTagTests.this.servletContext;
}
}

View File

@@ -60,20 +60,20 @@ public class AccessControlListTagTests {
@Before
@SuppressWarnings("rawtypes")
public void setup() {
SecurityContextHolder.getContext().setAuthentication(bob);
tag = new AccessControlListTag();
SecurityContextHolder.getContext().setAuthentication(this.bob);
this.tag = new AccessControlListTag();
WebApplicationContext ctx = mock(WebApplicationContext.class);
pe = mock(PermissionEvaluator.class);
this.pe = mock(PermissionEvaluator.class);
Map beanMap = new HashMap();
beanMap.put("pe", pe);
beanMap.put("pe", this.pe);
when(ctx.getBeansOfType(PermissionEvaluator.class)).thenReturn(beanMap);
MockServletContext servletCtx = new MockServletContext();
servletCtx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
pageContext = new MockPageContext(servletCtx, new MockHttpServletRequest(), new MockHttpServletResponse());
tag.setPageContext(pageContext);
this.pageContext = new MockPageContext(servletCtx, new MockHttpServletRequest(), new MockHttpServletResponse());
this.tag.setPageContext(this.pageContext);
}
@After
@@ -84,109 +84,109 @@ public class AccessControlListTagTests {
@Test
public void bodyIsEvaluatedIfAclGrantsAccess() throws Exception {
Object domainObject = new Object();
when(pe.hasPermission(bob, domainObject, "READ")).thenReturn(true);
when(this.pe.hasPermission(this.bob, domainObject, "READ")).thenReturn(true);
tag.setDomainObject(domainObject);
tag.setHasPermission("READ");
tag.setVar("allowed");
assertThat(tag.getDomainObject()).isSameAs(domainObject);
assertThat(tag.getHasPermission()).isEqualTo("READ");
this.tag.setDomainObject(domainObject);
this.tag.setHasPermission("READ");
this.tag.setVar("allowed");
assertThat(this.tag.getDomainObject()).isSameAs(domainObject);
assertThat(this.tag.getHasPermission()).isEqualTo("READ");
assertThat(tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat((Boolean) pageContext.getAttribute("allowed")).isTrue();
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isTrue();
}
@Test
public void childContext() throws Exception {
ServletContext servletContext = pageContext.getServletContext();
ServletContext servletContext = this.pageContext.getServletContext();
WebApplicationContext wac = (WebApplicationContext) servletContext
.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
servletContext.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
Object domainObject = new Object();
when(pe.hasPermission(bob, domainObject, "READ")).thenReturn(true);
when(this.pe.hasPermission(this.bob, domainObject, "READ")).thenReturn(true);
tag.setDomainObject(domainObject);
tag.setHasPermission("READ");
tag.setVar("allowed");
assertThat(tag.getDomainObject()).isSameAs(domainObject);
assertThat(tag.getHasPermission()).isEqualTo("READ");
this.tag.setDomainObject(domainObject);
this.tag.setHasPermission("READ");
this.tag.setVar("allowed");
assertThat(this.tag.getDomainObject()).isSameAs(domainObject);
assertThat(this.tag.getHasPermission()).isEqualTo("READ");
assertThat(tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat((Boolean) pageContext.getAttribute("allowed")).isTrue();
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isTrue();
}
// SEC-2022
@Test
public void multiHasPermissionsAreSplit() throws Exception {
Object domainObject = new Object();
when(pe.hasPermission(bob, domainObject, "READ")).thenReturn(true);
when(pe.hasPermission(bob, domainObject, "WRITE")).thenReturn(true);
when(this.pe.hasPermission(this.bob, domainObject, "READ")).thenReturn(true);
when(this.pe.hasPermission(this.bob, domainObject, "WRITE")).thenReturn(true);
tag.setDomainObject(domainObject);
tag.setHasPermission("READ,WRITE");
tag.setVar("allowed");
assertThat(tag.getDomainObject()).isSameAs(domainObject);
assertThat(tag.getHasPermission()).isEqualTo("READ,WRITE");
this.tag.setDomainObject(domainObject);
this.tag.setHasPermission("READ,WRITE");
this.tag.setVar("allowed");
assertThat(this.tag.getDomainObject()).isSameAs(domainObject);
assertThat(this.tag.getHasPermission()).isEqualTo("READ,WRITE");
assertThat(tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat((Boolean) pageContext.getAttribute("allowed")).isTrue();
verify(pe).hasPermission(bob, domainObject, "READ");
verify(pe).hasPermission(bob, domainObject, "WRITE");
verifyNoMoreInteractions(pe);
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isTrue();
verify(this.pe).hasPermission(this.bob, domainObject, "READ");
verify(this.pe).hasPermission(this.bob, domainObject, "WRITE");
verifyNoMoreInteractions(this.pe);
}
// SEC-2023
@Test
public void hasPermissionsBitMaskSupported() throws Exception {
Object domainObject = new Object();
when(pe.hasPermission(bob, domainObject, 1)).thenReturn(true);
when(pe.hasPermission(bob, domainObject, 2)).thenReturn(true);
when(this.pe.hasPermission(this.bob, domainObject, 1)).thenReturn(true);
when(this.pe.hasPermission(this.bob, domainObject, 2)).thenReturn(true);
tag.setDomainObject(domainObject);
tag.setHasPermission("1,2");
tag.setVar("allowed");
assertThat(tag.getDomainObject()).isSameAs(domainObject);
assertThat(tag.getHasPermission()).isEqualTo("1,2");
this.tag.setDomainObject(domainObject);
this.tag.setHasPermission("1,2");
this.tag.setVar("allowed");
assertThat(this.tag.getDomainObject()).isSameAs(domainObject);
assertThat(this.tag.getHasPermission()).isEqualTo("1,2");
assertThat(tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat((Boolean) pageContext.getAttribute("allowed")).isTrue();
verify(pe).hasPermission(bob, domainObject, 1);
verify(pe).hasPermission(bob, domainObject, 2);
verifyNoMoreInteractions(pe);
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isTrue();
verify(this.pe).hasPermission(this.bob, domainObject, 1);
verify(this.pe).hasPermission(this.bob, domainObject, 2);
verifyNoMoreInteractions(this.pe);
}
@Test
public void hasPermissionsMixedBitMaskSupported() throws Exception {
Object domainObject = new Object();
when(pe.hasPermission(bob, domainObject, 1)).thenReturn(true);
when(pe.hasPermission(bob, domainObject, "WRITE")).thenReturn(true);
when(this.pe.hasPermission(this.bob, domainObject, 1)).thenReturn(true);
when(this.pe.hasPermission(this.bob, domainObject, "WRITE")).thenReturn(true);
tag.setDomainObject(domainObject);
tag.setHasPermission("1,WRITE");
tag.setVar("allowed");
assertThat(tag.getDomainObject()).isSameAs(domainObject);
assertThat(tag.getHasPermission()).isEqualTo("1,WRITE");
this.tag.setDomainObject(domainObject);
this.tag.setHasPermission("1,WRITE");
this.tag.setVar("allowed");
assertThat(this.tag.getDomainObject()).isSameAs(domainObject);
assertThat(this.tag.getHasPermission()).isEqualTo("1,WRITE");
assertThat(tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat((Boolean) pageContext.getAttribute("allowed")).isTrue();
verify(pe).hasPermission(bob, domainObject, 1);
verify(pe).hasPermission(bob, domainObject, "WRITE");
verifyNoMoreInteractions(pe);
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isTrue();
verify(this.pe).hasPermission(this.bob, domainObject, 1);
verify(this.pe).hasPermission(this.bob, domainObject, "WRITE");
verifyNoMoreInteractions(this.pe);
}
@Test
public void bodyIsSkippedIfAclDeniesAccess() throws Exception {
Object domainObject = new Object();
when(pe.hasPermission(bob, domainObject, "READ")).thenReturn(false);
when(this.pe.hasPermission(this.bob, domainObject, "READ")).thenReturn(false);
tag.setDomainObject(domainObject);
tag.setHasPermission("READ");
tag.setVar("allowed");
this.tag.setDomainObject(domainObject);
this.tag.setHasPermission("READ");
this.tag.setVar("allowed");
assertThat(tag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat((Boolean) pageContext.getAttribute("allowed")).isFalse();
assertThat(this.tag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isFalse();
}
}

View File

@@ -51,12 +51,12 @@ public class AuthenticationTagTests {
@Test
public void testOperationWhenPrincipalIsAUserDetailsInstance() throws JspException {
SecurityContextHolder.getContext().setAuthentication(auth);
SecurityContextHolder.getContext().setAuthentication(this.auth);
authenticationTag.setProperty("name");
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
assertThat(authenticationTag.getLastMessage()).isEqualTo("rodUserDetails");
this.authenticationTag.setProperty("name");
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
assertThat(this.authenticationTag.getLastMessage()).isEqualTo("rodUserDetails");
}
@Test
@@ -64,20 +64,20 @@ public class AuthenticationTagTests {
SecurityContextHolder.getContext().setAuthentication(
new TestingAuthenticationToken("rodAsString", "koala", AuthorityUtils.NO_AUTHORITIES));
authenticationTag.setProperty("principal");
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
assertThat(authenticationTag.getLastMessage()).isEqualTo("rodAsString");
this.authenticationTag.setProperty("principal");
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
assertThat(this.authenticationTag.getLastMessage()).isEqualTo("rodAsString");
}
@Test
public void testNestedPropertyIsReadCorrectly() throws JspException {
SecurityContextHolder.getContext().setAuthentication(auth);
SecurityContextHolder.getContext().setAuthentication(this.auth);
authenticationTag.setProperty("principal.username");
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
assertThat(authenticationTag.getLastMessage()).isEqualTo("rodUserDetails");
this.authenticationTag.setProperty("principal.username");
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
assertThat(this.authenticationTag.getLastMessage()).isEqualTo("rodUserDetails");
}
@Test
@@ -85,36 +85,36 @@ public class AuthenticationTagTests {
SecurityContextHolder.getContext()
.setAuthentication(new TestingAuthenticationToken(null, "koala", AuthorityUtils.NO_AUTHORITIES));
authenticationTag.setProperty("principal");
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
this.authenticationTag.setProperty("principal");
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
}
@Test
public void testOperationWhenSecurityContextIsNull() throws Exception {
SecurityContextHolder.getContext().setAuthentication(null);
authenticationTag.setProperty("principal");
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
assertThat(authenticationTag.getLastMessage()).isNull();
this.authenticationTag.setProperty("principal");
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
assertThat(this.authenticationTag.getLastMessage()).isNull();
}
@Test
public void testSkipsBodyIfNullOrEmptyOperation() throws Exception {
authenticationTag.setProperty("");
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
this.authenticationTag.setProperty("");
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
}
@Test
public void testThrowsExceptionForUnrecognisedProperty() {
SecurityContextHolder.getContext().setAuthentication(auth);
authenticationTag.setProperty("qsq");
SecurityContextHolder.getContext().setAuthentication(this.auth);
this.authenticationTag.setProperty("qsq");
try {
authenticationTag.doStartTag();
authenticationTag.doEndTag();
this.authenticationTag.doStartTag();
this.authenticationTag.doEndTag();
fail("Should have throwns JspException");
}
catch (JspException expected) {
@@ -124,20 +124,20 @@ public class AuthenticationTagTests {
@Test
public void htmlEscapingIsUsedByDefault() throws Exception {
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("<>& ", ""));
authenticationTag.setProperty("name");
authenticationTag.doStartTag();
authenticationTag.doEndTag();
assertThat(authenticationTag.getLastMessage()).isEqualTo("&lt;&gt;&amp;&#32;");
this.authenticationTag.setProperty("name");
this.authenticationTag.doStartTag();
this.authenticationTag.doEndTag();
assertThat(this.authenticationTag.getLastMessage()).isEqualTo("&lt;&gt;&amp;&#32;");
}
@Test
public void settingHtmlEscapeToFalsePreventsEscaping() throws Exception {
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("<>& ", ""));
authenticationTag.setProperty("name");
authenticationTag.setHtmlEscape("false");
authenticationTag.doStartTag();
authenticationTag.doEndTag();
assertThat(authenticationTag.getLastMessage()).isEqualTo("<>& ");
this.authenticationTag.setProperty("name");
this.authenticationTag.setHtmlEscape("false");
this.authenticationTag.doStartTag();
this.authenticationTag.doEndTag();
assertThat(this.authenticationTag.getLastMessage()).isEqualTo("<>& ");
}
private class MyAuthenticationTag extends AuthenticationTag {
@@ -145,11 +145,11 @@ public class AuthenticationTagTests {
String lastMessage = null;
public String getLastMessage() {
return lastMessage;
return this.lastMessage;
}
protected void writeMessage(String msg) {
lastMessage = msg;
this.lastMessage = msg;
}
}

View File

@@ -64,19 +64,19 @@ public class AuthorizeTagTests {
@Before
public void setUp() {
SecurityContextHolder.getContext().setAuthentication(currentUser);
SecurityContextHolder.getContext().setAuthentication(this.currentUser);
StaticWebApplicationContext ctx = new StaticWebApplicationContext();
BeanDefinitionBuilder webExpressionHandler = BeanDefinitionBuilder
.rootBeanDefinition(DefaultWebSecurityExpressionHandler.class);
webExpressionHandler.addPropertyValue("permissionEvaluator", permissionEvaluator);
webExpressionHandler.addPropertyValue("permissionEvaluator", this.permissionEvaluator);
ctx.registerBeanDefinition("expressionHandler", webExpressionHandler.getBeanDefinition());
ctx.registerSingleton("wipe", MockWebInvocationPrivilegeEvaluator.class);
MockServletContext servletCtx = new MockServletContext();
servletCtx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
authorizeTag = new JspAuthorizeTag();
authorizeTag.setPageContext(new MockPageContext(servletCtx, request, new MockHttpServletResponse()));
this.authorizeTag = new JspAuthorizeTag();
this.authorizeTag.setPageContext(new MockPageContext(servletCtx, this.request, new MockHttpServletResponse()));
}
@After
@@ -89,65 +89,65 @@ public class AuthorizeTagTests {
@Test
public void taglibsDocumentationHasPermissionOr() throws Exception {
Object domain = new Object();
request.setAttribute("domain", domain);
authorizeTag.setAccess("hasPermission(#domain,'read') or hasPermission(#domain,'write')");
when(permissionEvaluator.hasPermission(eq(currentUser), eq(domain), anyString())).thenReturn(true);
this.request.setAttribute("domain", domain);
this.authorizeTag.setAccess("hasPermission(#domain,'read') or hasPermission(#domain,'write')");
when(this.permissionEvaluator.hasPermission(eq(this.currentUser), eq(domain), anyString())).thenReturn(true);
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat(this.authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
}
@Test
public void skipsBodyIfNoAuthenticationPresent() throws Exception {
SecurityContextHolder.clearContext();
authorizeTag.setAccess("permitAll");
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
this.authorizeTag.setAccess("permitAll");
assertThat(this.authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
}
@Test
public void skipsBodyIfAccessExpressionDeniesAccess() throws Exception {
authorizeTag.setAccess("denyAll");
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
this.authorizeTag.setAccess("denyAll");
assertThat(this.authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
}
@Test
public void showsBodyIfAccessExpressionAllowsAccess() throws Exception {
authorizeTag.setAccess("permitAll");
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
this.authorizeTag.setAccess("permitAll");
assertThat(this.authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
}
@Test
public void requestAttributeIsResolvedAsElVariable() throws JspException {
request.setAttribute("blah", "blah");
authorizeTag.setAccess("#blah == 'blah'");
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
this.request.setAttribute("blah", "blah");
this.authorizeTag.setAccess("#blah == 'blah'");
assertThat(this.authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
}
// url attribute tests
@Test
public void skipsBodyWithUrlSetIfNoAuthenticationPresent() throws Exception {
SecurityContextHolder.clearContext();
authorizeTag.setUrl("/something");
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
this.authorizeTag.setUrl("/something");
assertThat(this.authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
}
@Test
public void skipsBodyIfUrlIsNotAllowed() throws Exception {
authorizeTag.setUrl("/notallowed");
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
this.authorizeTag.setUrl("/notallowed");
assertThat(this.authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
}
@Test
public void evaluatesBodyIfUrlIsAllowed() throws Exception {
authorizeTag.setUrl("/allowed");
authorizeTag.setMethod("GET");
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
this.authorizeTag.setUrl("/allowed");
this.authorizeTag.setMethod("GET");
assertThat(this.authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
}
@Test
public void skipsBodyIfMethodIsNotAllowed() throws Exception {
authorizeTag.setUrl("/allowed");
authorizeTag.setMethod("POST");
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
this.authorizeTag.setUrl("/allowed");
this.authorizeTag.setMethod("POST");
assertThat(this.authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
}
public static class MockWebInvocationPrivilegeEvaluator implements WebInvocationPrivilegeEvaluator {