1 19 20 package com.sslexplorer.unixauth; 21 22 import java.io.Serializable ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import java.util.StringTokenizer ; 26 27 import com.sslexplorer.realms.Realm; 28 import com.sslexplorer.security.Role; 29 30 37 public class UNIXRole implements Role<UNIXRole>, Serializable { 38 39 private String name; 40 private int gid; 41 private String [] members; 42 private final Realm realm; 43 44 48 public UNIXRole(Realm realm, String etcGroupEntry) { 49 this.realm = realm; 50 String [] elements = etcGroupEntry.split(":"); 51 name = elements[0]; 52 if (elements.length > 2 && !name.equals("+")) { 53 gid = Integer.parseInt(elements[2]); 54 List <String > m = new ArrayList <String >(); 55 if (elements.length > 3) { 56 StringTokenizer z = new StringTokenizer (elements[3], ","); 57 while (z.hasMoreTokens()) { 58 m.add(z.nextToken()); 59 } 60 } 61 members = new String [m.size()]; 62 m.toArray(members); 63 } 64 else { 65 throw new IllegalArgumentException ("Invalid format."); 66 } 67 } 68 69 72 public int getGid() { 73 return gid; 74 } 75 76 80 public boolean containsMember(String username) { 81 for (int i = 0; i < members.length; i++) { 82 if (members[i].equals(username)) { 83 return true; 84 } 85 } 86 return false; 87 } 88 89 94 public String getPrincipalName() { 95 return name; 96 } 97 98 public String toString() { 99 return getPrincipalName(); 100 } 101 102 public int compareTo(UNIXRole o) { 103 return getPrincipalName().compareTo(o.getPrincipalName()); 104 } 105 106 109 public Realm getRealm() { 110 return realm; 111 } 112 } | Popular Tags |