1 16 17 package org.apache.jetspeed.om.security.ldap; 18 19 import javax.naming.directory.BasicAttributes ; 20 import org.apache.jetspeed.om.security.Permission; 21 import org.apache.jetspeed.services.JetspeedLDAP; 22 import org.apache.jetspeed.services.ldap.LDAPURL; 23 import org.apache.jetspeed.services.security.PermissionException; 24 25 33 public class LDAPPermission extends BaseLDAPObject implements Permission { 34 35 37 protected static final String OBJECT_CLASS = "jetspeedpermission"; 38 protected static final String ORGANIZATIONAL_UNIT = "ou=permissions"; 39 40 protected static final String ATTR_PERMISSION_NAME = "permissionname"; 41 protected static final String ATTR_PERMISSION_ID = "uid"; 42 43 45 protected String name = null; 46 protected String id = null; 47 protected boolean isNew = true; 48 49 51 public LDAPPermission() 52 { 53 isNew = true; 54 } 55 56 public LDAPPermission(String id) 57 { 58 this.setId(id); 59 isNew = true; 60 } 61 62 public LDAPPermission(String name, boolean isNew) 63 { 64 name = super.createId(name); 65 super.ldapurl = JetspeedLDAP.buildURL(ATTR_PERMISSION_ID + "=" + name + "," + ORGANIZATIONAL_UNIT); 66 this.isNew = isNew; 67 68 if (isNew) 69 { 70 this.setName(name); 71 super.myAttrs = new BasicAttributes (); 72 myAttrs.put(ATTR_PERMISSION_ID, id); 73 myAttrs.put(ATTR_PERMISSION_NAME, name); 74 super.setObjectClass(OBJECT_CLASS); 75 } 76 else 77 { 78 super.myAttrs = JetspeedLDAP.read(ldapurl); 79 this.id = super.getutil(ATTR_PERMISSION_ID); 80 this.name = super.getutil(ATTR_PERMISSION_NAME); 81 } 82 } 83 84 public LDAPPermission(LDAPURL ldapurl) 85 { 86 super.ldapurl = ldapurl; 87 super.myAttrs = JetspeedLDAP.read(ldapurl); 88 this.id = super.getutil(ATTR_PERMISSION_ID); 89 this.name = super.getutil(ATTR_PERMISSION_NAME); 90 } 91 92 94 public void update(boolean create) 95 throws PermissionException 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 PermissionException("Could not insert permission 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 PermissionException("Could not update permission in LDAP!"); 108 } 109 } 110 111 113 118 public String getName() 119 { 120 return name; 121 } 122 123 128 public void setName(String permissionName) 129 { 130 setId(permissionName); 131 name = super.createId(permissionName); 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 |