import org.springframework.stereotype.Service;
/**
- * CachedKeyManager
+ * CachedKeyManager
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- *
*/
@Service("keyManager#cached")
public class CachedKeyManager
extends AbstractKeyManager
implements KeyManager
{
- @Inject @Named(value="keyManager#jdo")
+ @Inject
+ @Named(value = "keyManager#jdo")
private KeyManager keyImpl;
- @Inject @Named(value="cache#keys")
- private Cache keysCache;
+ @Inject
+ @Named(value = "cache#keys")
+ private Cache<String, AuthenticationKey> keysCache;
public AuthenticationKey addKey( AuthenticationKey key )
{
{
try
{
- AuthenticationKey authkey = (AuthenticationKey) keysCache.get( key );
+ AuthenticationKey authkey = keysCache.get( key );
if ( authkey != null )
{
assertNotExpired( authkey );
else
{
authkey = this.keyImpl.findKey( key );
- keysCache.put( key,authkey );
+ keysCache.put( key, authkey );
return authkey;
}
}
@Inject
@Named(value = "cache#operations")
- private Cache operationsCache;
+ private Cache<String, Operation> operationsCache;
@Inject
@Named(value = "cache#permissions")
- private Cache permissionsCache;
+ private Cache<String, Permission> permissionsCache;
@Inject
@Named(value = "cache#resources")
- private Cache resourcesCache;
+ private Cache<String, Resource> resourcesCache;
@Inject
@Named(value = "cache#roles")
- private Cache rolesCache;
+ private Cache<String, Role> rolesCache;
@Inject
@Named(value = "cache#userAssignments")
- private Cache userAssignmentsCache;
+ private Cache<String, UserAssignment> userAssignmentsCache;
@Inject
@Named(value = "cache#userPermissions")
- private Cache userPermissionsCache;
+ private Cache<String, Map<String, List<Permission>>> userPermissionsCache;
@Inject
@Named(value = "cache#effectiveRoleSet")
- private Cache effectiveRoleSetCache;
+ private Cache<String, Set<Role>> effectiveRoleSetCache;
public void addChildRole( Role role, Role childRole )
throws RbacObjectInvalidException, RbacManagerException
public Map<String, List<Permission>> getAssignedPermissionMap( String principal )
throws RbacObjectNotFoundException, RbacManagerException
{
- Map<String, List<Permission>> el = (Map<String, List<Permission>>) userPermissionsCache.get( principal );
+ Map<String, List<Permission>> el = userPermissionsCache.get( principal );
if ( el != null )
{
public Set<Role> getEffectiveRoles( Role role )
throws RbacObjectNotFoundException, RbacManagerException
{
- Set<Role> el = (Set<Role>) effectiveRoleSetCache.get( role.getName() );
+ Set<Role> el = effectiveRoleSetCache.get( role.getName() );
if ( el != null )
{
public Operation getOperation( String operationName )
throws RbacObjectNotFoundException, RbacManagerException
{
- Object el = operationsCache.get( operationName );
+ Operation el = operationsCache.get( operationName );
if ( el != null )
{
- return (Operation) el;
+ return el;
}
else
{
public Permission getPermission( String permissionName )
throws RbacObjectNotFoundException, RbacManagerException
{
- Object el = permissionsCache.get( permissionName );
+ Permission el = permissionsCache.get( permissionName );
if ( el != null )
{
- return (Permission) el;
+ return el;
}
else
{
public Resource getResource( String resourceIdentifier )
throws RbacObjectNotFoundException, RbacManagerException
{
- Object el = resourcesCache.get( resourceIdentifier );
+ Resource el = resourcesCache.get( resourceIdentifier );
if ( el != null )
{
- return (Resource) el;
+ return el;
}
else
{
public Role getRole( String roleName )
throws RbacObjectNotFoundException, RbacManagerException
{
- Object el = rolesCache.get( roleName );
+ Role el = rolesCache.get( roleName );
if ( el != null )
{
- return (Role) el;
+ return el;
}
else
{
public UserAssignment getUserAssignment( String principal )
throws RbacObjectNotFoundException, RbacManagerException
{
- Object el = userAssignmentsCache.get( principal );
+ UserAssignment el = userAssignmentsCache.get( principal );
if ( el != null )
{
- return (UserAssignment) el;
+ return el;
}
else
{
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*/
-@Service( "userManager#cached" )
+@Service("userManager#cached")
public class CachedUserManager
implements UserManager, UserManagerListener
{
private Logger log = LoggerFactory.getLogger( getClass() );
@Inject
- @Named( value = "userManager#configurable" )
+ @Named(value = "userManager#configurable")
private UserManager userImpl;
@Inject
- @Named( value = "cache#users" )
- private Cache usersCache;
+ @Named(value = "cache#users")
+ private Cache<String, User> usersCache;
public boolean isReadOnly()
{
return getGuestUser();
}
- Object el = usersCache.get( username );
+ User el = usersCache.get( username );
if ( el != null )
{
- return (User) el;
+ return el;
}
else
{
public User getGuestUser()
throws UserNotFoundException, UserManagerException
{
- Object el = usersCache.get( GUEST_USERNAME );
+ User el = usersCache.get( GUEST_USERNAME );
if ( el != null )
{
- return (User) el;
+ return el;
}
else
{
*/
import org.apache.archiva.redback.common.ldap.user.LdapUser;
-import org.apache.archiva.redback.components.cache.builder.CacheBuilder;
+import org.apache.archiva.redback.components.cache.Cache;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
+import javax.inject.Named;
/**
* DefaultLdapCacheService
implements LdapCacheService
{
@Inject
- private CacheBuilder cacheBuilder;
+ @Named(value = "cache#ldapUser")
+ private Cache<String, LdapUser> usersCache;
+
+ @Inject
+ @Named(value = "cache#ldapUserDn")
+ private Cache<String, String> ldapCacheDn;
+
+
// LDAP Users
*/
public LdapUser getUser( String username )
{
- return (LdapUser) cacheBuilder.getCache( "ldapUser" ).get( username );
+ return usersCache.get( username );
}
/**
*/
public boolean removeUser( String username )
{
- return ( cacheBuilder.getCache( "ldapUser" ).remove( username ) == null ? false : true );
+ return ( usersCache.remove( username ) == null ? false : true );
}
/**
*/
public void removeAllUsers()
{
- cacheBuilder.getCache( "ldapUser" ).clear();
+ usersCache.clear();
}
/**
*/
public void addUser( LdapUser user )
{
- LdapUser existingUser = (LdapUser) cacheBuilder.getCache( "ldapUser" ).get( user.getUsername() );
+ LdapUser existingUser = usersCache.get( user.getUsername() );
if( existingUser != null )
{
removeUser( user.getUsername() );
}
- cacheBuilder.getCache( "ldapUser" ).put( user.getUsername(), user );
+ usersCache.put( user.getUsername(), user );
}
// LDAP UserDn
*/
public String getLdapUserDn( String username )
{
- return (String) cacheBuilder.getCache( "ldapUserDn" ).get( username );
+ return ldapCacheDn.get( username );
}
/**
*/
public boolean removeLdapUserDn( String username )
{
- return ( cacheBuilder.getCache( "ldapUserDn" ).remove( username ) == null ? false : true );
+ return ( ldapCacheDn.remove( username ) == null ? false : true );
}
/**
*/
public void removeAllLdapUserDn()
{
- cacheBuilder.getCache( "ldapUserDn" ).clear();
+ ldapCacheDn.clear();
}
/**
*/
public void addLdapUserDn( String username, String userDn )
{
- String existingUserDn = (String) cacheBuilder.getCache( "ldapUserDn" ).get( username );
+ String existingUserDn = ldapCacheDn.get( username );
if( existingUserDn != null )
{
removeUser( username );
}
- cacheBuilder.getCache( "ldapUserDn" ).put( username, userDn );
+ ldapCacheDn.put( username, userDn );
}
}