Browse Source
http://jira.springframework.org/browse/SEC-629. Added support for cache-ref elements on jdbc-user-service and ldap-user-service2.0.x
12 changed files with 1466 additions and 2170 deletions
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
package org.springframework.security.config; |
||||
|
||||
import org.springframework.security.providers.dao.UserCache; |
||||
import org.springframework.security.providers.dao.cache.NullUserCache; |
||||
import org.springframework.security.userdetails.UserDetailsService; |
||||
import org.springframework.security.userdetails.UserDetails; |
||||
import org.springframework.util.Assert; |
||||
|
||||
/** |
||||
* |
||||
* @author Luke Taylor |
||||
* @since 2.0 |
||||
*/ |
||||
class CachingUserDetailsService implements UserDetailsService { |
||||
private UserCache userCache = new NullUserCache(); |
||||
private UserDetailsService delegate; |
||||
|
||||
CachingUserDetailsService(UserDetailsService delegate) { |
||||
this.delegate = delegate; |
||||
} |
||||
|
||||
public UserCache getUserCache() { |
||||
return userCache; |
||||
} |
||||
|
||||
public void setUserCache(UserCache userCache) { |
||||
this.userCache = userCache; |
||||
} |
||||
|
||||
public UserDetails loadUserByUsername(String username) { |
||||
UserDetails user = userCache.getUserFromCache(username); |
||||
|
||||
if (user == null) { |
||||
user = delegate.loadUserByUsername(username); |
||||
} |
||||
|
||||
Assert.notNull(user, "UserDetailsService " + delegate + " returned null for username " + username + ". " + |
||||
"This is an interface contract violation"); |
||||
|
||||
userCache.putUserInCache(user); |
||||
|
||||
return user; |
||||
} |
||||
} |
||||
@ -1,66 +0,0 @@
@@ -1,66 +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.providers; |
||||
|
||||
import org.springframework.security.AuthenticationException; |
||||
import org.springframework.security.userdetails.UserDetails; |
||||
|
||||
/** |
||||
* Populates the <code>UserDetails</code> associated with a CAS authenticated |
||||
* user. |
||||
* |
||||
* <p> |
||||
* Intended to grant authorities (roles) for providers that do not support |
||||
* authorities/roles directly. It merely authenticates their identity. |
||||
* As Spring Security needs to know the authorities granted to a user in |
||||
* order to construct a valid <code>Authentication</code> object, implementations |
||||
* of this interface will provide this information. |
||||
* </p> |
||||
* |
||||
* <p> |
||||
* A {@link UserDetails} is returned by implementations. The |
||||
* <code>UserDetails</code> must, at minimum, contain the username and |
||||
* <code>GrantedAuthority[]</code> objects applicable to the authenticated |
||||
* user. Note that Spring Security ignores the password and enabled/disabled |
||||
* status of the <code>UserDetails</code> because this is |
||||
* authentication-related and should have been enforced by another provider server. The |
||||
* <code>UserDetails</code> returned by implementations is stored in the |
||||
* generated <code>AuthenticationToken</code>, so additional properties |
||||
* such as email addresses, telephone numbers etc can easily be stored. |
||||
* </p> |
||||
* |
||||
* <p> |
||||
* Implementations should not perform any caching. They will only be called |
||||
* when a refresh is required. |
||||
* </p> |
||||
* |
||||
* @author Ben Alex |
||||
* @author Ray Krueger |
||||
* @version $Id$ |
||||
*/ |
||||
public interface UserDetailsService { |
||||
/** |
||||
* Obtains the granted authorities for the specified user.<P>May throw any |
||||
* <code>AuthenticationException</code> or return <code>null</code> if the authorities are unavailable.</p> |
||||
* |
||||
* @param casUserId as obtained from the CAS validation service |
||||
* |
||||
* @return the details of the indicated user (at minimum the granted authorities and the username) |
||||
* |
||||
* @throws org.springframework.security.AuthenticationException DOCUMENT ME! |
||||
*/ |
||||
UserDetails getUserDetails(String casUserId) |
||||
throws AuthenticationException; |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue