public void createUser(UserDetails user) { DirContextAdapter ctx = new DirContextAdapter(); copyToContext(user, ctx); DistinguishedName dn = usernameMapper.buildDn(user.getUsername()); logger.debug("Creating new user '" + user.getUsername() + "' with DN '" + dn + "'"); template.bind(dn, ctx, null); // Check for any existing authorities which might be set for this DN and remove // them List<GrantedAuthority> authorities = getUserAuthorities(dn, user.getUsername()); if (authorities.size() > 0) { removeAuthorities(dn, authorities); } addAuthorities(dn, user.getAuthorities()); }
/** * {@inheritDoc} */ @Override public void bind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { bind(dn, ctx, null); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
/** * {@inheritDoc} */ @Override public void bind(DirContextOperations ctx) { Name dn = ctx.getDn(); if (dn != null && !ctx.isUpdateMode()) { bind(dn, ctx, null); } else { throw new IllegalStateException("The DirContextOperations instance needs to be properly initialized."); } }
public void create(Application app) throws ToutaticeAnnuaireException { logger.debug("entree dans la methode application.create"); Name dn = buildDn(app); try { ldapTemplateEcriture.bind(dn, null, buildAttributes(app)); } catch (NamingException e) { logger.error("Impossible de créér l'application "+ app.getNom()); throw new ToutaticeAnnuaireException("Erreur lors de la création de l'application "+app.getId()+" dans l'annuaire"); } }
@Override public void createRecursivelyAndUnbindSubnode() { DirContextAdapter ctx = new DirContextAdapter(); ctx.setAttributeValues("objectclass", new String[]{"top", "organizationalUnit"}); ctx.setAttributeValue("ou", "dummy"); ctx.setAttributeValue("description", "dummy description"); ldapTemplate.bind("ou=dummy", ctx, null); ldapTemplate.bind("ou=dummy,ou=dummy", ctx, null); ldapTemplate.unbind("ou=dummy,ou=dummy"); ldapTemplate.unbind("ou=dummy"); }
public void create(Structure str) throws ToutaticeAnnuaireException { Name dn = buildDn(str.getId()); try { Attributes attr = buildAttributes(str); ldapTemplateEcriture.bind(dn, null, attr); } catch (Exception e) { logger.info("Impossible de créér la structure "+ str.getId()); e.printStackTrace(); throw new ToutaticeAnnuaireException("Erreur lors de la création de la structure "+str.getId()+" dans l'annuaire"); } }
@Override public T create(final String dn, final String cn) { final T container = newContainer(dn, cn); // First create the LDAP entry log.info("{} {} will be created as {}", type.name(), container.getName(), dn); final DirContextAdapter context = new DirContextAdapter(dn); context.setAttributeValues("objectClass", new String[] { className }); mapToContext(container, context); template.bind(context); // Return the new container return container; }
public void create(Person p) throws ToutaticeAnnuaireException { Name dn = buildDn(p); try { Attributes attr = buildAttributes(p); ldapTemplateEcriture.bind(dn, null, attr); } catch (NamingException e) { logger.error("Impossible de créér la personne "+ p.getUid()); e.printStackTrace(); throw new ToutaticeAnnuaireException("Erreur lors de la création de la personne "+p.getUid()+" dans l'annuaire"); } }
@Test public void testBindWithContext() throws Exception { expectGetReadWriteContext(); when(dirContextOperationsMock.getDn()).thenReturn(nameMock); when(dirContextOperationsMock.isUpdateMode()).thenReturn(false); tested.bind(dirContextOperationsMock); verify(dirContextMock).bind(nameMock, dirContextOperationsMock, null); verify(dirContextMock).close(); }
@Test public void testBind_String() throws Exception { expectGetReadWriteContext(); Object expectedObject = new Object(); BasicAttributes expectedAttributes = new BasicAttributes(); tested.bind(DEFAULT_BASE_STRING, expectedObject, expectedAttributes); verify(dirContextMock).bind(DEFAULT_BASE_STRING, expectedObject, expectedAttributes); verify(dirContextMock).close(); }
@Test public void testBind() throws Exception { expectGetReadWriteContext(); Object expectedObject = new Object(); BasicAttributes expectedAttributes = new BasicAttributes(); tested.bind(nameMock, expectedObject, expectedAttributes); verify(dirContextMock).bind(nameMock, expectedObject, expectedAttributes); verify(dirContextMock).close(); }
private void createOu() { DirContextAdapter ctx = new DirContextAdapter(OU_DN); ctx.addAttributeValue("objectClass", "top"); ctx.addAttributeValue("objectClass", "organizationalUnit"); ctx.setAttributeValue("ou", "dummy"); ctx.setAttributeValue("description", "dummy description"); ldapTemplate.bind(ctx); }
@Before public void prepareTestedInstance() throws Exception { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person6"); adapter.setAttributeValue("sn", "Person6"); adapter.setAttributeValue("description", "Some description"); tested.bind(DN, adapter, null); }
private void createGroup() { DirContextAdapter ctx = new DirContextAdapter(GROUP_DN); ctx.addAttributeValue("objectclass", "top"); ctx.addAttributeValue("objectclass", "group"); ctx.addAttributeValue("cn", "testgroup"); ctx.addAttributeValue("sAMAccountName", "TESTGROUP"); for (int i = 0; i < 1501; i++) { ctx.addAttributeValue("member", buildUserRefDn("test" + i)); } ldapTemplate.bind(ctx); }
@Before public void prepareTestedInstance() throws Exception { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some\\Person6"); adapter.setAttributeValue("sn", "Person6"); adapter.setAttributeValue("description", "Some description"); tested.unbind(DN); tested.bind(DN, adapter, null); }
@Test public void testBindAndUnbindWithAttributesUsingLdapName() { Attributes attributes = setupAttributes(); tested.bind(LdapUtils.newLdapName(DN), null, attributes); verifyBoundCorrectData(); tested.unbind(LdapUtils.newLdapName(DN)); verifyCleanup(); }
@Test public void testBindAndUnbindWithDirContextAdapter() { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind(DN, adapter, null); verifyBoundCorrectData(); tested.unbind(DN); verifyCleanup(); }
@Test public void testBindGroupOfUniqueNamesWithNameValues() { DirContextAdapter ctx = new DirContextAdapter(LdapUtils.newLdapName("cn=TEST,ou=groups")); ctx.addAttributeValue("cn", "TEST"); ctx.addAttributeValue("objectclass", "top"); ctx.addAttributeValue("objectclass", "groupOfUniqueNames"); ctx.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base)); tested.bind(ctx); }
@Test public void testBindAndUnbindWithDirContextAdapterOnly() { DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN)); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind(adapter); verifyBoundCorrectData(); tested.unbind(DN); verifyCleanup(); }
@Test public void testBindAndUnbindWithDirContextAdapterUsingLdapName() { DirContextAdapter adapter = new DirContextAdapter(); adapter.setAttributeValues("objectclass", new String[] { "top", "person" }); adapter.setAttributeValue("cn", "Some Person4"); adapter.setAttributeValue("sn", "Person4"); tested.bind(LdapUtils.newLdapName(DN), adapter, null); verifyBoundCorrectData(); tested.unbind(LdapUtils.newLdapName(DN)); verifyCleanup(); }