- Removed packages scheduled for removal in 2.0.

- Added @Deprecated annotations.
This commit is contained in:
Arjen Poutsma
2010-02-01 11:25:25 +00:00
parent 9bc9786a0a
commit aba8e64434
44 changed files with 31 additions and 4897 deletions

View File

@@ -1,65 +0,0 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.support;
import org.acegisecurity.AccountExpiredException;
import org.acegisecurity.CredentialsExpiredException;
import org.acegisecurity.DisabledException;
import org.acegisecurity.LockedException;
import org.acegisecurity.userdetails.UserDetails;
/**
* Generic utility methods for Spring Security
*
* @author Tareq Abedrabbo
* @since 1.5.8
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public abstract class AcegiUtils {
/**
* Checks the validity of a user's account and credentials.
*
* @param user the user to check
* @throws org.springframework.security.AccountExpiredException
* if the account has expired
* @throws org.springframework.security.CredentialsExpiredException
* if the credentials have expired
* @throws org.springframework.security.DisabledException
* if the account is disabled
* @throws org.springframework.security.LockedException
* if the account is locked
*/
public static void checkUserValidity(UserDetails user)
throws AccountExpiredException, CredentialsExpiredException, DisabledException, LockedException {
if (!user.isAccountNonLocked()) {
throw new LockedException("User account is locked");
}
if (!user.isEnabled()) {
throw new DisabledException("User is disabled");
}
if (!user.isAccountNonExpired()) {
throw new AccountExpiredException("User account has expired");
}
if (!user.isCredentialsNonExpired()) {
throw new CredentialsExpiredException("User credentials have expired");
}
}
}

View File

@@ -366,7 +366,8 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl
/** Sets the server-side time to live
* @deprecated Use {@link #setValidationTimeToLive(int)} instead.
* */
*/
@Deprecated
public void setTimeToLive(int timeToLive) {
setValidationTimeToLive(timeToLive);
}

View File

@@ -1,119 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.wss4j.callback.acegi;
import java.io.IOException;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.acegisecurity.providers.dao.UserCache;
import org.acegisecurity.providers.dao.cache.NullUserCache;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.apache.ws.security.WSPasswordCallback;
import org.apache.ws.security.WSUsernameTokenPrincipal;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.util.Assert;
import org.springframework.ws.soap.security.callback.CleanupCallback;
import org.springframework.ws.soap.security.support.AcegiUtils;
import org.springframework.ws.soap.security.wss4j.callback.AbstractWsPasswordCallbackHandler;
import org.springframework.ws.soap.security.wss4j.callback.UsernameTokenPrincipalCallback;
/**
* Callback handler that validates a password digest using an Acegi <code>UserDetailsService</code>. Logic based on
* Acegi's <code>DigestProcessingFilter</code>.
* <p/>
* An Acegi <code>UserDetailService</code> is used to load <code>UserDetails</code> from. The digest of the password
* contained in this details object is then compared with the digest in the message.
*
* @author Arjen Poutsma
* @see org.acegisecurity.userdetails.UserDetailsService
* @see org.acegisecurity.ui.digestauth.DigestProcessingFilter
* @since 1.5.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiDigestPasswordValidationCallbackHandler extends AbstractWsPasswordCallbackHandler
implements InitializingBean {
private UserCache userCache = new NullUserCache();
private UserDetailsService userDetailsService;
/** Sets the users cache. Not required, but can benefit performance. */
public void setUserCache(UserCache userCache) {
this.userCache = userCache;
}
/** Sets the Acegi user details service. Required. */
public void setUserDetailsService(UserDetailsService userDetailsService) {
this.userDetailsService = userDetailsService;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(userDetailsService, "userDetailsService is required");
}
@Override
protected void handleUsernameToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
String identifier = callback.getIdentifier();
UserDetails user = loadUserDetails(identifier);
if (user != null) {
AcegiUtils.checkUserValidity(user);
callback.setPassword(user.getPassword());
}
}
@Override
protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback)
throws IOException, UnsupportedCallbackException {
UserDetails user = loadUserDetails(callback.getPrincipal().getName());
WSUsernameTokenPrincipal principal = callback.getPrincipal();
UsernamePasswordAuthenticationToken authRequest =
new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), user.getAuthorities());
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authRequest.toString());
}
SecurityContextHolder.getContext().setAuthentication(authRequest);
}
@Override
protected void handleCleanup(CleanupCallback callback) throws IOException, UnsupportedCallbackException {
SecurityContextHolder.clearContext();
}
private UserDetails loadUserDetails(String username) throws DataAccessException {
UserDetails user = userCache.getUserFromCache(username);
if (user == null) {
try {
user = userDetailsService.loadUserByUsername(username);
}
catch (UsernameNotFoundException notFound) {
if (logger.isDebugEnabled()) {
logger.debug("Username '" + username + "' not found");
}
return null;
}
userCache.putUserInCache(user);
}
return user;
}
}

