1 16 17 package org.apache.jetspeed.om.security.ldap; 18 19 import javax.naming.directory.BasicAttributes ; 20 import org.apache.jetspeed.om.security.Group; 21 import org.apache.jetspeed.services.JetspeedLDAP; 22 import org.apache.jetspeed.services.ldap.LDAPURL; 23 import org.apache.jetspeed.services.security.GroupException; 24 25 33 public class LDAPGroup extends BaseLDAPObject implements Group { 34 35 37 protected static final String OBJECT_CLASS = "jetspeedgroup"; 38 protected static final String ORGANIZATIONAL_UNIT = "ou=groups"; 39 40 protected static final String ATTR_GROUP_NAME = "groupname"; 41 protected static final String ATTR_GROUP_ID = "uid"; 42 43 45 protected String name = null; 46 protected String id = null; 47 protected boolean isNew = true; 48 49 51 public LDAPGroup() 52 { 53 isNew = true; 54 } 55 56 public LDAPGroup(String id) 57 { 58 this.setId(id); 59 isNew = true; 60 } 61 62 public LDAPGroup(String name, boolean isNew) 63 { 64 name = super.createId(name); 65 super.ldapurl = JetspeedLDAP.buildURL(ATTR_GROUP_ID + "=" + name + "," + ORGANIZATIONAL_UNIT); 66 this.isNew = isNew; 67 68 if (isNew) 69 { 70 this.setName(name); 71 super.myAttrs = new BasicAttributes (); 72 super.myAttrs.put(ATTR_GROUP_ID, this.getId()); 73 super.myAttrs.put(ATTR_GROUP_NAME, this.getName()); 74 super.setObjectClass(OBJECT_CLASS); 75 } 76 else 77 { 78 super.myAttrs = JetspeedLDAP.read(ldapurl); 79 this.id = getutil(ATTR_GROUP_ID); 80 this.name = getutil(ATTR_GROUP_NAME); 81 } 82 } 83 84 public LDAPGroup(LDAPURL ldapurl) 85 { 86 super.ldapurl = ldapurl; 87 super.myAttrs = JetspeedLDAP.read(ldapurl); 88 this.id = getutil(ATTR_GROUP_ID); 89 this.name = getutil(ATTR_GROUP_NAME); 90 } 91 92 94 public void update(boolean create) 95 throws GroupException 96 { 97 removeutil("createTimeStamp", false); 98 removeutil("modifyTimeStamp", false); 99 100 if (create) 101 { 102 if (JetspeedLDAP.addEntry(super.ldapurl, super.myAttrs) == false) throw new GroupException("Failed to insert group in LDAP!"); 103 } 104 else if (JetspeedLDAP.exists(super.ldapurl)) 105 { 106 JetspeedLDAP.deleteAttrs(super.ldapurl, super.rmAttrs); 107 if (JetspeedLDAP.updateEntry(super.ldapurl, super.myAttrs) == false) throw new GroupException("Failed to update group in LDAP!"); 108 } 109 } 110 111 113 118 public String getName() 119 { 120 return name; 121 } 122 123 128 public void setName(String groupName) 129 { 130 setId(groupName); 131 name = super.createId(groupName); 132 } 133 134 139 public String getId() 140 { 141 return id; 142 } 143 144 149 public void setId(String id) 150 { 151 if (this.id == null) 152 { 153 this.id = super.createId(id); 154 } 155 } 156 157 public boolean isNew() 158 { 159 return isNew; 160 } 161 162 void setNew(boolean isNew) 163 { 164 this.isNew = isNew; 165 } 166 167 } | Popular Tags |