Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package hudson.plugins.collabnet.auth;
 
 
Authorization cache.
public class CNAuthorizationCache {
    private Map<StringSet<Permission>> mPermSetMap = new HashMap<StringSet<Permission>>();
    private long mCacheExpirationDate;

    
Constructor.
    public CNAuthorizationCache() {
         = System.currentTimeMillis(); // first time we use the cache, we'd reset expiration
    }

    
Remove all cache entries and sets next expiration date
    private void clearCache() {
        .clear();
        AuthorizationStrategy authStrategy = Hudson.getInstance().getAuthorizationStrategy();
        CNAuthorizationStrategy cnAuthStrategy = (CNAuthorizationStrategyauthStrategy;
        long permCacheTimeoutMs = cnAuthStrategy.getAuthCacheTimeoutMs();
         = System.currentTimeMillis() + permCacheTimeoutMs;
    }

    
Get a user's permission available for a given project.

Parameters:
username the username
projectId the project id
Returns:
set containing all of the user's permissions
    public synchronized Set<PermissiongetUserProjectPermSet(String usernameString projectId) {
        if (System.currentTimeMillis() >= ) {
            clearCache();
        }
        String cacheKey = projectId + ":" + username;
        Set<PermissionuserPermSet = .get(cacheKey);
        if (userPermSet == null) {
            CNConnection conn = CNConnection.getInstance();
            Set<StringroleNameSet = new HashSet<String>(conn.getUserRoles(projectIdusername));
            Collection<CollabNetRoleuserRoles = CNProjectACL.CollabNetRoles.getMatchingRoles(roleNameSet);
            userPermSet = new HashSet<Permission>();
            for (CollabNetRole role : userRoles) {
                userPermSet.addAll(role.getPermissions());
            }
            .put(cacheKeyuserPermSet);
        }
        return userPermSet;
    }
New to GrepCode? Check out our FAQ X