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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user