View File

@@ -1,96 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.wss4j.callback.acegi;
import java.io.IOException;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.apache.ws.security.WSPasswordCallback;
import org.apache.ws.security.WSSecurityException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.ws.soap.security.callback.CleanupCallback;
import org.springframework.ws.soap.security.wss4j.callback.AbstractWsPasswordCallbackHandler;
/**
* Callback handler that validates a certificate uses an Acegi <code>AuthenticationManager</code>. Logic based on
* Acegi's <code>BasicProcessingFilter</code>.
* <p/>
* This handler requires an Acegi <code>AuthenticationManager</code> to operate. It can be set using the
* <code>authenticationManager</code> property. An Acegi <code>UsernamePasswordAuthenticationToken</code> is created
* with the username as principal and password as credentials.
*
* @author Arjen Poutsma
* @see org.acegisecurity.providers.UsernamePasswordAuthenticationToken
* @see org.acegisecurity.ui.basicauth.BasicProcessingFilter
* @since 1.5.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiPlainTextPasswordValidationCallbackHandler extends AbstractWsPasswordCallbackHandler
implements InitializingBean {
private AuthenticationManager authenticationManager;
private boolean ignoreFailure = false;
/** Sets the Acegi authentication manager. Required. */
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}
public void setIgnoreFailure(boolean ignoreFailure) {
this.ignoreFailure = ignoreFailure;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(authenticationManager, "authenticationManager is required");
}
@Override
protected void handleCleanup(CleanupCallback callback) throws IOException, UnsupportedCallbackException {
SecurityContextHolder.clearContext();
}
@Override
protected void handleUsernameTokenUnknown(WSPasswordCallback callback)
throws IOException, UnsupportedCallbackException {
String identifier = callback.getIdentifier();
try {
Authentication authResult = authenticationManager
.authenticate(new UsernamePasswordAuthenticationToken(identifier, callback.getPassword()));
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authResult.toString());
}
SecurityContextHolder.getContext().setAuthentication(authResult);
}
catch (AuthenticationException failed) {
if (logger.isDebugEnabled()) {
logger.debug("Authentication request for user '" + identifier + "' failed: " + failed.toString());
}
SecurityContextHolder.clearContext();
if (!ignoreFailure) {
throw new WSSecurityException(WSSecurityException.FAILED_AUTHENTICATION);
}
}
}
}

View File

@@ -1,6 +0,0 @@
<html>
<body>
Contains <code>CallbackHandler</code> implementations for WSS4J that use the <a href="http://www.acegisecurity.org/">Acegi
Security System for Spring</a>.
</body>
</html>

View File

