Add LDAP authentication and enabling Spring logging
[proteocache.git] / server / compbio / spring / security / PCacheLDAPAuthority.java
1 package compbio.spring.security;
2
3 import org.springframework.security.core.GrantedAuthority;
4 import org.springframework.util.Assert;
5
6 /**
7  * Maps groups defined in LDAP to roles for a specific user.
8  */
9 /*
10  * public enum PCacheLDAPAuthority implements GrantedAuthority { ROLE_LDAP_USER;
11  * public String getAuthority() { return name(); } }
12  */
13 public final class PCacheLDAPAuthority implements GrantedAuthority {
14
15         private static final long serialVersionUID = 1;
16
17         private String role = "ROLE_LDAP_USER";
18
19         public PCacheLDAPAuthority(String role) {
20                 Assert.hasText(role, "A granted authority textual representation is required");
21                 this.role = role;
22         }
23
24         public String getAuthority() {
25                 return role;
26         }
27
28         public boolean equals(Object obj) {
29                 if (this == obj) {
30                         return true;
31                 }
32                 if (obj instanceof PCacheLDAPAuthority) {
33                         return role.equals(((PCacheLDAPAuthority) obj).role);
34                 }
35                 return false;
36         }
37
38         public int hashCode() {
39                 return this.role.hashCode();
40         }
41
42         public String toString() {
43                 return this.role;
44         }
45 }