View Javadoc

1   package ch.odi.jaaspam;
2   
3   import java.security.Principal;
4   
5   /**
6    * An implementation of Principal suitable for PAM.
7    * A PAM principal is identified by a username.
8    *
9    * @author Ortwin Gl?ck
10   */
11  public class PamPrincipal implements Principal {
12      private String name;
13      
14      public PamPrincipal(String name) {
15          if (name == null) {
16              throw new IllegalArgumentException("name must not be null");
17          }
18          this.name = name;
19      }
20  
21      public String getName() {
22          return name;
23      }
24      
25      public boolean equals(Object o) {
26          if (o == null) return false;
27          if (this == o)  return true;
28          if (!(o instanceof PamPrincipal)) return false;
29          PamPrincipal that = (PamPrincipal) o;
30          return this.name.equals(that.name);
31      }
32      
33      public int hashCode() {
34          return name.hashCode();
35      }
36  
37  }