SWS-285
This commit is contained in:
@@ -35,6 +35,7 @@ public abstract class Wss4jMessageInterceptorAcegiCallbackHandlerTestCase extend
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
control.verify();
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
public void testValidateUsernameTokenPlainText() throws Exception {
|
||||
@@ -43,6 +44,11 @@ public abstract class Wss4jMessageInterceptorAcegiCallbackHandlerTestCase extend
|
||||
MessageContext messageContext = new DefaultMessageContext(message, getMessageFactory());
|
||||
interceptor.handleRequest(messageContext, null);
|
||||
assertValidateUsernameToken(message);
|
||||
|
||||
// test clean up
|
||||
messageContext.getResponse();
|
||||
interceptor.handleResponse(messageContext, null);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
public void testValidateUsernameTokenDigest() throws Exception {
|
||||
@@ -51,6 +57,11 @@ public abstract class Wss4jMessageInterceptorAcegiCallbackHandlerTestCase extend
|
||||
MessageContext messageContext = new DefaultMessageContext(message, getMessageFactory());
|
||||
interceptor.handleRequest(messageContext, null);
|
||||
assertValidateUsernameToken(message);
|
||||
|
||||
// test clean up
|
||||
messageContext.getResponse();
|
||||
interceptor.handleResponse(messageContext, null);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
protected void assertValidateUsernameToken(SoapMessage message) throws Exception {
|
||||
@@ -58,9 +69,7 @@ public abstract class Wss4jMessageInterceptorAcegiCallbackHandlerTestCase extend
|
||||
assertNotNull("No result returned", result);
|
||||
assertXpathNotExists("Security Header not removed", "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security",
|
||||
getDocument(message));
|
||||
Authentication authentication = SecurityContextHolder.getContext()
|
||||
.getAuthentication();
|
||||
assertNotNull("authentication must not be null", authentication);
|
||||
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
protected EndpointInterceptor prepareInterceptor(String actions, boolean validating, boolean digest)
|
||||
|
||||
@@ -25,11 +25,13 @@ import junit.framework.TestCase;
|
||||
import org.acegisecurity.AuthenticationManager;
|
||||
import org.acegisecurity.BadCredentialsException;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.acegisecurity.providers.x509.X509AuthenticationToken;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ws.soap.security.callback.CleanupCallback;
|
||||
|
||||
public class AcegiCertificateValidationCallbackHandlerTest extends TestCase {
|
||||
|
||||
@@ -63,6 +65,10 @@ public class AcegiCertificateValidationCallbackHandlerTest extends TestCase {
|
||||
callback = new CertificateValidationCallback(certificate);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
public void testValidateCertificateValid() throws Exception {
|
||||
mock.authenticate(new X509AuthenticationToken(certificate));
|
||||
control.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
@@ -71,6 +77,7 @@ public class AcegiCertificateValidationCallbackHandlerTest extends TestCase {
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertTrue("Not authenticated", authenticated);
|
||||
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
}
|
||||
|
||||
@@ -82,7 +89,18 @@ public class AcegiCertificateValidationCallbackHandlerTest extends TestCase {
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
}
|
||||
|
||||
public void testCleanUp() throws Exception {
|
||||
TestingAuthenticationToken authentication =
|
||||
new TestingAuthenticationToken(new Object(), new Object(), new GrantedAuthority[0]);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
||||
CleanupCallback cleanupCallback = new CleanupCallback();
|
||||
callbackHandler.handleInternal(cleanupCallback);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,11 +19,15 @@ package org.springframework.ws.soap.security.xwss.callback.acegi;
|
||||
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
|
||||
import junit.framework.TestCase;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.acegisecurity.userdetails.User;
|
||||
import org.acegisecurity.userdetails.UserDetailsService;
|
||||
import org.acegisecurity.userdetails.UsernameNotFoundException;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.ws.soap.security.callback.CleanupCallback;
|
||||
|
||||
public class AcegiDigestPasswordValidationCallbackHandlerTest extends TestCase {
|
||||
|
||||
private AcegiDigestPasswordValidationCallbackHandler callbackHandler;
|
||||
@@ -53,12 +57,17 @@ public class AcegiDigestPasswordValidationCallbackHandlerTest extends TestCase {
|
||||
callback = new PasswordValidationCallback(request);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
public void testAuthenticateUserDigestUserNotFound() throws Exception {
|
||||
control.expectAndThrow(mock.loadUserByUsername(username), new UsernameNotFoundException(username));
|
||||
control.replay();
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
}
|
||||
|
||||
@@ -69,6 +78,7 @@ public class AcegiDigestPasswordValidationCallbackHandlerTest extends TestCase {
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertTrue("Not authenticated", authenticated);
|
||||
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
}
|
||||
|
||||
@@ -79,6 +89,18 @@ public class AcegiDigestPasswordValidationCallbackHandlerTest extends TestCase {
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
}
|
||||
|
||||
public void testCleanUp() throws Exception {
|
||||
TestingAuthenticationToken authentication =
|
||||
new TestingAuthenticationToken(new Object(), new Object(), new GrantedAuthority[0]);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
||||
CleanupCallback cleanupCallback = new CleanupCallback();
|
||||
callbackHandler.handleInternal(cleanupCallback);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,10 +22,13 @@ import org.acegisecurity.Authentication;
|
||||
import org.acegisecurity.AuthenticationManager;
|
||||
import org.acegisecurity.BadCredentialsException;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.ws.soap.security.callback.CleanupCallback;
|
||||
|
||||
public class AcegiPlainTextPasswordValidationCallbackHandlerTest extends TestCase {
|
||||
|
||||
private AcegiPlainTextPasswordValidationCallbackHandler callbackHandler;
|
||||
@@ -52,6 +55,10 @@ public class AcegiPlainTextPasswordValidationCallbackHandlerTest extends TestCas
|
||||
callback = new PasswordValidationCallback(request);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
public void testAuthenticateUserPlainTextValid() throws Exception {
|
||||
Authentication authResult = new TestingAuthenticationToken(username, password, new GrantedAuthority[0]);
|
||||
control.expectAndReturn(mock.authenticate(new UsernamePasswordAuthenticationToken(username, password)),
|
||||
@@ -60,6 +67,7 @@ public class AcegiPlainTextPasswordValidationCallbackHandlerTest extends TestCas
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertTrue("Not authenticated", authenticated);
|
||||
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
}
|
||||
|
||||
@@ -70,7 +78,18 @@ public class AcegiPlainTextPasswordValidationCallbackHandlerTest extends TestCas
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
}
|
||||
|
||||
public void testCleanUp() throws Exception {
|
||||
TestingAuthenticationToken authentication =
|
||||
new TestingAuthenticationToken(new Object(), new Object(), new GrantedAuthority[0]);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
||||
CleanupCallback cleanupCallback = new CleanupCallback();
|
||||
callbackHandler.handleInternal(cleanupCallback);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package org.springframework.ws.soap.security.xwss.callback.jaas;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.security.auth.Subject;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import javax.security.auth.login.LoginException;
|
||||
@@ -72,7 +71,7 @@ public class CertificateLoginModule implements LoginModule {
|
||||
for (Iterator iterator = subject.getPrincipals().iterator(); iterator.hasNext();) {
|
||||
Principal principal = (Principal) iterator.next();
|
||||
if (principal instanceof X500Principal) {
|
||||
return ((X500Principal) principal).getName();
|
||||
return principal.getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user