Done implementing SWS-207
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.soap.security.xwss.callback;
|
||||
package org.springframework.ws.soap.security.callback;
|
||||
|
||||
import javax.security.auth.callback.Callback;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
@@ -46,7 +46,7 @@ public class CallbackHandlerChainTest extends TestCase {
|
||||
chain.handle(new Callback[]{callback});
|
||||
}
|
||||
|
||||
public void testUnsupportedNormal() throws Exception {
|
||||
public void testUnsupportedSupported() throws Exception {
|
||||
CallbackHandlerChain chain = new CallbackHandlerChain(new CallbackHandler[]{unsupported, supported});
|
||||
chain.handle(new Callback[]{callback});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.springframework.ws.soap.security.wss4j;
|
||||
|
||||
public class AxiomWss4jMessageInterceptorAcegiCallbackHandlerTest
|
||||
extends Wss4jMessageInterceptorAcegiCallbackHandlerTestCase {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.springframework.ws.soap.security.wss4j;
|
||||
|
||||
public class SaajWss4jMessageInterceptorAcegiCallbackHandlerTest
|
||||
extends Wss4jMessageInterceptorAcegiCallbackHandlerTestCase {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package org.springframework.ws.soap.security.wss4j;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.acegisecurity.Authentication;
|
||||
import org.acegisecurity.AuthenticationManager;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.acegisecurity.userdetails.memory.InMemoryDaoImpl;
|
||||
import org.apache.ws.security.WSConstants;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.EndpointInterceptor;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.acegi.AcegiDigestPasswordValidationCallbackHandler;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.acegi.AcegiPlainTextPasswordValidationCallbackHandler;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorAcegiCallbackHandlerTestCase extends Wss4jTestCase {
|
||||
|
||||
private Properties users = new Properties();
|
||||
|
||||
private MockControl control;
|
||||
|
||||
private AuthenticationManager mock;
|
||||
|
||||
protected void onSetup() throws Exception {
|
||||
control = MockControl.createControl(AuthenticationManager.class);
|
||||
mock = (AuthenticationManager) control.getMock();
|
||||
users.setProperty("Bert", "Ernie,ROLE_TEST");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
control.verify();
|
||||
}
|
||||
|
||||
public void testValidateUsernameTokenPlainText() throws Exception {
|
||||
EndpointInterceptor interceptor = prepareInterceptor("UsernameToken", true, false);
|
||||
SoapMessage message = loadMessage("usernameTokenPlainText-soap.xml");
|
||||
MessageContext messageContext = new DefaultMessageContext(message, getMessageFactory());
|
||||
interceptor.handleRequest(messageContext, null);
|
||||
assertValidateUsernameToken(message);
|
||||
}
|
||||
|
||||
public void testValidateUsernameTokenDigest() throws Exception {
|
||||
EndpointInterceptor interceptor = prepareInterceptor("UsernameToken", true, true);
|
||||
SoapMessage message = loadMessage("usernameTokenDigest-soap.xml");
|
||||
MessageContext messageContext = new DefaultMessageContext(message, getMessageFactory());
|
||||
interceptor.handleRequest(messageContext, null);
|
||||
assertValidateUsernameToken(message);
|
||||
}
|
||||
|
||||
protected void assertValidateUsernameToken(SoapMessage message) throws Exception {
|
||||
Object result = getMessage(message);
|
||||
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);
|
||||
}
|
||||
|
||||
protected EndpointInterceptor prepareInterceptor(String actions, boolean validating, boolean digest)
|
||||
throws Exception {
|
||||
Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
|
||||
if (validating) {
|
||||
interceptor.setValidationActions(actions);
|
||||
}
|
||||
else {
|
||||
interceptor.setSecurementActions(actions);
|
||||
}
|
||||
if (digest) {
|
||||
AcegiDigestPasswordValidationCallbackHandler callbackHandler =
|
||||
new AcegiDigestPasswordValidationCallbackHandler();
|
||||
InMemoryDaoImpl userDetailsService = new InMemoryDaoImpl();
|
||||
userDetailsService.setUserProperties(users);
|
||||
userDetailsService.afterPropertiesSet();
|
||||
callbackHandler.setUserDetailsService(userDetailsService);
|
||||
interceptor.setSecurementPasswordType(WSConstants.PW_DIGEST);
|
||||
interceptor.setValidationCallbackHandler(callbackHandler);
|
||||
interceptor.afterPropertiesSet();
|
||||
}
|
||||
else {
|
||||
AcegiPlainTextPasswordValidationCallbackHandler callbackHandler =
|
||||
new AcegiPlainTextPasswordValidationCallbackHandler();
|
||||
Authentication authResult = new TestingAuthenticationToken("Bert", "Ernie", new GrantedAuthority[0]);
|
||||
control.expectAndReturn(mock.authenticate(new UsernamePasswordAuthenticationToken("Bert", "Ernie")),
|
||||
authResult);
|
||||
callbackHandler.setAuthenticationManager(mock);
|
||||
callbackHandler.afterPropertiesSet();
|
||||
interceptor.setSecurementPasswordType(WSConstants.PW_TEXT);
|
||||
interceptor.setValidationCallbackHandler(callbackHandler);
|
||||
interceptor.afterPropertiesSet();
|
||||
}
|
||||
control.replay();
|
||||
return interceptor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.w3c.dom.Document;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SimpleCallbackHandler;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.KeyStoreCallbackHandler;
|
||||
import org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorEncryptionTestCase extends Wss4jTestCase {
|
||||
@@ -20,8 +20,8 @@ public abstract class Wss4jMessageInterceptorEncryptionTestCase extends Wss4jTes
|
||||
interceptor.setValidationActions("Encrypt");
|
||||
interceptor.setSecurementActions("Encrypt");
|
||||
|
||||
SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
|
||||
callbackHandler.setKeyPassword("123456");
|
||||
KeyStoreCallbackHandler callbackHandler = new KeyStoreCallbackHandler();
|
||||
callbackHandler.setPrivateKeyPassword("123456");
|
||||
interceptor.setValidationCallbackHandler(callbackHandler);
|
||||
|
||||
CryptoFactoryBean cryptoFactoryBean = new CryptoFactoryBean();
|
||||
@@ -63,6 +63,5 @@ public abstract class Wss4jMessageInterceptorEncryptionTestCase extends Wss4jTes
|
||||
Document document = getDocument(message);
|
||||
assertXpathExists("Encryption error", "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/xenc:EncryptedKey",
|
||||
document);
|
||||
//TODO see why the clear message appears in the unit test
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapHeaderElement;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SimpleCallbackHandler;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SimplePasswordValidationCallbackHandler;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorHeaderTestCase extends Wss4jTestCase {
|
||||
|
||||
@@ -21,7 +21,7 @@ public abstract class Wss4jMessageInterceptorHeaderTestCase extends Wss4jTestCas
|
||||
interceptor.setValidateRequest(true);
|
||||
interceptor.setSecureResponse(true);
|
||||
interceptor.setValidationActions("UsernameToken");
|
||||
SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
|
||||
SimplePasswordValidationCallbackHandler callbackHandler = new SimplePasswordValidationCallbackHandler();
|
||||
callbackHandler.setUsers(users);
|
||||
interceptor.setValidationCallbackHandler(callbackHandler);
|
||||
interceptor.afterPropertiesSet();
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SimpleCallbackHandler;
|
||||
import org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorSignTestCase extends Wss4jTestCase {
|
||||
@@ -19,8 +18,6 @@ public abstract class Wss4jMessageInterceptorSignTestCase extends Wss4jTestCase
|
||||
protected void onSetup() throws Exception {
|
||||
interceptor = new Wss4jSecurityInterceptor();
|
||||
interceptor.setValidationActions("Signature");
|
||||
SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
|
||||
interceptor.setValidationCallbackHandler(callbackHandler);
|
||||
|
||||
CryptoFactoryBean cryptoFactoryBean = new CryptoFactoryBean();
|
||||
Properties cryptoFactoryBeanConfig = new Properties();
|
||||
@@ -61,7 +58,6 @@ public abstract class Wss4jMessageInterceptorSignTestCase extends Wss4jTestCase
|
||||
interceptor.secureMessage(message, messageContext);
|
||||
assertNotNull("No result returned", response);
|
||||
Document document = getDocument((SoapMessage) response);
|
||||
message.writeTo(System.out);
|
||||
assertXpathExists("Absent SignatureConfirmation element",
|
||||
"/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse11:SignatureConfirmation", document);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.w3c.dom.Document;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SimpleCallbackHandler;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SimplePasswordValidationCallbackHandler;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorUsernameTokenTestCase extends Wss4jTestCase {
|
||||
|
||||
@@ -96,16 +96,16 @@ public abstract class Wss4jMessageInterceptorUsernameTokenTestCase extends Wss4j
|
||||
else {
|
||||
interceptor.setSecurementActions(actions);
|
||||
}
|
||||
SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
|
||||
SimplePasswordValidationCallbackHandler callbackHandler = new SimplePasswordValidationCallbackHandler();
|
||||
callbackHandler.setUsers(users);
|
||||
if (digest) {
|
||||
callbackHandler.setPasswordDigestRequired(true);
|
||||
callbackHandler.setPasswordPlainTextRequired(false);
|
||||
// callbackHandler.setPasswordDigestRequired(true);
|
||||
// callbackHandler.setPasswordPlainTextRequired(false);
|
||||
interceptor.setSecurementPasswordType(WSConstants.PW_DIGEST);
|
||||
}
|
||||
else {
|
||||
callbackHandler.setPasswordDigestRequired(false);
|
||||
callbackHandler.setPasswordPlainTextRequired(true);
|
||||
// callbackHandler.setPasswordDigestRequired(false);
|
||||
// callbackHandler.setPasswordPlainTextRequired(true);
|
||||
interceptor.setSecurementPasswordType(WSConstants.PW_TEXT);
|
||||
}
|
||||
interceptor.setValidationCallbackHandler(callbackHandler);
|
||||
|
||||
Reference in New Issue
Block a user