@@ -1,117 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.xwss.callback.acegi;
import java.io.IOException;
import java.security.cert.X509Certificate;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.x509.X509AuthenticationToken;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
import org.springframework.ws.soap.security.callback.CleanupCallback;
/**
* Callback handler that validates a certificate using an Acegi <code>AuthenticationManager</code>. Logic based on
* Acegi's <code>X509ProcessingFilter</code>. <p/> An Acegi <code>X509AuthenticationToken</code> is created with the
* certificate as the credentials. <p/> The configured authentication manager is expected to supply a provider which can
* handle this token (usually an instance of <code>X509AuthenticationProvider</code>).</p>
* <p/>
* This class only handles <code>CertificateValidationCallback</code>s, and throws an
* <code>UnsupportedCallbackException</code> for others.
*
* @author Arjen Poutsma
* @see X509AuthenticationToken
* @see org.acegisecurity.providers.x509.X509AuthenticationProvider
* @see org.acegisecurity.ui.x509.X509ProcessingFilter
* @see CertificateValidationCallback
* @since 1.0.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiCertificateValidationCallbackHandler extends AbstractCallbackHandler implements InitializingBean {
private AuthenticationManager authenticationManager;
private boolean ignoreFailure = false;
/** Sets the Acegi authentication manager. Required. */
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}
public void setIgnoreFailure(boolean ignoreFailure) {
this.ignoreFailure = ignoreFailure;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(authenticationManager, "authenticationManager is required");
}
/**
* Handles <code>CertificateValidationCallback</code>s, and throws an <code>UnsupportedCallbackException</code> for
* others
*
* @throws UnsupportedCallbackException when the callback is not supported
*/
@Override
protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
if (callback instanceof CertificateValidationCallback) {
((CertificateValidationCallback) callback).setValidator(new AcegiCertificateValidator());
}
else if (callback instanceof CleanupCallback) {
SecurityContextHolder.clearContext();
}
else {
throw new UnsupportedCallbackException(callback);
}
}
private class AcegiCertificateValidator implements CertificateValidationCallback.CertificateValidator {
public boolean validate(X509Certificate certificate)
throws CertificateValidationCallback.CertificateValidationException {
boolean result;
try {
Authentication authResult =
authenticationManager.authenticate(new X509AuthenticationToken(certificate));
if (logger.isDebugEnabled()) {
logger.debug("Authentication request for certificate with DN [" +
certificate.getSubjectX500Principal().getName() + "] successful");
}
SecurityContextHolder.getContext().setAuthentication(authResult);
return true;
}
catch (AuthenticationException failed) {
if (logger.isDebugEnabled()) {
logger.debug("Authentication request for certificate with DN [" +
certificate.getSubjectX500Principal().getName() + "] failed: " + failed.toString());
}
SecurityContextHolder.clearContext();
result = ignoreFailure;
}
return result;
}
}
}

View File

@@ -1,160 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.xwss.callback.acegi;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
import com.sun.xml.wss.impl.callback.TimestampValidationCallback;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.acegisecurity.providers.dao.UserCache;
import org.acegisecurity.providers.dao.cache.NullUserCache;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.util.Assert;
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
import org.springframework.ws.soap.security.callback.CleanupCallback;
import org.springframework.ws.soap.security.support.AcegiUtils;
import org.springframework.ws.soap.security.xwss.callback.DefaultTimestampValidator;
/**
* Callback handler that validates a password digest using an Acegi <code>UserDetailsService</code>. Logic based on
* Acegi's <code>DigestProcessingFilter</code>.
* <p/>
* An Acegi <code>UserDetailService</code> is used to load <code>UserDetails</code> from. The digest of the password
* contained in this details object is then compared with the digest in the message.
* <p/>
* This class only handles <code>PasswordValidationCallback</code>s that contain a <code>DigestPasswordRequest</code>,
* and throws an <code>UnsupportedCallbackException</code> for others.
*
* @author Arjen Poutsma
* @see UserDetailsService
* @see PasswordValidationCallback
* @see com.sun.xml.wss.impl.callback.PasswordValidationCallback.DigestPasswordRequest
* @see org.acegisecurity.ui.digestauth.DigestProcessingFilter
* @since 1.0.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiDigestPasswordValidationCallbackHandler extends AbstractCallbackHandler implements InitializingBean {
private UserCache userCache = new NullUserCache();
private UserDetailsService userDetailsService;
/** Sets the users cache. Not required, but can benefit performance. */
public void setUserCache(UserCache userCache) {
this.userCache = userCache;
}
/** Sets the Acegi user details service. Required. */
public void setUserDetailsService(UserDetailsService userDetailsService) {
this.userDetailsService = userDetailsService;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(userDetailsService, "userDetailsService is required");
}
/**
* Handles <code>PasswordValidationCallback</code>s that contain a <code>DigestPasswordRequest</code>, and throws an
* <code>UnsupportedCallbackException</code> for others
*
* @throws UnsupportedCallbackException when the callback is not supported
*/
@Override
protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
if (callback instanceof PasswordValidationCallback) {
PasswordValidationCallback passwordCallback = (PasswordValidationCallback) callback;
if (passwordCallback.getRequest() instanceof PasswordValidationCallback.DigestPasswordRequest) {
PasswordValidationCallback.DigestPasswordRequest request =
(PasswordValidationCallback.DigestPasswordRequest) passwordCallback.getRequest();
String username = request.getUsername();
UserDetails user = loadUserDetails(username);
if (user != null) {
AcegiUtils.checkUserValidity(user);
request.setPassword(user.getPassword());
}
AcegiDigestPasswordValidator validator = new AcegiDigestPasswordValidator(user);
passwordCallback.setValidator(validator);
return;
}
}
else if (callback instanceof TimestampValidationCallback) {
TimestampValidationCallback timestampCallback = (TimestampValidationCallback) callback;
timestampCallback.setValidator(new DefaultTimestampValidator());
}
else if (callback instanceof CleanupCallback) {
SecurityContextHolder.clearContext();
return;
}
throw new UnsupportedCallbackException(callback);
}
private UserDetails loadUserDetails(String username) throws DataAccessException {
UserDetails user = userCache.getUserFromCache(username);
if (user == null) {
try {
user = userDetailsService.loadUserByUsername(username);
}
catch (UsernameNotFoundException notFound) {
if (logger.isDebugEnabled()) {
logger.debug("Username '" + username + "' not found");
}
return null;
}
userCache.putUserInCache(user);
}
return user;
}
private class AcegiDigestPasswordValidator extends PasswordValidationCallback.DigestPasswordValidator {
private UserDetails user;
private AcegiDigestPasswordValidator(UserDetails user) {
this.user = user;
}
@Override
public boolean validate(PasswordValidationCallback.Request request)
throws PasswordValidationCallback.PasswordValidationException {
if (super.validate(request)) {
UsernamePasswordAuthenticationToken authRequest =
new UsernamePasswordAuthenticationToken(user, user.getPassword());
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authRequest.toString());
}
SecurityContextHolder.getContext().setAuthentication(authRequest);
return true;
}
else {
return false;
}
}
}
}

View File

