private TgwRole createRole(String dn, Attributes attrs) throws NamingException{ TgwRole role = new TgwRole(); role.setDn(dn); Attribute cn = attrs.get(rolePrefix); if(cn != null){ role.setName((String)cn.get()); role.setAdmin(role.getName().equals(adminRolename)); } Attribute description = attrs.get(descriptionAttribute); if(description != null) role.setDescription((String)description.get()); Attribute member = attrs.get(roleUserAttribute); if(member != null){ int size = member.size(); String[] users = new String[size]; for(int i=0;i<size;i++){ users[i] = (String)member.get(i); } role.setUsers(users); } return role; }
private Attributes createRoleAttributes(TgwRole role){ Attributes attrs = new BasicAttributes(); attrs.put(roleObjectClass); attrs.put(new BasicAttribute(rolePrefix,role.getName())); attrs.put(new BasicAttribute(descriptionAttribute,role.getDescription())); return attrs; }
public void deleteRole(String roledn) { TgwRole role = getRole(roledn); if(role.isAdmin()){ // should throw Exception ?? log.warn(role.getName() + "couldn't delete role which represents admin priviledge."); return; } try{ ctx = new InitialDirContext(environment); ctx.destroySubcontext(DirectoryUtils.getRDN(roledn,searchBase)); log.info("deleting " + roledn + " completed."); // ctx.close(); }catch(NamingException ne){ ne.printStackTrace(); }finally{ DirectoryUtils.closeQuietly(ctx); } }
throw new RevisionDescriptorNotFoundException(currentUri); String[] users = role.getUsers(); StringBuffer buf = new StringBuffer(); props.put("DAV:group-member-set",groupMemberSet); NodeProperty ldapCn = new NodeProperty(rolePrefix,role.getName(),LDAP_NAMESPACE); props.put(LDAP_NAMESPACE + rolePrefix, ldapCn);
private void addUserRoleAttribute(){ DirContext ctx = null; Hashtable<String, String> bindenv = getCurrentBindEnvironment(); try{ ctx = new InitialDirContext(bindenv); Attributes attrs = ctx.getAttributes(getDN(username,userSearchPrefix,userSearchBase,searchBase,false)); Attribute attr = attrs.get(userRoleAttribute); if(attr != null){ NamingEnumeration roles = attr.getAll(); while(roles.hasMore()){ String rolename = (String)roles.next(); Pattern p = Pattern.compile("^" + roleSearchPrefix + "=([0-9a-zA-Z]*)[,0-9a-zA-Z=]?"); Matcher m = p.matcher(rolename); if(m.find()){ rolename = m.group(1); } TgwRole role = new TgwRole(rolename); roleList.add(role); } } }catch(NamingException ne){ ne.printStackTrace(); }finally{ closeQuietly(ctx); } }
public int hashCode(){ return getName().hashCode(); }
if(values.hasMore()){ String value = (String)values.next(); TgwRole role = new TgwRole(value); if(!roleList.contains(role)) roleList.add(role);
for (Iterator i = roleList.iterator(); i.hasNext();) { TgwRole role = (TgwRole) i.next(); list.add(role.getName());
public void modifyRole(TgwRole role) { String dn = DirectoryUtils.getAbsoluteDN(role.getName(),rolePrefix,roleSuffix,searchBase); try{ ctx = new InitialDirContext(environment); Attributes attrs = createRoleAttributes(role); ctx.modifyAttributes(DirectoryUtils.getRDN(dn,searchBase),DirContext.REPLACE_ATTRIBUTE,attrs); // ctx.close(); }catch(NamingException ne){ ne.printStackTrace(); }finally{ DirectoryUtils.closeQuietly(ctx); } }
public void addRole(TgwRole role) { String dn = DirectoryUtils.getAbsoluteDN(role.getName(),rolePrefix,roleSuffix,searchBase); try{ ctx = new InitialDirContext(environment); Attributes attrs = createRoleAttributes(role); if(roleRequiredAttributes != null){ NamingEnumeration reqattrs = roleRequiredAttributes.getAll(); while(reqattrs.hasMore()){ attrs.put((Attribute)reqattrs.next()); } } ctx.createSubcontext(DirectoryUtils.getRDN(dn,searchBase),attrs); String adminUserDn = userPrefix + "=" + adminUsername + DirectoryUtils.buildSuffix(userSuffix,searchBase,true,true); TgwUser admin = new TgwUser(adminUsername); admin.setDn(adminUserDn); updateRoles(admin,new String[]{role.getName()},DirContext.ADD_ATTRIBUTE); log.info("adding " + dn + " completed."); // ctx.close(); }catch(NamingException ne){ ne.printStackTrace(); }finally{ DirectoryUtils.closeQuietly(ctx); } }