SEC-2781: Remove deprecations
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* 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.security.access;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
/**
|
||||
* A property editor that can create a populated <tt>List<ConfigAttribute></tt> from a comma separated list of values.
|
||||
* <p>
|
||||
* Trims preceding and trailing spaces from presented command separated tokens, as this can be a source
|
||||
* of hard-to-spot configuration issues for end users.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @deprecated
|
||||
*/
|
||||
public class ConfigAttributeEditor extends PropertyEditorSupport {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void setAsText(String s) throws IllegalArgumentException {
|
||||
if (StringUtils.hasText(s)) {
|
||||
setValue(SecurityConfig.createList(StringUtils.commaDelimitedListToStringArray(s)));
|
||||
} else {
|
||||
setValue(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,14 +66,6 @@ public class SecurityConfig implements ConfigAttribute {
|
||||
return createList(StringUtils.commaDelimitedListToStringArray(access));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use createList instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static List<ConfigAttribute> createSingleAttributeList(String access) {
|
||||
return createList(access);
|
||||
}
|
||||
|
||||
public static List<ConfigAttribute> createList(String... attributeNames) {
|
||||
Assert.notNull(attributeNames, "You must supply an array of attribute names");
|
||||
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>(attributeNames.length);
|
||||
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.security.access.hierarchicalroles;
|
||||
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
|
||||
/**
|
||||
* This class wraps Spring Security's <tt>UserDetailsService</tt> in a way that its <tt>loadUserByUsername()</tt>
|
||||
* method returns wrapped <tt>UserDetails</tt> that return all hierarchically reachable authorities
|
||||
* instead of only the directly assigned authorities.
|
||||
*
|
||||
* @author Michael Mayr
|
||||
* @deprecated use a {@code RoleHierarchyVoter} or use a {@code RoleHierarchyAuthoritiesMapper} to populate the
|
||||
* Authentication object with the additional authorities.
|
||||
*/
|
||||
public class UserDetailsServiceWrapper implements UserDetailsService {
|
||||
|
||||
private UserDetailsService userDetailsService = null;
|
||||
|
||||
private RoleHierarchy roleHierarchy = null;
|
||||
|
||||
public void setRoleHierarchy(RoleHierarchy roleHierarchy) {
|
||||
this.roleHierarchy = roleHierarchy;
|
||||
}
|
||||
|
||||
public void setUserDetailsService(UserDetailsService userDetailsService) {
|
||||
this.userDetailsService = userDetailsService;
|
||||
}
|
||||
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
UserDetails userDetails = userDetailsService.loadUserByUsername(username);
|
||||
// wrapped UserDetailsService might throw UsernameNotFoundException or DataAccessException which will then bubble up
|
||||
return new UserDetailsWrapper(userDetails, roleHierarchy);
|
||||
}
|
||||
|
||||
public UserDetailsService getWrappedUserDetailsService() {
|
||||
return userDetailsService;
|
||||
}
|
||||
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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.security.access.hierarchicalroles;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.security.access.vote.RoleHierarchyVoter;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
/**
|
||||
* This class wraps Spring Security's <tt>UserDetails</tt> in a way that its <tt>getAuthorities()</tt> method is
|
||||
* delegated to <tt>RoleHierarchy.getReachableGrantedAuthorities</tt>. All other methods are
|
||||
* delegated to the <tt>UserDetails</tt> implementation.
|
||||
*
|
||||
* @author Michael Mayr
|
||||
* @deprecated use a {@link RoleHierarchyVoter} or {@code RoleHierarchyAuthoritiesMapper} instead.
|
||||
*/
|
||||
public class UserDetailsWrapper implements UserDetails {
|
||||
|
||||
private static final long serialVersionUID = 1532428778390085311L;
|
||||
|
||||
private UserDetails userDetails = null;
|
||||
|
||||
private RoleHierarchy roleHierarchy = null;
|
||||
|
||||
public UserDetailsWrapper(UserDetails userDetails, RoleHierarchy roleHierarchy) {
|
||||
this.userDetails = userDetails;
|
||||
this.roleHierarchy = roleHierarchy;
|
||||
}
|
||||
|
||||
public boolean isAccountNonExpired() {
|
||||
return userDetails.isAccountNonExpired();
|
||||
}
|
||||
|
||||
public boolean isAccountNonLocked() {
|
||||
return userDetails.isAccountNonLocked();
|
||||
}
|
||||
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return roleHierarchy.getReachableGrantedAuthorities(userDetails.getAuthorities());
|
||||
}
|
||||
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return userDetails.isCredentialsNonExpired();
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return userDetails.isEnabled();
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return userDetails.getPassword();
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return userDetails.getUsername();
|
||||
}
|
||||
|
||||
public UserDetails getUnwrappedUserDetails() {
|
||||
return userDetails;
|
||||
}
|
||||
|
||||
}
|
||||
-21
@@ -50,9 +50,6 @@ public abstract class AbstractAccessDecisionManager implements AccessDecisionMan
|
||||
|
||||
private boolean allowIfAllAbstainDecisions = false;
|
||||
|
||||
protected AbstractAccessDecisionManager() {
|
||||
}
|
||||
|
||||
protected AbstractAccessDecisionManager(List<AccessDecisionVoter<? extends Object>> decisionVoters) {
|
||||
Assert.notEmpty(decisionVoters, "A list of AccessDecisionVoters is required");
|
||||
this.decisionVoters = decisionVoters;
|
||||
@@ -84,24 +81,6 @@ public abstract class AbstractAccessDecisionManager implements AccessDecisionMan
|
||||
this.allowIfAllAbstainDecisions = allowIfAllAbstainDecisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor
|
||||
*/
|
||||
@Deprecated
|
||||
public void setDecisionVoters(List<AccessDecisionVoter<? extends Object>> newList) {
|
||||
Assert.notEmpty(newList);
|
||||
|
||||
Iterator<AccessDecisionVoter<? extends Object>> iter = newList.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
Object currentObject = iter.next();
|
||||
Assert.isInstanceOf(AccessDecisionVoter.class, currentObject, "AccessDecisionVoter " +
|
||||
currentObject.getClass().getName() + " must implement AccessDecisionVoter");
|
||||
}
|
||||
|
||||
this.decisionVoters = newList;
|
||||
}
|
||||
|
||||
public void setMessageSource(MessageSource messageSource) {
|
||||
this.messages = new MessageSourceAccessor(messageSource);
|
||||
}
|
||||
|
||||
@@ -29,13 +29,6 @@ import org.springframework.security.core.Authentication;
|
||||
*/
|
||||
public class AffirmativeBased extends AbstractAccessDecisionManager {
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor which takes voter list
|
||||
*/
|
||||
@Deprecated
|
||||
public AffirmativeBased() {
|
||||
}
|
||||
|
||||
public AffirmativeBased(List<AccessDecisionVoter<? extends Object>> decisionVoters) {
|
||||
super(decisionVoters);
|
||||
}
|
||||
|
||||
@@ -34,13 +34,6 @@ public class ConsensusBased extends AbstractAccessDecisionManager {
|
||||
|
||||
private boolean allowIfEqualGrantedDeniedDecisions = true;
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor which takes voter list
|
||||
*/
|
||||
@Deprecated
|
||||
public ConsensusBased() {
|
||||
}
|
||||
|
||||
public ConsensusBased(List<AccessDecisionVoter<? extends Object>> decisionVoters) {
|
||||
super(decisionVoters);
|
||||
}
|
||||
|
||||
@@ -31,13 +31,6 @@ import org.springframework.security.core.Authentication;
|
||||
*/
|
||||
public class UnanimousBased extends AbstractAccessDecisionManager {
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor which takes voter list
|
||||
*/
|
||||
@Deprecated
|
||||
public UnanimousBased() {
|
||||
}
|
||||
|
||||
public UnanimousBased(List<AccessDecisionVoter<? extends Object>> decisionVoters) {
|
||||
super(decisionVoters);
|
||||
}
|
||||
|
||||
-5
@@ -44,9 +44,4 @@ public class AccountExpiredException extends AccountStatusException {
|
||||
public AccountExpiredException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public AccountExpiredException(String msg, Object extraInformation) {
|
||||
super(msg, extraInformation);
|
||||
}
|
||||
}
|
||||
|
||||
-5
@@ -16,9 +16,4 @@ public abstract class AccountStatusException extends AuthenticationException {
|
||||
public AccountStatusException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected AccountStatusException(String msg, Object extraInformation) {
|
||||
super(msg, extraInformation);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -14,21 +14,21 @@ public class AccountStatusUserDetailsChecker implements UserDetailsChecker {
|
||||
|
||||
public void check(UserDetails user) {
|
||||
if (!user.isAccountNonLocked()) {
|
||||
throw new LockedException(messages.getMessage("AccountStatusUserDetailsChecker.locked", "User account is locked"), user);
|
||||
throw new LockedException(messages.getMessage("AccountStatusUserDetailsChecker.locked", "User account is locked"));
|
||||
}
|
||||
|
||||
if (!user.isEnabled()) {
|
||||
throw new DisabledException(messages.getMessage("AccountStatusUserDetailsChecker.disabled", "User is disabled"), user);
|
||||
throw new DisabledException(messages.getMessage("AccountStatusUserDetailsChecker.disabled", "User is disabled"));
|
||||
}
|
||||
|
||||
if (!user.isAccountNonExpired()) {
|
||||
throw new AccountExpiredException(messages.getMessage("AccountStatusUserDetailsChecker.expired",
|
||||
"User account has expired"), user);
|
||||
"User account has expired"));
|
||||
}
|
||||
|
||||
if (!user.isCredentialsNonExpired()) {
|
||||
throw new CredentialsExpiredException(messages.getMessage("AccountStatusUserDetailsChecker.credentialsExpired",
|
||||
"User credentials have expired"), user);
|
||||
"User credentials have expired"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-22
@@ -33,31 +33,20 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Ben Alex
|
||||
*/
|
||||
public class AnonymousAuthenticationProvider implements AuthenticationProvider, InitializingBean, MessageSourceAware {
|
||||
public class AnonymousAuthenticationProvider implements AuthenticationProvider, MessageSourceAware {
|
||||
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
protected MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor();
|
||||
private String key;
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated Use constructor injection
|
||||
*/
|
||||
@Deprecated
|
||||
public AnonymousAuthenticationProvider() {
|
||||
}
|
||||
|
||||
public AnonymousAuthenticationProvider(String key) {
|
||||
Assert.hasLength(key, "A Key is required");
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.hasLength(key, "A Key is required");
|
||||
}
|
||||
|
||||
public Authentication authenticate(Authentication authentication)
|
||||
throws AuthenticationException {
|
||||
if (!supports(authentication.getClass())) {
|
||||
@@ -76,15 +65,6 @@ public class AnonymousAuthenticationProvider implements AuthenticationProvider,
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated Use constructor injection
|
||||
*/
|
||||
@Deprecated
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void setMessageSource(MessageSource messageSource) {
|
||||
Assert.notNull(messageSource, "messageSource cannot be null");
|
||||
this.messages = new MessageSourceAccessor(messageSource);
|
||||
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
package org.springframework.security.authentication;
|
||||
|
||||
import org.springframework.security.core.SpringSecurityCoreVersion;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A holder of the context as a string.
|
||||
*
|
||||
* @author Ruud Senden
|
||||
* @since 2.0
|
||||
*/
|
||||
@Deprecated
|
||||
public class AuthenticationDetails implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
||||
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private final String context;
|
||||
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param context that the authentication request is initiated from
|
||||
*/
|
||||
public AuthenticationDetails(Object context) {
|
||||
this.context = context == null ? "" : context.toString();
|
||||
doPopulateAdditionalInformation(context);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
* Provided so that subclasses can populate additional information.
|
||||
*
|
||||
* @param context the existing contextual information
|
||||
*/
|
||||
protected void doPopulateAdditionalInformation(Object context) {}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof AuthenticationDetails) {
|
||||
AuthenticationDetails rhs = (AuthenticationDetails) obj;
|
||||
|
||||
// this.context cannot be null
|
||||
if (!context.equals(rhs.getContext())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the context.
|
||||
*
|
||||
* @return the context
|
||||
*/
|
||||
public String getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString() + ": ");
|
||||
sb.append("Context: " + this.getContext());
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
package org.springframework.security.authentication;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
* Base implementation of {@link AuthenticationDetailsSource}.
|
||||
* <p>
|
||||
* By default will create an instance of <code>AuthenticationDetails</code>.
|
||||
* Any object that accepts an <code>Object</code> as its sole constructor can
|
||||
* be used instead of this default.
|
||||
* </p>
|
||||
*
|
||||
* @author Ruud Senden
|
||||
* @since 2.0
|
||||
* @deprecated Write an implementation of AuthenticationDetailsSource which returns the desired type directly.
|
||||
*/
|
||||
@Deprecated
|
||||
public class AuthenticationDetailsSourceImpl implements AuthenticationDetailsSource<Object, Object> {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private Class<?> clazz = AuthenticationDetails.class;
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public Object buildDetails(Object context) {
|
||||
Object result = null;
|
||||
try {
|
||||
Constructor<?> constructor = getFirstMatchingConstructor(context);
|
||||
result = constructor.newInstance(context);
|
||||
} catch (Exception ex) {
|
||||
ReflectionUtils.handleReflectionException(ex);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first matching constructor that can take the given object
|
||||
* as an argument. Please note that we cannot use
|
||||
* getDeclaredConstructor(new Class[]{object.getClass()})
|
||||
* as this will only match if the constructor argument type matches
|
||||
* the object type exactly (instead of checking whether it is assignable)
|
||||
*
|
||||
* @param object the object for which to find a matching constructor
|
||||
* @return a matching constructor for the given object
|
||||
* @throws NoSuchMethodException if no matching constructor can be found
|
||||
*/
|
||||
private Constructor<?> getFirstMatchingConstructor(Object object) throws NoSuchMethodException {
|
||||
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
|
||||
Constructor<?> constructor = null;
|
||||
for (Constructor<?> tryMe : constructors) {
|
||||
Class<?>[] parameterTypes = tryMe.getParameterTypes();
|
||||
if (parameterTypes.length == 1 && (object == null || parameterTypes[0].isInstance(object))) {
|
||||
constructor = tryMe;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (constructor == null) {
|
||||
if (object == null) {
|
||||
throw new NoSuchMethodException("No constructor found that can take a single argument");
|
||||
} else {
|
||||
throw new NoSuchMethodException("No constructor found that can take a single argument of type " + object.getClass());
|
||||
}
|
||||
}
|
||||
return constructor;
|
||||
}
|
||||
|
||||
public void setClazz(Class<?> clazz) {
|
||||
Assert.notNull(clazz, "Class required");
|
||||
this.clazz = clazz;
|
||||
}
|
||||
}
|
||||
-5
@@ -36,11 +36,6 @@ public class BadCredentialsException extends AuthenticationException {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BadCredentialsException(String msg, Object extraInformation) {
|
||||
super(msg, extraInformation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>BadCredentialsException</code> with the specified
|
||||
* message and root cause.
|
||||
|
||||
-5
@@ -44,9 +44,4 @@ public class CredentialsExpiredException extends AccountStatusException {
|
||||
public CredentialsExpiredException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CredentialsExpiredException(String msg, Object extraInformation) {
|
||||
super(msg, extraInformation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,9 +43,4 @@ public class DisabledException extends AccountStatusException {
|
||||
public DisabledException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public DisabledException(String msg, Object extraInformation) {
|
||||
super(msg, extraInformation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,9 +44,4 @@ public class LockedException extends AccountStatusException {
|
||||
public LockedException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public LockedException(String msg, Object extraInformation) {
|
||||
super(msg, extraInformation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,14 +86,6 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
|
||||
protected MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor();
|
||||
private AuthenticationManager parent;
|
||||
private boolean eraseCredentialsAfterAuthentication = true;
|
||||
private boolean clearExtraInformation = false;
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor which takes provider list
|
||||
*/
|
||||
@Deprecated
|
||||
public ProviderManager() {
|
||||
}
|
||||
|
||||
public ProviderManager(List<AuthenticationProvider> providers) {
|
||||
this(providers, null);
|
||||
@@ -208,11 +200,6 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
|
||||
@SuppressWarnings("deprecation")
|
||||
private void prepareException(AuthenticationException ex, Authentication auth) {
|
||||
eventPublisher.publishAuthenticationFailure(ex, auth);
|
||||
ex.setAuthentication(auth);
|
||||
|
||||
if (clearExtraInformation) {
|
||||
ex.clearExtraInformation();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,14 +225,6 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
|
||||
this.messages = new MessageSourceAccessor(messageSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor injection
|
||||
*/
|
||||
@Deprecated
|
||||
public void setParent(AuthenticationManager parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void setAuthenticationEventPublisher(AuthenticationEventPublisher eventPublisher) {
|
||||
Assert.notNull(eventPublisher, "AuthenticationEventPublisher cannot be null");
|
||||
this.eventPublisher = eventPublisher;
|
||||
@@ -267,39 +246,6 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
|
||||
return eraseCredentialsAfterAuthentication;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link AuthenticationProvider} objects to be used for authentication.
|
||||
*
|
||||
* @param providers the list of authentication providers which will be used to process authentication requests.
|
||||
*
|
||||
* @throws IllegalArgumentException if the list is empty or null, or any of the elements in the list is not an
|
||||
* AuthenticationProvider instance.
|
||||
* @deprecated Use constructor injection
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void setProviders(List providers) {
|
||||
Assert.notNull(providers, "Providers list cannot be null");
|
||||
for(Object currentObject : providers) {
|
||||
Assert.isInstanceOf(AuthenticationProvider.class, currentObject, "Can only provide AuthenticationProvider instances");
|
||||
}
|
||||
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to true, the {@code extraInformation} set on an {@code AuthenticationException} will be cleared
|
||||
* before rethrowing it. This is useful for use with remoting protocols where the information shouldn't
|
||||
* be serialized to the client. Defaults to 'false'.
|
||||
*
|
||||
* @see org.springframework.security.core.AuthenticationException#getExtraInformation()
|
||||
* @deprecated the {@code extraInformation} property is deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public void setClearExtraInformation(boolean clearExtraInformation) {
|
||||
this.clearExtraInformation = clearExtraInformation;
|
||||
}
|
||||
|
||||
private static final class NullEventPublisher implements AuthenticationEventPublisher {
|
||||
public void publishAuthenticationFailure(AuthenticationException exception, Authentication authentication) {}
|
||||
public void publishAuthenticationSuccess(Authentication authentication) {}
|
||||
|
||||
+1
-16
@@ -37,21 +37,15 @@ public class RememberMeAuthenticationProvider implements AuthenticationProvider,
|
||||
protected MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor();
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* @deprecated Use constructor injection
|
||||
*/
|
||||
@Deprecated
|
||||
public RememberMeAuthenticationProvider() {
|
||||
}
|
||||
|
||||
public RememberMeAuthenticationProvider(String key) {
|
||||
Assert.hasLength(key);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.hasLength(key);
|
||||
Assert.notNull(this.messages, "A message source must be set");
|
||||
}
|
||||
|
||||
@@ -72,15 +66,6 @@ public class RememberMeAuthenticationProvider implements AuthenticationProvider,
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated Use constructor injection
|
||||
*/
|
||||
@Deprecated
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void setMessageSource(MessageSource messageSource) {
|
||||
this.messages = new MessageSourceAccessor(messageSource);
|
||||
}
|
||||
|
||||
+4
-4
@@ -308,21 +308,21 @@ public abstract class AbstractUserDetailsAuthenticationProvider implements Authe
|
||||
logger.debug("User account is locked");
|
||||
|
||||
throw new LockedException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.locked",
|
||||
"User account is locked"), user);
|
||||
"User account is locked"));
|
||||
}
|
||||
|
||||
if (!user.isEnabled()) {
|
||||
logger.debug("User account is disabled");
|
||||
|
||||
throw new DisabledException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled",
|
||||
"User is disabled"), user);
|
||||
"User is disabled"));
|
||||
}
|
||||
|
||||
if (!user.isAccountNonExpired()) {
|
||||
logger.debug("User account is expired");
|
||||
|
||||
throw new AccountExpiredException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.expired",
|
||||
"User account has expired"), user);
|
||||
"User account has expired"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,7 +334,7 @@ public abstract class AbstractUserDetailsAuthenticationProvider implements Authe
|
||||
|
||||
throw new CredentialsExpiredException(messages.getMessage(
|
||||
"AbstractUserDetailsAuthenticationProvider.credentialsExpired",
|
||||
"User credentials have expired"), user);
|
||||
"User credentials have expired"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -77,7 +77,7 @@ public class DaoAuthenticationProvider extends AbstractUserDetailsAuthentication
|
||||
logger.debug("Authentication failed: no credentials provided");
|
||||
|
||||
throw new BadCredentialsException(messages.getMessage(
|
||||
"AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), userDetails);
|
||||
"AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
|
||||
}
|
||||
|
||||
String presentedPassword = authentication.getCredentials().toString();
|
||||
@@ -86,7 +86,7 @@ public class DaoAuthenticationProvider extends AbstractUserDetailsAuthentication
|
||||
logger.debug("Authentication failed: password does not match stored value");
|
||||
|
||||
throw new BadCredentialsException(messages.getMessage(
|
||||
"AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), userDetails);
|
||||
"AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -32,7 +32,6 @@ import java.util.List;
|
||||
public final class DelegatingApplicationListener implements ApplicationListener<ApplicationEvent> {
|
||||
private List<SmartApplicationListener> listeners = new ArrayList<SmartApplicationListener>();
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if(event == null) {
|
||||
return;
|
||||
|
||||
@@ -22,10 +22,6 @@ package org.springframework.security.core;
|
||||
* @author Ben Alex
|
||||
*/
|
||||
public abstract class AuthenticationException extends RuntimeException {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private Authentication authentication;
|
||||
private transient Object extraInformation;
|
||||
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
@@ -48,47 +44,4 @@ public abstract class AuthenticationException extends RuntimeException {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use the exception message or use a custom exception if you really need additional information.
|
||||
*/
|
||||
@Deprecated
|
||||
public AuthenticationException(String msg, Object extraInformation) {
|
||||
super(msg);
|
||||
if (extraInformation instanceof CredentialsContainer) {
|
||||
((CredentialsContainer) extraInformation).eraseCredentials();
|
||||
}
|
||||
this.extraInformation = extraInformation;
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
* The authentication request which this exception corresponds to (may be {@code null})
|
||||
* @deprecated to avoid potential leaking of sensitive information (e.g. through serialization/remoting).
|
||||
*/
|
||||
@Deprecated
|
||||
public Authentication getAuthentication() {
|
||||
return authentication;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setAuthentication(Authentication authentication) {
|
||||
this.authentication = authentication;
|
||||
}
|
||||
|
||||
/**
|
||||
* Any additional information about the exception. Generally a {@code UserDetails} object.
|
||||
*
|
||||
* @return extra information or {@code null}
|
||||
* @deprecated Use the exception message or use a custom exception if you really need additional information.
|
||||
*/
|
||||
@Deprecated
|
||||
public Object getExtraInformation() {
|
||||
return extraInformation;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void clearExtraInformation() {
|
||||
this.extraInformation = null;
|
||||
}
|
||||
}
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package org.springframework.security.core.authority;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.SpringSecurityCoreVersion;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@Deprecated
|
||||
public class GrantedAuthoritiesContainerImpl implements MutableGrantedAuthoritiesContainer {
|
||||
|
||||
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
||||
|
||||
private List<GrantedAuthority> authorities;
|
||||
|
||||
public void setGrantedAuthorities(Collection<? extends GrantedAuthority> newAuthorities) {
|
||||
ArrayList<GrantedAuthority> temp = new ArrayList<GrantedAuthority>(newAuthorities.size());
|
||||
temp.addAll(newAuthorities);
|
||||
authorities = Collections.unmodifiableList(temp);
|
||||
}
|
||||
|
||||
public List<GrantedAuthority> getGrantedAuthorities() {
|
||||
Assert.notNull(authorities, "Granted authorities have not been set");
|
||||
return authorities;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Authorities: ").append(authorities);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* 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.security.core.authority;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.SpringSecurityCoreVersion;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* Basic concrete implementation of a {@link GrantedAuthority}.
|
||||
*
|
||||
* <p>
|
||||
* Stores a <code>String</code> representation of an authority granted to the {@link Authentication} object.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @deprecated Use the final class {@link SimpleGrantedAuthority} or implement your own.
|
||||
*/
|
||||
@Deprecated
|
||||
public class GrantedAuthorityImpl implements GrantedAuthority {
|
||||
|
||||
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
||||
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private final String role;
|
||||
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public GrantedAuthorityImpl(String role) {
|
||||
Assert.hasText(role, "A granted authority textual representation is required");
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof String) {
|
||||
return obj.equals(this.role);
|
||||
}
|
||||
|
||||
if (obj instanceof GrantedAuthority) {
|
||||
GrantedAuthority attr = (GrantedAuthority) obj;
|
||||
|
||||
return this.role.equals(attr.getAuthority());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getAuthority() {
|
||||
return this.role;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.role.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.role;
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package org.springframework.security.core.authority;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Indicates that a object can be used to store and retrieve GrantedAuthority objects.
|
||||
* <p>
|
||||
* Typically used in a pre-authenticated scenario when an AuthenticationDetails instance may also be
|
||||
* used to obtain user authorities.
|
||||
*
|
||||
* @author Ruud Senden
|
||||
* @author Luke Taylor
|
||||
* @since 2.0
|
||||
*/
|
||||
@Deprecated
|
||||
public interface MutableGrantedAuthoritiesContainer extends GrantedAuthoritiesContainer {
|
||||
/**
|
||||
* Used to store authorities in the containing object.
|
||||
*/
|
||||
void setGrantedAuthorities(Collection<? extends GrantedAuthority> authorities);
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* 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.security.core.session;
|
||||
|
||||
/**
|
||||
* Implemented by {@link org.springframework.security.core.Authentication#getDetails()}
|
||||
* implementations that are capable of returning a session ID.
|
||||
* <p>
|
||||
* Used to extract the session ID from an <code>Authentication</code> object.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @deprecated Legacy of former concurrency control implementation. Will be removed in a future version.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface SessionIdentifierAware {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
* Obtains the session ID.
|
||||
*
|
||||
* @return the session ID, or <code>null</code> if not known.
|
||||
*/
|
||||
String getSessionId();
|
||||
}
|
||||
-12
@@ -36,18 +36,6 @@ public class UsernameNotFoundException extends AuthenticationException {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code UsernameNotFoundException}, making use of the {@code extraInformation}
|
||||
* property of the superclass.
|
||||
*
|
||||
* @param msg the detail message
|
||||
* @param extraInformation additional information such as the username.
|
||||
*/
|
||||
@Deprecated
|
||||
public UsernameNotFoundException(String msg, Object extraInformation) {
|
||||
super(msg, extraInformation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code UsernameNotFoundException} with the specified message and root cause.
|
||||
*
|
||||
|
||||
+2
-2
@@ -154,7 +154,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService {
|
||||
logger.debug("Query returned no results for user '" + username + "'");
|
||||
|
||||
throw new UsernameNotFoundException(
|
||||
messages.getMessage("JdbcDaoImpl.notFound", new Object[]{username}, "Username {0} not found"), username);
|
||||
messages.getMessage("JdbcDaoImpl.notFound", new Object[]{username}, "Username {0} not found"));
|
||||
}
|
||||
|
||||
UserDetails user = users.get(0); // contains no GrantedAuthority[]
|
||||
@@ -178,7 +178,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService {
|
||||
|
||||
throw new UsernameNotFoundException(
|
||||
messages.getMessage("JdbcDaoImpl.noAuthority",
|
||||
new Object[] {username}, "User {0} has no GrantedAuthority"), username);
|
||||
new Object[] {username}, "User {0} has no GrantedAuthority"));
|
||||
}
|
||||
|
||||
return createUserDetails(username, user, dbAuths);
|
||||
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* 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.security.core.userdetails.memory;
|
||||
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves user details from an in-memory list created by the bean context.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @deprecated Use InMemoryUserDetailsManager instead (or write your own implementation)
|
||||
*/
|
||||
@Deprecated
|
||||
public class InMemoryDaoImpl implements UserDetailsService, InitializingBean {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private UserMap userMap;
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(this.userMap,
|
||||
"A list of users, passwords, enabled/disabled status and their granted authorities must be set");
|
||||
}
|
||||
|
||||
public UserMap getUserMap() {
|
||||
return userMap;
|
||||
}
|
||||
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
return userMap.getUser(username);
|
||||
}
|
||||
|
||||
public void setUserMap(UserMap userMap) {
|
||||
this.userMap = userMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the internal <code>UserMap</code> to reflect the <code>Properties</code> instance passed. This
|
||||
* helps externalise user information to another file etc.
|
||||
*
|
||||
* @param props the account information in a <code>Properties</code> object format
|
||||
*/
|
||||
public void setUserProperties(Properties props) {
|
||||
UserMap userMap = new UserMap();
|
||||
this.userMap = UserMapEditor.addUsersFromProperties(userMap, props);
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* 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.security.core.userdetails.memory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* Used by {@link InMemoryDaoImpl} to store a list of users and their corresponding granted authorities.
|
||||
* <p>
|
||||
* Usernames are used as the lookup key and are stored in lower case, to allow case-insensitive lookups. So this class
|
||||
* should not be used if usernames need to be case-sensitive.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @deprecated Use a plain map instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class UserMap {
|
||||
//~ Static fields/initializers =====================================================================================
|
||||
|
||||
private static final Log logger = LogFactory.getLog(UserMap.class);
|
||||
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private final Map<String, UserDetails> userMap = new HashMap<String, UserDetails>();
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
* Adds a user to the in-memory map.
|
||||
*
|
||||
* @param user the user to be stored
|
||||
*
|
||||
* @throws IllegalArgumentException if a null User was passed
|
||||
*/
|
||||
public void addUser(UserDetails user) throws IllegalArgumentException {
|
||||
Assert.notNull(user, "Must be a valid User");
|
||||
|
||||
logger.info("Adding user [" + user + "]");
|
||||
this.userMap.put(user.getUsername().toLowerCase(), user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates the specified user by performing a case insensitive search by username.
|
||||
*
|
||||
* @param username to find
|
||||
*
|
||||
* @return the located user
|
||||
*
|
||||
* @throws UsernameNotFoundException if the user could not be found
|
||||
*/
|
||||
public UserDetails getUser(String username) throws UsernameNotFoundException {
|
||||
UserDetails result = this.userMap.get(username.toLowerCase());
|
||||
|
||||
if (result == null) {
|
||||
throw new UsernameNotFoundException("Could not find user: " + username, username);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the size of the user map.
|
||||
*
|
||||
* @return the number of users in the map
|
||||
*/
|
||||
public int getUserCount() {
|
||||
return this.userMap.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the users in this {@link UserMap}. Overrides previously added users.
|
||||
*
|
||||
* @param users {@link Map} <{@link String}, {@link UserDetails}> with pairs (username, userdetails)
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setUsers(Map<String, UserDetails> users) {
|
||||
userMap.clear();
|
||||
for (Map.Entry<String, UserDetails> entry : users.entrySet()) {
|
||||
userMap.put(entry.getKey().toLowerCase(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* 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.security.core.userdetails.memory;
|
||||
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import org.springframework.beans.propertyeditors.PropertiesEditor;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
/**
|
||||
* Property editor to assist with the setup of a {@link UserMap}.<p>The format of entries should be:</p>
|
||||
* <p><code> username=password,grantedAuthority[,grantedAuthority][,enabled|disabled] </code></p>
|
||||
* <p>The <code>password</code> must always be the first entry after the equals. The <code>enabled</code> or
|
||||
* <code>disabled</code> keyword can appear anywhere (apart from the first entry reserved for the password). If
|
||||
* neither <code>enabled</code> or <code>disabled</code> appear, the default is <code>enabled</code>. At least one
|
||||
* granted authority must be listed.</p>
|
||||
* <p>The <code>username</code> represents the key and duplicates are handled the same was as duplicates would be
|
||||
* in Java <code>Properties</code> files.</p>
|
||||
* <p>If the above requirements are not met, the invalid entry will be silently ignored.</p>
|
||||
* <p>This editor always assumes each entry has a non-expired account and non-expired credentials. However, it
|
||||
* does honour the user enabled/disabled flag as described above.</p>
|
||||
*
|
||||
* @author Ben Alex
|
||||
*/
|
||||
@Deprecated
|
||||
public class UserMapEditor extends PropertyEditorSupport {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public static UserMap addUsersFromProperties(UserMap userMap, Properties props) {
|
||||
// Now we have properties, process each one individually
|
||||
UserAttributeEditor configAttribEd = new UserAttributeEditor();
|
||||
|
||||
for (Object o : props.keySet()) {
|
||||
String username = (String) o;
|
||||
String value = props.getProperty(username);
|
||||
|
||||
// Convert value to a password, enabled setting, and list of granted authorities
|
||||
configAttribEd.setAsText(value);
|
||||
|
||||
UserAttribute attr = (UserAttribute) configAttribEd.getValue();
|
||||
|
||||
// Make a user object, assuming the properties were properly provided
|
||||
if (attr != null) {
|
||||
UserDetails user = new User(username, attr.getPassword(), attr.isEnabled(), true, true, true,
|
||||
attr.getAuthorities());
|
||||
userMap.addUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
return userMap;
|
||||
}
|
||||
|
||||
public void setAsText(String s) throws IllegalArgumentException {
|
||||
UserMap userMap = new UserMap();
|
||||
|
||||
if ((s == null) || "".equals(s)) {
|
||||
// Leave value in property editor null
|
||||
} else {
|
||||
// Use properties editor to tokenize the string
|
||||
PropertiesEditor propertiesEditor = new PropertiesEditor();
|
||||
propertiesEditor.setAsText(s);
|
||||
|
||||
Properties props = (Properties) propertiesEditor.getValue();
|
||||
addUsersFromProperties(userMap, props);
|
||||
}
|
||||
|
||||
setValue(userMap);
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
package org.springframework.security.access.hierarchicalroles;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class UserDetailsServiceWrapperTests {
|
||||
|
||||
private UserDetailsService wrappedUserDetailsService = null;
|
||||
private UserDetailsServiceWrapper userDetailsServiceWrapper = null;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
|
||||
roleHierarchy.setHierarchy("ROLE_A > ROLE_B");
|
||||
final UserDetails user = new User("EXISTING_USER", "PASSWORD", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_A"));
|
||||
final UserDetailsService wrappedUserDetailsService = mock(UserDetailsService.class);
|
||||
when(wrappedUserDetailsService.loadUserByUsername("EXISTING_USER")).thenReturn(user);
|
||||
when(wrappedUserDetailsService.loadUserByUsername("USERNAME_NOT_FOUND_EXCEPTION")).thenThrow(new UsernameNotFoundException("USERNAME_NOT_FOUND_EXCEPTION"));
|
||||
|
||||
this.wrappedUserDetailsService = wrappedUserDetailsService;
|
||||
userDetailsServiceWrapper = new UserDetailsServiceWrapper();
|
||||
userDetailsServiceWrapper.setRoleHierarchy(roleHierarchy);
|
||||
userDetailsServiceWrapper.setUserDetailsService(wrappedUserDetailsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadUserByUsername() {
|
||||
UserDetails expectedUserDetails = new User("EXISTING_USER", "PASSWORD", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B"));
|
||||
UserDetails userDetails = userDetailsServiceWrapper.loadUserByUsername("EXISTING_USER");
|
||||
assertEquals(expectedUserDetails.getPassword(), userDetails.getPassword());
|
||||
assertEquals(expectedUserDetails.getUsername(), userDetails.getUsername());
|
||||
assertEquals(expectedUserDetails.isAccountNonExpired(), userDetails.isAccountNonExpired());
|
||||
assertEquals(expectedUserDetails.isAccountNonLocked(), userDetails.isAccountNonLocked());
|
||||
assertEquals(expectedUserDetails.isCredentialsNonExpired(), expectedUserDetails.isCredentialsNonExpired());
|
||||
assertEquals(expectedUserDetails.isEnabled(), userDetails.isEnabled());
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(expectedUserDetails.getAuthorities(), userDetails.getAuthorities()));
|
||||
|
||||
try {
|
||||
userDetails = userDetailsServiceWrapper.loadUserByUsername("USERNAME_NOT_FOUND_EXCEPTION");
|
||||
fail("testLoadUserByUsername() - UsernameNotFoundException did not bubble up!");
|
||||
} catch (UsernameNotFoundException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWrappedUserDetailsService() {
|
||||
assertTrue(userDetailsServiceWrapper.getWrappedUserDetailsService() == wrappedUserDetailsService);
|
||||
}
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
package org.springframework.security.access.hierarchicalroles;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link UserDetailsWrapper}.
|
||||
*
|
||||
* @author Michael Mayr
|
||||
*/
|
||||
@SuppressWarnings({"deprecation"})
|
||||
public class UserDetailsWrapperTests extends TestCase {
|
||||
|
||||
private List<GrantedAuthority> authorities = null;
|
||||
private UserDetails userDetails1 = null;
|
||||
private UserDetails userDetails2 = null;
|
||||
private UserDetailsWrapper userDetailsWrapper1 = null;
|
||||
private UserDetailsWrapper userDetailsWrapper2 = null;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
|
||||
roleHierarchy.setHierarchy("ROLE_A > ROLE_B");
|
||||
authorities = AuthorityUtils.createAuthorityList("ROLE_A");
|
||||
userDetails1 = new User("TestUser1", "TestPassword1", true, true, true, true, authorities);
|
||||
userDetails2 = new User("TestUser2", "TestPassword2", false, false, false, false, authorities);
|
||||
userDetailsWrapper1 = new UserDetailsWrapper(userDetails1, roleHierarchy);
|
||||
userDetailsWrapper2 = new UserDetailsWrapper(userDetails2, roleHierarchy);
|
||||
}
|
||||
|
||||
public void testIsAccountNonExpired() {
|
||||
assertEquals(userDetails1.isAccountNonExpired(), userDetailsWrapper1.isAccountNonExpired());
|
||||
assertEquals(userDetails2.isAccountNonExpired(), userDetailsWrapper2.isAccountNonExpired());
|
||||
}
|
||||
|
||||
public void testIsAccountNonLocked() {
|
||||
assertEquals(userDetails1.isAccountNonLocked(), userDetailsWrapper1.isAccountNonLocked());
|
||||
assertEquals(userDetails2.isAccountNonLocked(), userDetailsWrapper2.isAccountNonLocked());
|
||||
}
|
||||
|
||||
public void testGetAuthorities() {
|
||||
List<GrantedAuthority> expectedAuthorities = AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B");
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(userDetailsWrapper1.getAuthorities(), expectedAuthorities));
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(userDetailsWrapper2.getAuthorities(), expectedAuthorities));
|
||||
}
|
||||
|
||||
public void testIsCredentialsNonExpired() {
|
||||
assertEquals(userDetails1.isCredentialsNonExpired(), userDetailsWrapper1.isCredentialsNonExpired());
|
||||
assertEquals(userDetails2.isCredentialsNonExpired(), userDetailsWrapper2.isCredentialsNonExpired());
|
||||
}
|
||||
|
||||
public void testIsEnabled() {
|
||||
assertEquals(userDetails1.isEnabled(), userDetailsWrapper1.isEnabled());
|
||||
assertEquals(userDetails2.isEnabled(), userDetailsWrapper2.isEnabled());
|
||||
}
|
||||
|
||||
public void testGetPassword() {
|
||||
assertEquals(userDetails1.getPassword(), userDetailsWrapper1.getPassword());
|
||||
assertEquals(userDetails2.getPassword(), userDetailsWrapper2.getPassword());
|
||||
}
|
||||
|
||||
public void testGetUsername() {
|
||||
assertEquals(userDetails1.getUsername(), userDetailsWrapper1.getUsername());
|
||||
assertEquals(userDetails2.getUsername(), userDetailsWrapper2.getUsername());
|
||||
}
|
||||
|
||||
public void testGetUnwrappedUserDetails() {
|
||||
assertTrue(userDetailsWrapper1.getUnwrappedUserDetails() == userDetails1);
|
||||
assertTrue(userDetailsWrapper2.getUnwrappedUserDetails() == userDetails2);
|
||||
}
|
||||
|
||||
}
|
||||
+16
-33
@@ -41,31 +41,34 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void testAllowIfAccessDecisionManagerDefaults() {
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl();
|
||||
List list = new Vector();
|
||||
DenyAgainVoter denyVoter = new DenyAgainVoter();
|
||||
list.add(denyVoter);
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl(list);
|
||||
assertTrue(!mock.isAllowIfAllAbstainDecisions()); // default
|
||||
mock.setAllowIfAllAbstainDecisions(true);
|
||||
assertTrue(mock.isAllowIfAllAbstainDecisions()); // changed
|
||||
}
|
||||
|
||||
public void testDelegatesSupportsClassRequests() throws Exception {
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl();
|
||||
List list = new Vector();
|
||||
list.add(new DenyVoter());
|
||||
list.add(new MockStringOnlyVoter());
|
||||
mock.setDecisionVoters(list);
|
||||
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl(list);
|
||||
|
||||
assertTrue(mock.supports(String.class));
|
||||
assertTrue(!mock.supports(Integer.class));
|
||||
}
|
||||
|
||||
public void testDelegatesSupportsRequests() throws Exception {
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl();
|
||||
List list = new Vector();
|
||||
DenyVoter voter = new DenyVoter();
|
||||
DenyAgainVoter denyVoter = new DenyAgainVoter();
|
||||
list.add(voter);
|
||||
list.add(denyVoter);
|
||||
mock.setDecisionVoters(list);
|
||||
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl(list);
|
||||
|
||||
ConfigAttribute attr = new SecurityConfig("DENY_AGAIN_FOR_SURE");
|
||||
assertTrue(mock.supports(attr));
|
||||
@@ -75,40 +78,20 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testProperlyStoresListOfVoters() throws Exception {
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl();
|
||||
List list = new Vector();
|
||||
DenyVoter voter = new DenyVoter();
|
||||
DenyAgainVoter denyVoter = new DenyAgainVoter();
|
||||
list.add(voter);
|
||||
list.add(denyVoter);
|
||||
mock.setDecisionVoters(list);
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl(list);
|
||||
assertEquals(list.size(), mock.getDecisionVoters().size());
|
||||
}
|
||||
|
||||
public void testRejectsEmptyList() throws Exception {
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl();
|
||||
List list = new Vector();
|
||||
|
||||
try {
|
||||
mock.setDecisionVoters(list);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testRejectsListContainingInvalidObjectTypes() {
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl();
|
||||
List list = new Vector();
|
||||
DenyVoter voter = new DenyVoter();
|
||||
DenyAgainVoter denyVoter = new DenyAgainVoter();
|
||||
String notAVoter = "NOT_A_VOTER";
|
||||
list.add(voter);
|
||||
list.add(notAVoter);
|
||||
list.add(denyVoter);
|
||||
|
||||
try {
|
||||
mock.setDecisionVoters(list);
|
||||
new MockDecisionManagerImpl(list);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
@@ -116,10 +99,8 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testRejectsNullVotersList() throws Exception {
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl();
|
||||
|
||||
try {
|
||||
mock.setDecisionVoters(null);
|
||||
new MockDecisionManagerImpl(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
@@ -133,10 +114,8 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
|
||||
public void testWillNotStartIfDecisionVotersNotSet()
|
||||
throws Exception {
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl();
|
||||
|
||||
try {
|
||||
mock.afterPropertiesSet();
|
||||
new MockDecisionManagerImpl(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
@@ -146,6 +125,10 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
private class MockDecisionManagerImpl extends AbstractAccessDecisionManager {
|
||||
protected MockDecisionManagerImpl(List<AccessDecisionVoter<? extends Object>> decisionVoters) {
|
||||
super(decisionVoters);
|
||||
}
|
||||
|
||||
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) {
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -48,7 +48,6 @@ public class AffirmativeBasedTests {
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setup() {
|
||||
mgr = new AffirmativeBased();
|
||||
|
||||
grant = mock(AccessDecisionVoter.class);
|
||||
abstain = mock(AccessDecisionVoter.class);
|
||||
@@ -61,32 +60,33 @@ public class AffirmativeBasedTests {
|
||||
|
||||
@Test
|
||||
public void oneAffirmativeVoteOneDenyVoteOneAbstainVoteGrantsAccess() throws Exception {
|
||||
mgr.setDecisionVoters(Arrays.<AccessDecisionVoter<? extends Object>>asList(grant, deny, abstain));
|
||||
|
||||
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>>asList(grant, deny, abstain));
|
||||
mgr.afterPropertiesSet();
|
||||
mgr.decide(user, new Object(), attrs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneDenyVoteOneAbstainVoteOneAffirmativeVoteGrantsAccess() throws Exception {
|
||||
mgr.setDecisionVoters(Arrays.<AccessDecisionVoter<? extends Object>>asList(deny, abstain, grant));
|
||||
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>>asList(deny, abstain, grant));
|
||||
mgr.decide(user, new Object(), attrs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneAffirmativeVoteTwoAbstainVotesGrantsAccess() throws Exception {
|
||||
mgr.setDecisionVoters(Arrays.<AccessDecisionVoter<? extends Object>>asList(grant, abstain, abstain));
|
||||
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>>asList(grant, abstain, abstain));
|
||||
mgr.decide(user, new Object(), attrs);
|
||||
}
|
||||
|
||||
@Test(expected=AccessDeniedException.class)
|
||||
public void oneDenyVoteTwoAbstainVotesDeniesAccess() throws Exception {
|
||||
mgr.setDecisionVoters(Arrays.<AccessDecisionVoter<? extends Object>>asList(deny, abstain, abstain));
|
||||
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>>asList(deny, abstain, abstain));
|
||||
mgr.decide(user, new Object(), attrs);
|
||||
}
|
||||
|
||||
@Test(expected=AccessDeniedException.class)
|
||||
public void onlyAbstainVotesDeniesAccessWithDefault() throws Exception {
|
||||
mgr.setDecisionVoters(Arrays.<AccessDecisionVoter<? extends Object>>asList(abstain, abstain, abstain));
|
||||
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>>asList(abstain, abstain, abstain));
|
||||
assertTrue(!mgr.isAllowIfAllAbstainDecisions()); // check default
|
||||
|
||||
mgr.decide(user, new Object(), attrs);
|
||||
@@ -94,7 +94,7 @@ public class AffirmativeBasedTests {
|
||||
|
||||
@Test
|
||||
public void testThreeAbstainVotesGrantsAccessIfAllowIfAllAbstainDecisionsIsSet() throws Exception {
|
||||
mgr.setDecisionVoters(Arrays.<AccessDecisionVoter<? extends Object>>asList(abstain, abstain, abstain));
|
||||
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>>asList(abstain, abstain, abstain));
|
||||
mgr.setAllowIfAllAbstainDecisions(true);
|
||||
assertTrue(mgr.isAllowIfAllAbstainDecisions()); // check changed
|
||||
|
||||
|
||||
+1
-3
@@ -106,7 +106,6 @@ public class ConsensusBasedTests {
|
||||
}
|
||||
|
||||
private ConsensusBased makeDecisionManager() {
|
||||
ConsensusBased decisionManager = new ConsensusBased();
|
||||
RoleVoter roleVoter = new RoleVoter();
|
||||
DenyVoter denyForSureVoter = new DenyVoter();
|
||||
DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
|
||||
@@ -114,9 +113,8 @@ public class ConsensusBasedTests {
|
||||
voters.add(roleVoter);
|
||||
voters.add(denyForSureVoter);
|
||||
voters.add(denyAgainForSureVoter);
|
||||
decisionManager.setDecisionVoters(voters);
|
||||
|
||||
return decisionManager;
|
||||
return new ConsensusBased(voters);
|
||||
}
|
||||
|
||||
private TestingAuthenticationToken makeTestToken() {
|
||||
|
||||
+2
-8
@@ -39,7 +39,6 @@ public class UnanimousBasedTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
private UnanimousBased makeDecisionManager() {
|
||||
UnanimousBased decisionManager = new UnanimousBased();
|
||||
RoleVoter roleVoter = new RoleVoter();
|
||||
DenyVoter denyForSureVoter = new DenyVoter();
|
||||
DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
|
||||
@@ -47,13 +46,10 @@ public class UnanimousBasedTests extends TestCase {
|
||||
voters.add(roleVoter);
|
||||
voters.add(denyForSureVoter);
|
||||
voters.add(denyAgainForSureVoter);
|
||||
decisionManager.setDecisionVoters(voters);
|
||||
|
||||
return decisionManager;
|
||||
return new UnanimousBased(voters);
|
||||
}
|
||||
|
||||
private UnanimousBased makeDecisionManagerWithFooBarPrefix() {
|
||||
UnanimousBased decisionManager = new UnanimousBased();
|
||||
RoleVoter roleVoter = new RoleVoter();
|
||||
roleVoter.setRolePrefix("FOOBAR_");
|
||||
|
||||
@@ -63,9 +59,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
voters.add(roleVoter);
|
||||
voters.add(denyForSureVoter);
|
||||
voters.add(denyAgainForSureVoter);
|
||||
decisionManager.setDecisionVoters(voters);
|
||||
|
||||
return decisionManager;
|
||||
return new UnanimousBased(voters);
|
||||
}
|
||||
|
||||
private TestingAuthenticationToken makeTestToken() {
|
||||
|
||||
-51
@@ -1,51 +0,0 @@
|
||||
package org.springframework.security.authentication;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
*/
|
||||
@SuppressWarnings({"deprecation"})
|
||||
public class AuthenticationDetailsSourceImplTests {
|
||||
|
||||
@Test
|
||||
public void buildDetailsReturnsExpectedAuthenticationDetails() {
|
||||
AuthenticationDetailsSourceImpl ads = new AuthenticationDetailsSourceImpl();
|
||||
AuthenticationDetails details = (AuthenticationDetails) ads.buildDetails("the context");
|
||||
assertEquals("the context", details.getContext());
|
||||
assertEquals(new AuthenticationDetails("the context"), details);
|
||||
ads.setClazz(AuthenticationDetails.class);
|
||||
details = (AuthenticationDetails) ads.buildDetails("another context");
|
||||
assertEquals("another context", details.getContext());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void nonMatchingConstructorIsRejected() {
|
||||
AuthenticationDetailsSourceImpl ads = new AuthenticationDetailsSourceImpl();
|
||||
ads.setClazz(String.class);
|
||||
ads.buildDetails(new Object());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void constructorTakingMultipleArgumentsIsRejected() {
|
||||
AuthenticationDetailsSourceImpl ads = new AuthenticationDetailsSourceImpl();
|
||||
ads.setClazz(TestingAuthenticationToken.class);
|
||||
ads.buildDetails(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authenticationDetailsEqualsBehavesAsExpected() {
|
||||
AuthenticationDetails details = new AuthenticationDetails("the context");
|
||||
assertFalse((new AuthenticationDetails("different context")).equals(details));
|
||||
assertFalse((new AuthenticationDetails(null)).equals(details));
|
||||
assertFalse(details.equals(new AuthenticationDetails(null)));
|
||||
assertFalse(details.equals("a string"));
|
||||
// Just check toString() functions OK
|
||||
details.toString();
|
||||
(new AuthenticationDetails(null)).toString();
|
||||
}
|
||||
|
||||
}
|
||||
+6
-12
@@ -35,35 +35,29 @@ public class DefaultAuthenticationEventPublisherTests {
|
||||
Exception cause = new Exception();
|
||||
Object extraInfo = new Object();
|
||||
publisher.publishAuthenticationFailure(new BadCredentialsException(""), a);
|
||||
publisher.publishAuthenticationFailure(new BadCredentialsException("", extraInfo), a);
|
||||
publisher.publishAuthenticationFailure(new BadCredentialsException("", cause), a);
|
||||
verify(appPublisher, times(3)).publishEvent(isA(AuthenticationFailureBadCredentialsEvent.class));
|
||||
verify(appPublisher, times(2)).publishEvent(isA(AuthenticationFailureBadCredentialsEvent.class));
|
||||
reset(appPublisher);
|
||||
publisher.publishAuthenticationFailure(new UsernameNotFoundException(""), a);
|
||||
publisher.publishAuthenticationFailure(new UsernameNotFoundException("", extraInfo), a);
|
||||
publisher.publishAuthenticationFailure(new UsernameNotFoundException("", cause), a);
|
||||
publisher.publishAuthenticationFailure(new AccountExpiredException(""), a);
|
||||
publisher.publishAuthenticationFailure(new AccountExpiredException("", extraInfo), a);
|
||||
publisher.publishAuthenticationFailure(new AccountExpiredException("", cause), a);
|
||||
publisher.publishAuthenticationFailure(new ProviderNotFoundException(""), a);
|
||||
publisher.publishAuthenticationFailure(new DisabledException(""), a);
|
||||
publisher.publishAuthenticationFailure(new DisabledException("", extraInfo), a);
|
||||
publisher.publishAuthenticationFailure(new DisabledException("", cause), a);
|
||||
publisher.publishAuthenticationFailure(new LockedException(""), a);
|
||||
publisher.publishAuthenticationFailure(new LockedException("", extraInfo), a);
|
||||
publisher.publishAuthenticationFailure(new LockedException("", cause), a);
|
||||
publisher.publishAuthenticationFailure(new AuthenticationServiceException(""), a);
|
||||
publisher.publishAuthenticationFailure(new AuthenticationServiceException("",cause), a);
|
||||
publisher.publishAuthenticationFailure(new CredentialsExpiredException(""), a);
|
||||
publisher.publishAuthenticationFailure(new CredentialsExpiredException("", extraInfo), a);
|
||||
publisher.publishAuthenticationFailure(new CredentialsExpiredException("", cause), a);
|
||||
verify(appPublisher, times(3)).publishEvent(isA(AuthenticationFailureBadCredentialsEvent.class));
|
||||
verify(appPublisher, times(3)).publishEvent(isA(AuthenticationFailureExpiredEvent.class));
|
||||
verify(appPublisher, times(2)).publishEvent(isA(AuthenticationFailureBadCredentialsEvent.class));
|
||||
verify(appPublisher, times(2)).publishEvent(isA(AuthenticationFailureExpiredEvent.class));
|
||||
verify(appPublisher).publishEvent(isA(AuthenticationFailureProviderNotFoundEvent.class));
|
||||
verify(appPublisher, times(3)).publishEvent(isA(AuthenticationFailureDisabledEvent.class));
|
||||
verify(appPublisher, times(3)).publishEvent(isA(AuthenticationFailureLockedEvent.class));
|
||||
verify(appPublisher, times(2)).publishEvent(isA(AuthenticationFailureDisabledEvent.class));
|
||||
verify(appPublisher, times(2)).publishEvent(isA(AuthenticationFailureLockedEvent.class));
|
||||
verify(appPublisher, times(2)).publishEvent(isA(AuthenticationFailureServiceExceptionEvent.class));
|
||||
verify(appPublisher, times(3)).publishEvent(isA(AuthenticationFailureCredentialsExpiredEvent.class));
|
||||
verify(appPublisher, times(2)).publishEvent(isA(AuthenticationFailureCredentialsExpiredEvent.class));
|
||||
verifyNoMoreInteractions(appPublisher);
|
||||
}
|
||||
|
||||
|
||||
+14
-49
@@ -69,10 +69,9 @@ public class ProviderManagerTests {
|
||||
@Test
|
||||
public void authenticationSucceedsWithSupportedTokenAndReturnsExpectedObject() throws Exception {
|
||||
final Authentication a = mock(Authentication.class);
|
||||
ProviderManager mgr = new ProviderManager();
|
||||
ProviderManager mgr = new ProviderManager(Arrays.asList(createProviderWhichReturns(a)));
|
||||
AuthenticationEventPublisher publisher = mock(AuthenticationEventPublisher.class);
|
||||
mgr.setAuthenticationEventPublisher(publisher);
|
||||
mgr.setProviders(Arrays.asList(createProviderWhichReturns(a)));
|
||||
|
||||
Authentication result = mgr.authenticate(a);
|
||||
assertEquals(a, result);
|
||||
@@ -82,37 +81,24 @@ public class ProviderManagerTests {
|
||||
@Test
|
||||
public void authenticationSucceedsWhenFirstProviderReturnsNullButSecondAuthenticates() {
|
||||
final Authentication a = mock(Authentication.class);
|
||||
ProviderManager mgr = new ProviderManager();
|
||||
ProviderManager mgr = new ProviderManager(Arrays.asList(createProviderWhichReturns(null), createProviderWhichReturns(a)));
|
||||
AuthenticationEventPublisher publisher = mock(AuthenticationEventPublisher.class);
|
||||
mgr.setAuthenticationEventPublisher(publisher);
|
||||
mgr.setProviders(Arrays.asList(createProviderWhichReturns(null), createProviderWhichReturns(a)));
|
||||
|
||||
Authentication result = mgr.authenticate(a);
|
||||
assertSame(a, result);
|
||||
verify(publisher).publishAuthenticationSuccess(result);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void startupFailsIfProviderListDoesNotContainProviders() throws Exception {
|
||||
List<Object> providers = new ArrayList<Object>();
|
||||
providers.add("THIS_IS_NOT_A_PROVIDER");
|
||||
|
||||
ProviderManager mgr = new ProviderManager();
|
||||
|
||||
mgr.setProviders(providers);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testStartupFailsIfProvidersNotSet() throws Exception {
|
||||
ProviderManager mgr = new ProviderManager();
|
||||
mgr.afterPropertiesSet();
|
||||
new ProviderManager(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detailsAreNotSetOnAuthenticationTokenIfAlreadySetByProvider() throws Exception {
|
||||
Object requestDetails = "(Request Details)";
|
||||
final Object resultDetails = "(Result Details)";
|
||||
ProviderManager authMgr = makeProviderManager();
|
||||
|
||||
// A provider which sets the details object
|
||||
AuthenticationProvider provider = new AuthenticationProvider() {
|
||||
@@ -126,7 +112,7 @@ public class ProviderManagerTests {
|
||||
}
|
||||
};
|
||||
|
||||
authMgr.setProviders(Arrays.asList(provider));
|
||||
ProviderManager authMgr = new ProviderManager(Arrays.asList(provider));
|
||||
|
||||
TestingAuthenticationToken request = createAuthenticationToken();
|
||||
request.setDetails(requestDetails);
|
||||
@@ -150,35 +136,32 @@ public class ProviderManagerTests {
|
||||
|
||||
@Test
|
||||
public void authenticationExceptionIsIgnoredIfLaterProviderAuthenticates() throws Exception {
|
||||
ProviderManager mgr = new ProviderManager();
|
||||
final Authentication authReq = mock(Authentication.class);
|
||||
mgr.setProviders(Arrays.asList(createProviderWhichThrows(new BadCredentialsException("", new Throwable())),
|
||||
ProviderManager mgr = new ProviderManager(Arrays.asList(createProviderWhichThrows(new BadCredentialsException("", new Throwable())),
|
||||
createProviderWhichReturns(authReq)));
|
||||
assertSame(authReq, mgr.authenticate(mock(Authentication.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authenticationExceptionIsRethrownIfNoLaterProviderAuthenticates() throws Exception {
|
||||
ProviderManager mgr = new ProviderManager();
|
||||
|
||||
mgr.setProviders(Arrays.asList(createProviderWhichThrows(new BadCredentialsException("", "extra")),
|
||||
ProviderManager mgr = new ProviderManager(Arrays.asList(createProviderWhichThrows(new BadCredentialsException("")),
|
||||
createProviderWhichReturns(null)));
|
||||
try {
|
||||
mgr.authenticate(mock(Authentication.class));
|
||||
fail("Expected BadCredentialsException");
|
||||
} catch (BadCredentialsException expected) {
|
||||
assertEquals("extra", expected.getExtraInformation());
|
||||
}
|
||||
}
|
||||
|
||||
// SEC-546
|
||||
@Test
|
||||
public void accountStatusExceptionPreventsCallsToSubsequentProviders() throws Exception {
|
||||
ProviderManager authMgr = makeProviderManager();
|
||||
AuthenticationProvider iThrowAccountStatusException = createProviderWhichThrows(new AccountStatusException(""){});
|
||||
AuthenticationProvider iThrowAccountStatusException = createProviderWhichThrows(new AccountStatusException("") {
|
||||
});
|
||||
AuthenticationProvider otherProvider = mock(AuthenticationProvider.class);
|
||||
|
||||
authMgr.setProviders(Arrays.asList(iThrowAccountStatusException, otherProvider));
|
||||
ProviderManager authMgr = new ProviderManager(Arrays.asList(iThrowAccountStatusException, otherProvider));
|
||||
|
||||
try {
|
||||
authMgr.authenticate(mock(Authentication.class));
|
||||
@@ -188,22 +171,6 @@ public class ProviderManagerTests {
|
||||
verifyZeroInteractions(otherProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extraInformationIsClearedIfFlagIsSet() throws Exception {
|
||||
ProviderManager authMgr = makeProviderManager();
|
||||
AuthenticationProvider iThrowAccountStatusException = createProviderWhichThrows(new AccountStatusException("", "extra"){});
|
||||
|
||||
authMgr.setProviders(Arrays.asList(iThrowAccountStatusException));
|
||||
authMgr.setClearExtraInformation(true);
|
||||
|
||||
try {
|
||||
authMgr.authenticate(mock(Authentication.class));
|
||||
fail("Expected AccountStatusException");
|
||||
} catch (AccountStatusException expected) {
|
||||
assertNull(expected.getExtraInformation());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parentAuthenticationIsUsedIfProvidersDontAuthenticate() throws Exception {
|
||||
AuthenticationManager parent = mock(AuthenticationManager.class);
|
||||
@@ -229,15 +196,15 @@ public class ProviderManagerTests {
|
||||
|
||||
@Test
|
||||
public void providerNotFoundFromParentIsIgnored() throws Exception {
|
||||
ProviderManager mgr = new ProviderManager();
|
||||
final Authentication authReq = mock(Authentication.class);
|
||||
AuthenticationEventPublisher publisher = mock(AuthenticationEventPublisher.class);
|
||||
mgr.setAuthenticationEventPublisher(publisher);
|
||||
// Set a provider that throws an exception - this is the exception we expect to be propagated
|
||||
mgr.setProviders(Arrays.asList(createProviderWhichThrows(new BadCredentialsException(""))));
|
||||
AuthenticationManager parent = mock(AuthenticationManager.class);
|
||||
when(parent.authenticate(authReq)).thenThrow(new ProviderNotFoundException(""));
|
||||
mgr.setParent(parent);
|
||||
|
||||
// Set a provider that throws an exception - this is the exception we expect to be propagated
|
||||
ProviderManager mgr = new ProviderManager(Arrays.asList(createProviderWhichThrows(new BadCredentialsException(""))), parent);
|
||||
mgr.setAuthenticationEventPublisher(publisher);
|
||||
|
||||
try {
|
||||
mgr.authenticate(authReq);
|
||||
fail("Expected exception");
|
||||
@@ -262,7 +229,6 @@ public class ProviderManagerTests {
|
||||
fail("Expected exception");
|
||||
} catch (BadCredentialsException e) {
|
||||
assertSame(expected, e);
|
||||
assertSame(authReq, e.getAuthentication());
|
||||
}
|
||||
verify(publisher).publishAuthenticationFailure(expected, authReq);
|
||||
}
|
||||
@@ -282,7 +248,6 @@ public class ProviderManagerTests {
|
||||
fail("Expected exception");
|
||||
} catch (LockedException e) {
|
||||
assertSame(expected, e);
|
||||
assertSame(authReq, e.getAuthentication());
|
||||
}
|
||||
verify(publisher).publishAuthenticationFailure(expected, authReq);
|
||||
}
|
||||
|
||||
+6
-13
@@ -37,8 +37,7 @@ public class AnonymousAuthenticationProviderTests {
|
||||
|
||||
@Test
|
||||
public void testDetectsAnInvalidKey() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
aap.setKey("qwerty");
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider("qwerty");
|
||||
|
||||
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("WRONG_KEY", "Test",
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
|
||||
@@ -52,10 +51,8 @@ public class AnonymousAuthenticationProviderTests {
|
||||
|
||||
@Test
|
||||
public void testDetectsMissingKey() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
|
||||
try {
|
||||
aap.afterPropertiesSet();
|
||||
new AnonymousAuthenticationProvider(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
@@ -64,16 +61,13 @@ public class AnonymousAuthenticationProviderTests {
|
||||
|
||||
@Test
|
||||
public void testGettersSetters() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
aap.setKey("qwerty");
|
||||
aap.afterPropertiesSet();
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider("qwerty");
|
||||
assertEquals("qwerty", aap.getKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoresClassesItDoesNotSupport() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
aap.setKey("qwerty");
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider("qwerty");
|
||||
|
||||
TestingAuthenticationToken token = new TestingAuthenticationToken("user", "password", "ROLE_A");
|
||||
assertFalse(aap.supports(TestingAuthenticationToken.class));
|
||||
@@ -84,8 +78,7 @@ public class AnonymousAuthenticationProviderTests {
|
||||
|
||||
@Test
|
||||
public void testNormalOperation() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
aap.setKey("qwerty");
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider("qwerty");
|
||||
|
||||
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("qwerty", "Test",
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
|
||||
@@ -97,7 +90,7 @@ public class AnonymousAuthenticationProviderTests {
|
||||
|
||||
@Test
|
||||
public void testSupports() {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider("qwerty");
|
||||
assertTrue(aap.supports(AnonymousAuthenticationToken.class));
|
||||
assertFalse(aap.supports(TestingAuthenticationToken.class));
|
||||
}
|
||||
|
||||
+1
-1
@@ -234,7 +234,7 @@ public class DefaultJaasAuthenticationProviderTests {
|
||||
@Test
|
||||
public void publishNullPublisher() {
|
||||
provider.setApplicationEventPublisher(null);
|
||||
AuthenticationException ae = new BadCredentialsException("Failed to login", token);
|
||||
AuthenticationException ae = new BadCredentialsException("Failed to login");
|
||||
|
||||
provider.publishFailureEvent(token, ae);
|
||||
provider.publishSuccessEvent(token);
|
||||
|
||||
+6
-12
@@ -34,8 +34,7 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void testDetectsAnInvalidKey() throws Exception {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
aap.setKey("qwerty");
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider("qwerty");
|
||||
|
||||
RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("WRONG_KEY", "Test",
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
|
||||
@@ -48,10 +47,8 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testDetectsMissingKey() throws Exception {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
|
||||
try {
|
||||
aap.afterPropertiesSet();
|
||||
new RememberMeAuthenticationProvider(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
@@ -59,15 +56,13 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testGettersSetters() throws Exception {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
aap.setKey("qwerty");
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider("qwerty");
|
||||
aap.afterPropertiesSet();
|
||||
assertEquals("qwerty", aap.getKey());
|
||||
}
|
||||
|
||||
public void testIgnoresClassesItDoesNotSupport() throws Exception {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
aap.setKey("qwerty");
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider("qwerty");
|
||||
|
||||
TestingAuthenticationToken token = new TestingAuthenticationToken("user", "password","ROLE_A");
|
||||
assertFalse(aap.supports(TestingAuthenticationToken.class));
|
||||
@@ -77,8 +72,7 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testNormalOperation() throws Exception {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
aap.setKey("qwerty");
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider("qwerty");
|
||||
|
||||
RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("qwerty", "Test",
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
|
||||
@@ -89,7 +83,7 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSupports() {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider("qwerty");
|
||||
assertTrue(aap.supports(RememberMeAuthenticationToken.class));
|
||||
assertFalse(aap.supports(TestingAuthenticationToken.class));
|
||||
}
|
||||
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* 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.security.core.userdetails.memory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link InMemoryDaoImpl}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
*/
|
||||
@SuppressWarnings({"deprecation"})
|
||||
public class InMemoryDaoTests extends TestCase {
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
private UserMap makeUserMap() {
|
||||
UserMapEditor editor = new UserMapEditor();
|
||||
editor.setAsText("rod=koala,ROLE_ONE,ROLE_TWO,enabled\nScott=wombat,ROLE_ONE,ROLE_TWO,enabled");
|
||||
|
||||
return (UserMap) editor.getValue();
|
||||
}
|
||||
|
||||
public void testLookupFails() throws Exception {
|
||||
InMemoryDaoImpl dao = new InMemoryDaoImpl();
|
||||
dao.setUserMap(makeUserMap());
|
||||
dao.afterPropertiesSet();
|
||||
|
||||
try {
|
||||
dao.loadUserByUsername("UNKNOWN_USER");
|
||||
fail("Should have thrown UsernameNotFoundException");
|
||||
} catch (UsernameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testLookupSuccess() throws Exception {
|
||||
InMemoryDaoImpl dao = new InMemoryDaoImpl();
|
||||
dao.setUserMap(makeUserMap());
|
||||
dao.afterPropertiesSet();
|
||||
assertEquals("koala", dao.loadUserByUsername("rod").getPassword());
|
||||
assertEquals("wombat", dao.loadUserByUsername("scott").getPassword());
|
||||
}
|
||||
|
||||
public void testLookupSuccessWithMixedCase() throws Exception {
|
||||
InMemoryDaoImpl dao = new InMemoryDaoImpl();
|
||||
dao.setUserMap(makeUserMap());
|
||||
dao.afterPropertiesSet();
|
||||
assertEquals("koala", dao.loadUserByUsername("rod").getPassword());
|
||||
assertEquals("wombat", dao.loadUserByUsername("ScOTt").getPassword());
|
||||
}
|
||||
|
||||
public void testStartupFailsIfUserMapNotSet() throws Exception {
|
||||
InMemoryDaoImpl dao = new InMemoryDaoImpl();
|
||||
|
||||
try {
|
||||
dao.afterPropertiesSet();
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testStartupFailsIfUserMapSetToNull() throws Exception {
|
||||
InMemoryDaoImpl dao = new InMemoryDaoImpl();
|
||||
dao.setUserMap(null);
|
||||
|
||||
try {
|
||||
dao.afterPropertiesSet();
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testStartupSuccessIfUserMapSet() throws Exception {
|
||||
InMemoryDaoImpl dao = new InMemoryDaoImpl();
|
||||
dao.setUserMap(makeUserMap());
|
||||
dao.afterPropertiesSet();
|
||||
assertEquals(2, dao.getUserMap().getUserCount());
|
||||
}
|
||||
|
||||
public void testUseOfExternalPropertiesObject() throws Exception {
|
||||
InMemoryDaoImpl dao = new InMemoryDaoImpl();
|
||||
Properties props = new Properties();
|
||||
props.put("rod", "koala,ROLE_ONE,ROLE_TWO,enabled");
|
||||
props.put("scott", "wombat,ROLE_ONE,ROLE_TWO,enabled");
|
||||
dao.setUserProperties(props);
|
||||
assertEquals("koala", dao.loadUserByUsername("rod").getPassword());
|
||||
assertEquals("wombat", dao.loadUserByUsername("scott").getPassword());
|
||||
}
|
||||
}
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* 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.security.core.userdetails.memory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link UserMapEditor}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class UserMapEditorTests extends TestCase {
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void testConvertedIntoUserSuccessfullyWhenDisabled() {
|
||||
UserMapEditor editor = new UserMapEditor();
|
||||
editor.setAsText("rod=koala,ROLE_ONE,ROLE_TWO,disabled");
|
||||
|
||||
UserMap map = (UserMap) editor.getValue();
|
||||
assertTrue(!map.getUser("rod").isEnabled());
|
||||
}
|
||||
|
||||
public void testConvertedIntoUserSuccessfullyWhenEnabled() {
|
||||
UserMapEditor editor = new UserMapEditor();
|
||||
editor.setAsText("rod=koala,ROLE_ONE,ROLE_TWO");
|
||||
|
||||
UserMap map = (UserMap) editor.getValue();
|
||||
assertEquals("rod", map.getUser("rod").getUsername());
|
||||
assertEquals("koala", map.getUser("rod").getPassword());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(map.getUser("rod").getAuthorities()).contains("ROLE_ONE"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(map.getUser("rod").getAuthorities()).contains("ROLE_TWO"));
|
||||
assertTrue(map.getUser("rod").isEnabled());
|
||||
}
|
||||
|
||||
public void testEmptyStringReturnsEmptyMap() {
|
||||
UserMapEditor editor = new UserMapEditor();
|
||||
editor.setAsText("");
|
||||
|
||||
UserMap map = (UserMap) editor.getValue();
|
||||
assertEquals(0, map.getUserCount());
|
||||
}
|
||||
|
||||
public void testMalformedStringReturnsEmptyMap() {
|
||||
UserMapEditor editor = new UserMapEditor();
|
||||
editor.setAsText("MALFORMED_STRING");
|
||||
|
||||
UserMap map = (UserMap) editor.getValue();
|
||||
assertEquals(0, map.getUserCount());
|
||||
}
|
||||
|
||||
public void testMultiUserParsing() {
|
||||
UserMapEditor editor = new UserMapEditor();
|
||||
editor.setAsText("rod=koala,ROLE_ONE,ROLE_TWO,enabled\r\nscott=wombat,ROLE_ONE,ROLE_TWO,enabled");
|
||||
|
||||
UserMap map = (UserMap) editor.getValue();
|
||||
assertEquals("rod", map.getUser("rod").getUsername());
|
||||
assertEquals("scott", map.getUser("scott").getUsername());
|
||||
}
|
||||
|
||||
public void testNullReturnsEmptyMap() {
|
||||
UserMapEditor editor = new UserMapEditor();
|
||||
editor.setAsText(null);
|
||||
|
||||
UserMap map = (UserMap) editor.getValue();
|
||||
assertEquals(0, map.getUserCount());
|
||||
}
|
||||
}
|
||||
-82
@@ -1,82 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* 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.security.core.userdetails.memory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link UserMap}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class UserMapTests {
|
||||
@Test
|
||||
public void testAddAndRetrieveUser() {
|
||||
UserDetails rod = new User("rod", "koala", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE","ROLE_TWO"));
|
||||
UserDetails scott = new User("scott", "wombat", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE","ROLE_THREE"));
|
||||
UserDetails peter = new User("peter", "opal", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE","ROLE_FOUR"));
|
||||
UserMap map = new UserMap();
|
||||
map.addUser(rod);
|
||||
map.addUser(scott);
|
||||
map.addUser(peter);
|
||||
assertEquals(3, map.getUserCount());
|
||||
|
||||
assertEquals(rod, map.getUser("rod"));
|
||||
assertEquals(scott, map.getUser("scott"));
|
||||
assertEquals(peter, map.getUser("peter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullUserCannotBeAdded() {
|
||||
UserMap map = new UserMap();
|
||||
assertEquals(0, map.getUserCount());
|
||||
|
||||
try {
|
||||
map.addUser(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownUserIsNotRetrieved() {
|
||||
UserDetails rod = new User("rod", "koala", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE","ROLE_TWO"));
|
||||
UserMap map = new UserMap();
|
||||
assertEquals(0, map.getUserCount());
|
||||
map.addUser(rod);
|
||||
assertEquals(1, map.getUserCount());
|
||||
|
||||
try {
|
||||
map.getUser("scott");
|
||||
fail("Should have thrown UsernameNotFoundException");
|
||||
} catch (UsernameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user