@@ -1,123 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.xwss.callback.acegi;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
import org.springframework.ws.soap.security.callback.CleanupCallback;
/**
* Callback handler that validates a certificate uses an Acegi <code>AuthenticationManager</code>. Logic based on
* Acegi's <code>BasicProcessingFilter</code>.
* <p/>
* This handler requires an Acegi <code>AuthenticationManager</code> to operate. It can be set using the
* <code>authenticationManager</code> property. An Acegi <code>UsernamePasswordAuthenticationToken</code> is created
* with the username as principal and password as credentials.
* <p/>
* This class only handles <code>PasswordValidationCallback</code>s that contain a
* <code>PlainTextPasswordRequest</code>, and throws an <code>UnsupportedCallbackException</code> for others.
*
* @author Arjen Poutsma
* @see UsernamePasswordAuthenticationToken
* @see PasswordValidationCallback
* @see com.sun.xml.wss.impl.callback.PasswordValidationCallback.PlainTextPasswordRequest
* @see org.acegisecurity.ui.basicauth.BasicProcessingFilter
* @since 1.0.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiPlainTextPasswordValidationCallbackHandler extends AbstractCallbackHandler
implements InitializingBean {
private AuthenticationManager authenticationManager;
private boolean ignoreFailure = false;
/** Sets the Acegi authentication manager. Required. */
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}
public void setIgnoreFailure(boolean ignoreFailure) {
this.ignoreFailure = ignoreFailure;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(authenticationManager, "authenticationManager is required");
}
/**
* Handles <code>PasswordValidationCallback</code>s that contain a <code>PlainTextPasswordRequest</code>, and throws
* an <code>UnsupportedCallbackException</code> for others.
*
* @throws UnsupportedCallbackException when the callback is not supported
*/
@Override
protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
if (callback instanceof PasswordValidationCallback) {
PasswordValidationCallback validationCallback = (PasswordValidationCallback) callback;
if (validationCallback.getRequest() instanceof PasswordValidationCallback.PlainTextPasswordRequest) {
validationCallback.setValidator(new AcegiPlainTextPasswordValidator());
return;
}
}
else if (callback instanceof CleanupCallback) {
SecurityContextHolder.clearContext();
return;
}
throw new UnsupportedCallbackException(callback);
}
private class AcegiPlainTextPasswordValidator implements PasswordValidationCallback.PasswordValidator {
public boolean validate(PasswordValidationCallback.Request request)
throws PasswordValidationCallback.PasswordValidationException {
PasswordValidationCallback.PlainTextPasswordRequest plainTextRequest =
(PasswordValidationCallback.PlainTextPasswordRequest) request;
try {
Authentication authResult = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(plainTextRequest.getUsername(),
plainTextRequest.getPassword()));
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authResult.toString());
}
SecurityContextHolder.getContext().setAuthentication(authResult);
return true;
}
catch (AuthenticationException failed) {
if (logger.isDebugEnabled()) {
logger.debug("Authentication request for user '" + plainTextRequest.getUsername() + "' failed: " +
failed.toString());
}
SecurityContextHolder.clearContext();
return ignoreFailure;
}
}
}
}

View File

