Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hudson.plugins.collabnet.auth;
  
  
 
Authentication class for CollabNet.
 
 public class CNAuthentication implements Authentication {
     public static final String SUPER_USER = "SuperUser";
     private String principal;
     private CollabNetApp cna;
     private GrantedAuthority[] authorities;
     private Collection<Stringgroups;
     private boolean authenticated = false;
     private boolean cnauthed = false;
 
     private static Logger log = Logger.getLogger("CNAuthentication");
     
     public CNAuthentication(Object principalObject credentials) {
         this. = (Stringprincipal;
         this. = (CollabNetAppcredentials;
         this.setupAuthorities();
         this.setupGroups();
         this.setAuthenticated(true);
     }
    
    
The only granted authority is superuser-ness.
 
     private void setupAuthorities() {
         boolean isSuper = false;
         try {
             isSuper = this..isUserSuper(this.);
         } catch (RemoteException re) {
             .info("setupAuthoritites: failed with RemoteException: " + 
                      re.getMessage());
         }
 
         if (isSuper) {
             this. = new GrantedAuthority[1];
             this.[0] = 
                 new GrantedAuthorityImpl(.);
         } else {
             this. = new GrantedAuthority[0];
         }
     }

    
Check which groups this user belongs to.
 
     private void setupGroups() {
         this. = Collections.emptyList();
         try {
             this. = .getUserGroups(this.);
         } catch (RemoteException re) {}
     }
     
     public void setAuthenticated(boolean authenticated) {
         this. = authenticated;
     }
     
     public boolean isAuthenticated() {
         return this.;
     }
    
    

Returns:
a copy of the granted authorities.
 
     public GrantedAuthority[] getAuthorities() {
         GrantedAuthority[] authCopy = 
             new GrantedAuthority[this..length];
         System.arraycopy(this., 0, authCopy, 0, 
                          this..length);
         return authCopy;
     }
     
     public Object getPrincipal() {
         return this.;
     }
     
     public String getName() {
         return (String)this.getPrincipal();
     }
     
     public Object getDetails() {
             return null;
     }
     
     public Object getCredentials() {
         return this.;
    }

    

Parameters:
group name of a CN group.
Returns:
true if the user is a member of the given group.
    public boolean isMember(String group) {
        return this..contains(group);
    }
    public String toString() {
        return "CNAuthentication [for: " + this.getPrincipal() + 
            ", authenticated=" + this.isAuthenticated() + "]";
    }
    public boolean isCNAuthed() {
        return this.;
    }
    public void setCNAuthed(boolean cnauthed) {
        this. = cnauthed;
    }
    public String getSessionId() {
        String sessionId = null;
        if (this.getCredentials() instanceof CollabNetApp) {
            sessionId = ((CollabNetApp)this.getCredentials()).getSessionId();
        }
        return sessionId;
    }
New to GrepCode? Check out our FAQ X