1
0
mirror of synced 2026-08-05 01:36:56 +00:00

SEC-1552 Refactor AuthorizeTag and LegacyAuthorize tag to make them independent of JSP tag rendering.

This commit is contained in:
Rossen Stoyanchev
2010-10-26 12:33:51 +01:00
parent 7258abbbf4
commit 70600a0277
11 changed files with 458 additions and 346 deletions
@@ -36,7 +36,7 @@ import javax.servlet.jsp.tagext.Tag;
public class AuthorizeTagAttributeTests extends TestCase {
//~ Instance fields ================================================================================================
private final LegacyAuthorizeTag authorizeTag = new LegacyAuthorizeTag();
private final JspAuthorizeTag authorizeTag = new JspAuthorizeTag();
private TestingAuthenticationToken currentUser;
//~ Methods ========================================================================================================
@@ -34,7 +34,7 @@ import javax.servlet.jsp.tagext.Tag;
public class AuthorizeTagCustomGrantedAuthorityTests extends TestCase {
//~ Instance fields ================================================================================================
private final LegacyAuthorizeTag authorizeTag = new LegacyAuthorizeTag();
private final JspAuthorizeTag authorizeTag = new JspAuthorizeTag();
private TestingAuthenticationToken currentUser;
//~ Methods ========================================================================================================
@@ -33,7 +33,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
public class AuthorizeTagExpressionLanguageTests extends TestCase {
//~ Instance fields ================================================================================================
private final LegacyAuthorizeTag authorizeTag = new LegacyAuthorizeTag();
private final JspAuthorizeTag authorizeTag = new JspAuthorizeTag();
private MockPageContext pageContext;
private TestingAuthenticationToken currentUser;
@@ -43,7 +43,7 @@ import org.springframework.web.context.support.StaticWebApplicationContext;
public class AuthorizeTagTests {
//~ Instance fields ================================================================================================
private AuthorizeTag authorizeTag;
private JspAuthorizeTag authorizeTag;
private final TestingAuthenticationToken currentUser = new TestingAuthenticationToken("abc", "123", "ROLE SUPERVISOR", "ROLE_TELLER");
//~ Methods ========================================================================================================
@@ -56,7 +56,7 @@ public class AuthorizeTagTests {
ctx.registerSingleton("wipe", MockWebInvocationPrivilegeEvaluator.class);
MockServletContext servletCtx = new MockServletContext();
servletCtx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
authorizeTag = new AuthorizeTag();
authorizeTag = new JspAuthorizeTag();
authorizeTag.setPageContext(new MockPageContext(servletCtx, new MockHttpServletRequest(), new MockHttpServletResponse()));
}
@@ -125,9 +125,18 @@ public class AuthorizeTagTests {
@Test
public void testDefaultsToNotOutputtingBodyWhenNoRequiredAuthorities() throws JspException {
assertEquals("", authorizeTag.getIfAllGranted());
assertEquals("", authorizeTag.getIfAnyGranted());
assertEquals("", authorizeTag.getIfNotGranted());
assertEquals(null, authorizeTag.getIfAllGranted());
assertEquals(null, authorizeTag.getIfAnyGranted());
assertEquals(null, authorizeTag.getIfNotGranted());
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
}
@Test
public void testDefaultsToNotOutputtingBodyWhenNoAuthoritiesProvided() throws JspException {
authorizeTag.setIfAllGranted("");
authorizeTag.setIfAnyGranted("");
authorizeTag.setIfNotGranted("");
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
}