@@ -1,69 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.xwss.callback.acegi;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import com.sun.xml.wss.impl.callback.PasswordCallback;
import com.sun.xml.wss.impl.callback.UsernameCallback;
import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContextHolder;
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
/**
* Callback handler that adds username/password information to a mesage using an Acegi {@link
* org.acegisecurity.context.SecurityContext SecurityContext}.
* <p/>
* This class handles <code>UsernameCallback</code>s and <code>PasswordCallback</code>s, and throws an
* <code>UnsupportedCallbackException</code> for others
*
* @author Arjen Poutsma
* @since 1.5.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiUsernamePasswordCallbackHandler extends AbstractCallbackHandler {
@Override
protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
if (callback instanceof UsernameCallback) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.getName() != null) {
UsernameCallback usernameCallback = (UsernameCallback) callback;
usernameCallback.setUsername(authentication.getName());
return;
}
else {
logger.warn("Cannot handle UsernameCallback: Acegi SecurityContext contains no Authentication");
}
}
else if (callback instanceof PasswordCallback) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.getName() != null) {
PasswordCallback passwordCallback = (PasswordCallback) callback;
passwordCallback.setPassword(authentication.getCredentials().toString());
return;
}
else {
logger.warn("Canot handle PasswordCallback: Acegi SecurityContext contains no Authentication");
}
}
throw new UnsupportedCallbackException(callback);
}
}

View File

@@ -1,6 +0,0 @@
<html>
<body>
Contains <code>CallbackHandler</code> implementations for XWSS that use the <a href="http://www.acegisecurity.org/">Acegi
Security System for Spring</a>.
</body>
</html>

View File

@@ -1,92 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.wss4j.callback.acegi;
import junit.framework.TestCase;
import org.acegisecurity.Authentication;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.GrantedAuthorityImpl;
import org.acegisecurity.DisabledException;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.userdetails.User;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.apache.ws.security.WSUsernameTokenPrincipal;
import org.apache.ws.security.WSPasswordCallback;
import org.easymock.MockControl;
import org.springframework.ws.soap.security.wss4j.callback.UsernameTokenPrincipalCallback;
/** @author tareq */
public class AcegiDigestPasswordValidationCallbackHandlerTest extends TestCase {
private AcegiDigestPasswordValidationCallbackHandler callbackHandler;
private GrantedAuthorityImpl grantedAuthority;
private UserDetailsService userDetailsService;
private MockControl control;
private UserDetails user;
@Override
protected void setUp() throws Exception {
callbackHandler = new AcegiDigestPasswordValidationCallbackHandler();
grantedAuthority = new GrantedAuthorityImpl("ROLE_1");
control = MockControl.createControl(UserDetailsService.class);
userDetailsService = (UserDetailsService) control.getMock();
userDetailsService.loadUserByUsername("Ernie");
callbackHandler.setUserDetailsService(userDetailsService);
}
@Override
protected void tearDown() throws Exception {
control.reset();
}
public void testHandleUsernameTokenPrincipal() throws Exception {
user = new User("Ernie", "Bert", true, true, true, true, new GrantedAuthority[]{grantedAuthority});
WSUsernameTokenPrincipal principal = new WSUsernameTokenPrincipal("Ernie", true);
UsernameTokenPrincipalCallback callback = new UsernameTokenPrincipalCallback(principal);
control.setDefaultReturnValue(user);
control.replay();
callbackHandler.handleUsernameTokenPrincipal(callback);
SecurityContext context = SecurityContextHolder.getContext();
assertNotNull("SecurityContext must not be null", context);
Authentication authentication = context.getAuthentication();
assertNotNull("Authentication must not be null", authentication);
GrantedAuthority[] authorities = authentication.getAuthorities();
assertTrue("GrantedAuthority[] must not be null or empty", (authorities != null && authorities.length > 0));
assertEquals("Unexpected authority", grantedAuthority, authorities[0]);
}
public void testHandleUsernameTokenWithDisabledUser() throws Exception {
user = new User("Ernie", "Bert", false, true, true, true, new GrantedAuthority[]{grantedAuthority});
WSPasswordCallback callback = new WSPasswordCallback("ID", WSPasswordCallback.USERNAME_TOKEN);
control.setDefaultReturnValue(user);
control.replay();
try {
callbackHandler.handleUsernameToken(callback);
fail("disabled user authenticated");
} catch (DisabledException expected) {
}
}
}

View File

@@ -1,108 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.xwss.callback.acegi;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
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 {
private AcegiCertificateValidationCallbackHandler callbackHandler;
private MockControl control;
private AuthenticationManager mock;
private X509Certificate certificate;
private CertificateValidationCallback callback;
@Override
protected void setUp() throws Exception {
callbackHandler = new AcegiCertificateValidationCallbackHandler();
control = MockControl.createControl(AuthenticationManager.class);
mock = (AuthenticationManager) control.getMock();
callbackHandler.setAuthenticationManager(mock);
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream is = null;
try {
is = new ClassPathResource("/org/springframework/ws/soap/security/xwss/test-keystore.jks").getInputStream();
keyStore.load(is, "password".toCharArray());
}
finally {
if (is != null) {
is.close();
}
}
certificate = (X509Certificate) keyStore.getCertificate("alias");
callback = new CertificateValidationCallback(certificate);
}
@Override
protected void tearDown() throws Exception {
SecurityContextHolder.clearContext();
}
public void testValidateCertificateValid() throws Exception {
mock.authenticate(new X509AuthenticationToken(certificate));
control.setMatcher(MockControl.ALWAYS_MATCHER);
control.setReturnValue(new TestingAuthenticationToken(certificate, null, new GrantedAuthority[0]));
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertTrue("Not authenticated", authenticated);
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testValidateCertificateInvalid() throws Exception {
mock.authenticate(new X509AuthenticationToken(certificate));
control.setMatcher(MockControl.ALWAYS_MATCHER);
control.setThrowable(new BadCredentialsException(""));
control.replay();
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());
}
}

View File

