SEC-576: Tidying.
This commit is contained in:
+12
-26
@@ -2,13 +2,13 @@ package org.springframework.security.ui.preauth;
|
||||
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
import org.springframework.security.MockAuthenticationManager;
|
||||
import org.springframework.security.ui.FilterChainOrder;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.MockFilterChain;
|
||||
import org.springframework.mock.web.MockFilterConfig;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
@@ -17,8 +17,7 @@ public class PreAuthenticatedProcessingFilterTests extends TestCase {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
public void testAfterPropertiesSet()
|
||||
{
|
||||
public void testAfterPropertiesSet() {
|
||||
ConcretePreAuthenticatedProcessingFilter filter = new ConcretePreAuthenticatedProcessingFilter();
|
||||
try {
|
||||
filter.afterPropertiesSet();
|
||||
@@ -28,52 +27,39 @@ public class PreAuthenticatedProcessingFilterTests extends TestCase {
|
||||
fail("AfterPropertiesSet throws unexpected exception");
|
||||
}
|
||||
}
|
||||
|
||||
public void testInit() throws Exception
|
||||
{
|
||||
getFilter(true).init(new MockFilterConfig());
|
||||
// Init doesn't do anything, so nothing to test
|
||||
}
|
||||
|
||||
public void testDestroy() throws Exception
|
||||
{
|
||||
getFilter(true).destroy();
|
||||
// Destroy doesn't do anything, so nothing to test
|
||||
}
|
||||
|
||||
public final void testDoFilterAuthenticated() throws Exception
|
||||
{
|
||||
public final void testDoFilterAuthenticated() throws Exception {
|
||||
testDoFilter(true);
|
||||
}
|
||||
|
||||
public final void testDoFilterUnauthenticated() throws Exception
|
||||
{
|
||||
public final void testDoFilterUnauthenticated() throws Exception {
|
||||
testDoFilter(false);
|
||||
}
|
||||
|
||||
private final void testDoFilter(boolean grantAccess) throws Exception
|
||||
{
|
||||
private final void testDoFilter(boolean grantAccess) throws Exception {
|
||||
MockHttpServletRequest req = new MockHttpServletRequest();
|
||||
MockHttpServletResponse res = new MockHttpServletResponse();
|
||||
getFilter(grantAccess).doFilter(req,res,new MockFilterChain());
|
||||
assertEquals(grantAccess,null!= SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
private static final ConcretePreAuthenticatedProcessingFilter getFilter(boolean grantAccess) throws Exception
|
||||
{
|
||||
private static final ConcretePreAuthenticatedProcessingFilter getFilter(boolean grantAccess) throws Exception {
|
||||
ConcretePreAuthenticatedProcessingFilter filter = new ConcretePreAuthenticatedProcessingFilter();
|
||||
filter.setAuthenticationManager(new MockAuthenticationManager(grantAccess));
|
||||
filter.afterPropertiesSet();
|
||||
return filter;
|
||||
}
|
||||
|
||||
private static final class ConcretePreAuthenticatedProcessingFilter extends AbstractPreAuthenticatedProcessingFilter
|
||||
{
|
||||
private static final class ConcretePreAuthenticatedProcessingFilter extends AbstractPreAuthenticatedProcessingFilter {
|
||||
protected Object getPreAuthenticatedPrincipal(HttpServletRequest httpRequest) {
|
||||
return "testPrincipal";
|
||||
}
|
||||
protected Object getPreAuthenticatedCredentials(HttpServletRequest httpRequest) {
|
||||
return "testCredentials";
|
||||
}
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return FilterChainOrder.PRE_AUTH_FILTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user