1 package de.webman.sync.ldap; 2 3 import javax.naming.directory.*; 4 import javax.naming.*; 5 import java.util.ArrayList ; 6 import java.util.List ; 7 import java.util.Iterator ; 8 import de.webman.sync.User; 9 10 11 17 public class LDAPUser 18 implements User 19 { 20 21 22 25 String dn = null; 26 27 30 ArrayList groups = new ArrayList (); 31 32 35 boolean dirty = false; 36 37 40 String displayName = null; 41 42 45 String login = null; 46 47 56 public LDAPUser (SearchResult sr, String [] attributes) 57 throws NamingException 58 { 59 dn = sr.getName(); 60 61 for (NamingEnumeration ae = sr.getAttributes().getAll(); ae.hasMore();) { 62 Attribute attr = (Attribute)ae.next(); 63 64 if (attributes[LDAPAdaptor.ATTRIBUTE_WEBMAN_GROUP] != null && 65 attributes[LDAPAdaptor.ATTRIBUTE_WEBMAN_GROUP].equals(attr.getID())) { 66 for (NamingEnumeration e = attr.getAll(); 67 e.hasMore(); ) { 68 String val = e.next().toString(); 69 if (!groups.contains(val)) 70 groups.add(val); 71 } 72 } 73 else if (attributes[LDAPAdaptor.ATTRIBUTE_DIRTY_FLAG] != null && 74 attributes[LDAPAdaptor.ATTRIBUTE_DIRTY_FLAG].equals(attr.getID())) { 75 76 NamingEnumeration e = attr.getAll(); 77 if (e.hasMore()) { 78 79 String val = e.next().toString(); 80 if (val != null) 81 dirty = attributes[LDAPAdaptor.ATTRIBUTE_YES_VALUE].equals(val); 82 else 83 dirty = false; 84 } 85 } 86 else if (attributes[LDAPAdaptor.ATTRIBUTE_DISPLAY_NAME] != null && 87 attributes[LDAPAdaptor.ATTRIBUTE_DISPLAY_NAME].equals(attr.getID())) { 88 NamingEnumeration e = attr.getAll(); 89 if (e.hasMore()) 90 displayName = e.next().toString(); 91 } 92 else if (attributes[LDAPAdaptor.ATTRIBUTE_LOGIN] != null && 93 attributes[LDAPAdaptor.ATTRIBUTE_LOGIN].equals(attr.getID())) { 94 NamingEnumeration e = attr.getAll(); 95 if (e.hasMore()) 96 login = e.next().toString(); 97 } 98 } 99 } 100 101 102 106 public List getGroups() { 107 return groups; 108 } 109 110 112 public String getID() { 113 return dn; 114 } 115 116 119 public String getWebmanName() { 120 if (login != null) 121 return login; 122 if (dn != null && dn.startsWith("cn=")) 123 return dn.substring(3); 124 return dn; 125 } 126 127 130 public String getDisplayName() { 131 if (displayName != null) 132 return displayName; 133 return getWebmanName(); 134 } 135 136 139 public boolean isDirty() { 140 return dirty; 141 } 142 143 144 145 148 public String toString() { 149 StringBuffer buf = new StringBuffer (); 150 151 buf.append("["); 152 buf.append(dn); 153 buf.append(": "); 154 for (Iterator it = groups.iterator(); it.hasNext(); ) { 155 buf.append((String )it.next()); 156 if (it.hasNext()) 157 buf.append(", "); 158 } 159 160 buf.append("]"); 161 162 if (dirty) 163 buf.append("*"); 164 165 return buf.toString(); 166 } 167 } 168 | Popular Tags |