@@ -1,121 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.DisabledException;
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;
private MockControl control;
private UserDetailsService mock;
private String username;
private String password;
private PasswordValidationCallback callback;
@Override
protected void setUp() throws Exception {
callbackHandler = new AcegiDigestPasswordValidationCallbackHandler();
control = MockControl.createControl(UserDetailsService.class);
mock = (UserDetailsService) control.getMock();
callbackHandler.setUserDetailsService(mock);
username = "Bert";
password = "Ernie";
String nonce = "9mdsYDCrjjYRur0rxzYt2oD7";
String passwordDigest = "kwNstEaiFOrI7B31j7GuETYvdgk=";
String creationTime = "2006-06-01T23:48:42Z";
PasswordValidationCallback.DigestPasswordRequest request =
new PasswordValidationCallback.DigestPasswordRequest(username, passwordDigest, nonce, creationTime);
callback = new PasswordValidationCallback(request);
}
@Override
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();
}
public void testAuthenticateUserDigestValid() throws Exception {
User user = new User(username, password, true, true, true, true, new GrantedAuthority[0]);
control.expectAndReturn(mock.loadUserByUsername(username), user);
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertTrue("Not authenticated", authenticated);
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testAuthenticateUserDigestValidInvalid() throws Exception {
User user = new User(username, "Big bird", true, true, true, true, new GrantedAuthority[0]);
control.expectAndReturn(mock.loadUserByUsername(username), user);
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertFalse("Authenticated", authenticated);
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testAuthenticateUserDigestDisbaled() throws Exception {
User user = new User(username, "Ernie", false, true, true, true, new GrantedAuthority[0]);
control.expectAndReturn(mock.loadUserByUsername(username), user);
control.replay();
try {
callbackHandler.handleInternal(callback);
fail("disabled user authenticated");
} catch (
DisabledException expected) {
}
}
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());
}
}

View File

@@ -1,97 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.xwss.callback.acegi;
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
import junit.framework.TestCase;
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;
private MockControl control;
private AuthenticationManager mock;
private PasswordValidationCallback callback;
private String username;
private String password;
@Override
protected void setUp() throws Exception {
callbackHandler = new AcegiPlainTextPasswordValidationCallbackHandler();
control = MockControl.createControl(AuthenticationManager.class);
mock = (AuthenticationManager) control.getMock();
callbackHandler.setAuthenticationManager(mock);
username = "Bert";
password = "Ernie";
PasswordValidationCallback.PlainTextPasswordRequest request =
new PasswordValidationCallback.PlainTextPasswordRequest(username, password);
callback = new PasswordValidationCallback(request);
}
@Override
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)),
authResult);
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertTrue("Not authenticated", authenticated);
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testAuthenticateUserPlainTextInvalid() throws Exception {
control.expectAndThrow(mock.authenticate(new UsernamePasswordAuthenticationToken(username, password)),
new BadCredentialsException(""));
control.replay();
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());
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.soap.security.xwss.callback.acegi;
import com.sun.xml.wss.impl.callback.PasswordCallback;
import com.sun.xml.wss.impl.callback.UsernameCallback;
import junit.framework.TestCase;
import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
public class AcegiUsernamePasswordCallbackHandlerTest extends TestCase {
private AcegiUsernamePasswordCallbackHandler handler;
@Override
protected void setUp() throws Exception {
handler = new AcegiUsernamePasswordCallbackHandler();
Authentication authentication = new UsernamePasswordAuthenticationToken("Bert", "Ernie");
SecurityContextHolder.getContext().setAuthentication(authentication);
}
@Override
protected void tearDown() throws Exception {
SecurityContextHolder.clearContext();
}
public void testUsernameCallback() throws Exception {
UsernameCallback usernameCallback = new UsernameCallback();
handler.handleInternal(usernameCallback);
assertEquals("Invalid username", "Bert", usernameCallback.getUsername());
}
public void testPasswordCallback() throws Exception {
PasswordCallback passwordCallback = new PasswordCallback();
handler.handleInternal(passwordCallback);
assertEquals("Invalid username", "Ernie", passwordCallback.getPassword());
}
}