List of usage examples for javax.naming.directory BasicAttribute add
public boolean add(Object attrVal)
From source file:ldap.Entry.java
/** * Utility method - useful for creating a multi valued attribute for the Entry constructor * @param ID//from w ww .j a v a 2 s. co m * @param vals * @return a newly created multi valued attribute */ public static BasicAttribute makeAtt(String ID, String[] vals) { BasicAttribute att = new BasicAttribute(ID); for (String val : vals) att.add(val); return att; }
From source file:egovframework.com.ext.ldapumt.service.impl.DeptManageLdapDAO.java
/** * ./* w w w .jav a 2 s . co m*/ * @param vo vo */ public void insertDeptManage(UcorgVO vo) throws Exception { BasicAttribute ocattr = new BasicAttribute("objectclass"); ocattr.add("top"); ocattr.add("ucorg2"); insertOrgManage(vo, ocattr); }
From source file:org.apache.archiva.redback.authentication.ldap.LdapBindAuthenticatorTest.java
private void bindUserObject(DirContext context, String cn, String dn) throws Exception { Attributes attributes = new BasicAttributes(true); BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("inetOrgPerson"); objectClass.add("person"); objectClass.add("organizationalperson"); attributes.put(objectClass);/*from w ww. j ava 2 s. c o m*/ attributes.put("cn", cn); attributes.put("sn", "foo"); attributes.put("mail", "foo"); attributes.put("userPassword", passwordEncoder.encodePassword("foo")); attributes.put("givenName", "foo"); context.createSubcontext(dn, attributes); }
From source file:org.apache.archiva.redback.rest.services.LdapGroupMappingServiceTest.java
private void createGroup(DirContext context, String groupName, String dn) throws Exception { Attributes attributes = new BasicAttributes(true); BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("groupOfUniqueNames"); attributes.put(objectClass);//from w ww.j a va 2 s . c o m attributes.put("cn", groupName); BasicAttribute basicAttribute = new BasicAttribute("uniquemember"); basicAttribute.add("uid=admin," + suffix); attributes.put(basicAttribute); context.createSubcontext(dn, attributes); }
From source file:org.apache.archiva.redback.rest.services.LdapGroupMappingServiceTest.java
@Override public void startServer() throws Exception { super.startServer(); groupSuffix = apacheDs.addSimplePartition("test", new String[] { "archiva", "apache", "org" }).getSuffix(); log.info("groupSuffix: {}", groupSuffix); suffix = "ou=People,dc=archiva,dc=apache,dc=org"; log.info("DN Suffix: {}", suffix); apacheDs.startServer();/*from ww w. j a va2 s . co m*/ BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("organizationalUnit"); Attributes attributes = new BasicAttributes(true); attributes.put(objectClass); attributes.put("organizationalUnitName", "foo"); apacheDs.getAdminContext().createSubcontext(suffix, attributes); createGroups(); }
From source file:org.nuxeo.ecm.directory.ldap.MockLdapServer.java
private void initConfiguration() throws NamingException { // Create the partition for the tests MutablePartitionConfiguration testPartition = new MutablePartitionConfiguration(); testPartition.setId("NuxeoTestLdapServer"); testPartition.setSuffix(BASE_DN);/* w ww . j a v a 2s. com*/ BasicAttributes attributes = new BasicAttributes(); BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("domain"); objectClass.add("extensibleObject"); attributes.put(objectClass); testPartition.setContextEntry(attributes); Set<Object> indexedAttrs = new HashSet<Object>(); indexedAttrs.add("objectClass"); indexedAttrs.add("uid"); indexedAttrs.add("cn"); indexedAttrs.add("ou"); indexedAttrs.add("uniqueMember"); // POSIX RFC-2307 schema. indexedAttrs.add("gidNumber"); indexedAttrs.add("uidNumber"); testPartition.setIndexedAttributes(indexedAttrs); Set<MutablePartitionConfiguration> partitions = new HashSet<MutablePartitionConfiguration>(); partitions.add(testPartition); cfg.setPartitionConfigurations(partitions); }
From source file:org.apache.archiva.redback.rbac.ldap.LdapRbacManagerTest.java
private void createGroup(DirContext context, String groupName, String dn, List<String> users) throws Exception { Attributes attributes = new BasicAttributes(true); BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("groupOfUniqueNames"); attributes.put(objectClass);/*from w w w . j ava 2 s. c om*/ attributes.put("cn", groupName); if (!users.isEmpty()) { BasicAttribute basicAttribute = new BasicAttribute("uniquemember"); for (String user : users) { basicAttribute.add("uid=" + user + "," + suffix);// dc=archiva,dc=apache,dc=org" ); } attributes.put(basicAttribute); } context.createSubcontext(dn, attributes); }
From source file:edu.kit.scc.ldap.LdapPosixGroupDao.java
/** * Updates a POSIX group in the LDAP directory. * /*from w ww . jav a 2 s . c o m*/ * @param group the {@link PosixGroup} to update * @return the {@link PosixGroup} updated */ public PosixGroup updateGroup(PosixGroup group) { BasicAttribute posixGroupBasicAttribute = new BasicAttribute("objectclass"); posixGroupBasicAttribute.add("posixGroup"); Attributes posixGroupAttributes = new BasicAttributes(); posixGroupAttributes.put(posixGroupBasicAttribute); if (group.getCommonName() != null) { posixGroupAttributes.put("cn", group.getCommonName()); } if (group.getGidNumber() != null) { posixGroupAttributes.put("gidNumber", String.valueOf(group.getGidNumber())); } if (group.getUserPassword() != null) { posixGroupAttributes.put("userPassword", group.getUserPassword()); } if (group.getDescription() != null) { posixGroupAttributes.put("description", group.getDescription()); } LdapName groupDn = LdapUtils.emptyLdapName(); try { groupDn = new LdapName(groupBase); groupDn.add("cn=" + group.getCommonName()); log.debug("Update {}", groupDn.toString()); ldapTemplate.bind(groupDn, null, posixGroupAttributes); return group; } catch (InvalidNameException ex) { log.error("ERROR {}", ex.toString()); } return null; }
From source file:edu.kit.scc.ldap.LdapPosixGroupDao.java
/** * Inserts a new POSIX group into the LDAP directory. * //from w ww. j a v a 2 s. co m * @param group the {@link PosixGroup} to insert * @return the {@link PosixGroup} inserted */ public PosixGroup insertGroup(PosixGroup group) { if (group.commonName == null || group.gidNumber == null) { log.warn("PosixGroup has missing mandatory attributes"); return null; } BasicAttribute posixGroupBasicAttribute = new BasicAttribute("objectclass"); posixGroupBasicAttribute.add("posixGroup"); Attributes posixGroupAttributes = new BasicAttributes(); posixGroupAttributes.put(posixGroupBasicAttribute); posixGroupAttributes.put("cn", group.getCommonName()); posixGroupAttributes.put("gidNumber", String.valueOf(group.getGidNumber())); if (group.getUserPassword() != null) { posixGroupAttributes.put("userPassword", group.getUserPassword()); } if (group.getDescription() != null) { posixGroupAttributes.put("description", group.getDescription()); } LdapName newGroupDn = LdapUtils.emptyLdapName(); try { newGroupDn = new LdapName(groupBase); newGroupDn.add("cn=" + group.getCommonName()); log.debug("Insert {}", newGroupDn.toString()); ldapTemplate.bind(newGroupDn, null, posixGroupAttributes); return group; } catch (NameAlreadyBoundException ex) { log.error("ERROR {}", ex.getMessage()); } catch (InvalidNameException ex) { log.error("ERROR {}", ex.getMessage()); } return null; }
From source file:org.apache.archiva.redback.rbac.ldap.LdapRbacManagerTest.java
/** * Creates a new RbacStore which contains no data. *//* w ww . ja v a 2 s .c o m*/ @Before public void setUp() throws Exception { super.setUp(); this.clearCache(); setRbacManager(rbacManager); assertTrue(getRbacManager() instanceof LdapRbacManager); rbacManager.setWritableLdap(true); rbacManager.getRbacImpl().eraseDatabase(); passwordEncoder = new SHA1PasswordEncoder(); usersPerGroup = new HashMap<String, List<String>>(3); usersPerGroup.put("theADMIN", Arrays.asList("admin", "user.9", "bob")); usersPerGroup.put("thePROJECT_ADMIN", Arrays.asList("admin", "bob")); usersPerGroup.put("theDEVELOPER", Arrays.asList("admin", "user.7", "bob")); users = new ArrayList<String>(4); users.add("admin"); users.add("user.7"); users.add("user.8"); users.add("user.9"); groupSuffix = apacheDs.addSimplePartition("test", new String[] { "archiva", "apache", "org" }).getSuffix(); log.info("groupSuffix: {}", groupSuffix); suffix = "ou=People,dc=archiva,dc=apache,dc=org"; log.info("DN Suffix: {}", suffix); apacheDs.startServer(); BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("organizationalUnit"); Attributes attributes = new BasicAttributes(true); attributes.put(objectClass); attributes.put("organizationalUnitName", "foo"); apacheDs.getAdminContext().createSubcontext(suffix, attributes); }