public void updateUser(UserDetails user) { DistinguishedName dn = usernameMapper.buildDn(user.getUsername()); logger.debug("Updating user '" + user.getUsername() + "' with DN '" + dn + "'"); List<GrantedAuthority> authorities = getUserAuthorities(dn, user.getUsername()); DirContextAdapter ctx = loadUserAsContext(dn, user.getUsername()); ctx.setUpdateMode(true); copyToContext(user, ctx); // Remove the objectclass attribute from the list of mods (if present). List<ModificationItem> mods = new LinkedList<>(Arrays.asList(ctx .getModificationItems())); ListIterator<ModificationItem> modIt = mods.listIterator(); while (modIt.hasNext()) { ModificationItem mod = (ModificationItem) modIt.next(); Attribute a = mod.getAttribute(); if ("objectclass".equalsIgnoreCase(a.getID())) { modIt.remove(); } } template.modifyAttributes(dn, mods.toArray(new ModificationItem[mods.size()])); // template.rebind(dn, ctx, null); // Remove the old authorities and replace them with the new one removeAuthorities(dn, authorities); addAuthorities(dn, user.getAuthorities()); }
private void changePasswordUsingAttributeModification (DistinguishedName userDn, String oldPassword, String newPassword) { final ModificationItem[] passwordChange = new ModificationItem[] { new ModificationItem( DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(passwordAttributeName, newPassword)) }; if (oldPassword == null) { template.modifyAttributes(userDn, passwordChange); return; } template.executeReadWrite(dirCtx -> { LdapContext ctx = (LdapContext) dirCtx; ctx.removeFromEnvironment("com.sun.jndi.ldap.connect.pool"); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, LdapUtils.getFullDn(userDn, ctx).toString()); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, oldPassword); // TODO: reconnect doesn't appear to actually change the credentials try { ctx.reconnect(null); } catch (javax.naming.AuthenticationException e) { throw new BadCredentialsException( "Authentication for password change failed."); } ctx.modifyAttributes(userDn, passwordChange); return null; }); }
public void update(String dn, String fullname, String lastname, String description) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("sn", lastname); ctx.setAttributeValue("description", description); ldapTemplate.modifyAttributes(ctx); jdbcTemplate.update("update PERSON set lastname=?, description = ? where fullname = ?", new Object[] { lastname, description, fullname }); }
public void updateAndRename(String dn, String newDn, String description) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("description", description); ldapTemplate.modifyAttributes(ctx); ldapTemplate.rename(dn, newDn); }
public void update(String dn, String fullname, String lastname, String description) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("sn", lastname); ctx.setAttributeValue("description", description); ldapTemplate.modifyAttributes(ctx); }
public void updateAndRename(String dn, String newDn, String description) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("description", description); ldapTemplate.modifyAttributes(ctx); ldapTemplate.rename(dn, newDn); }
public void updateAndRename(String dn, String newDn, String updatedDescription) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("description", updatedDescription); ldapTemplate.modifyAttributes(ctx); ldapTemplate.rename(dn, newDn); }
public void modifyAttributes(String dn, String lastName, String description) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("sn", lastName); ctx.setAttributeValue("description", description); ldapTemplate.modifyAttributes(dn, ctx.getModificationItems()); }
public void modifyAttributes(String dn, String lastName, String description) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("sn", lastName); ctx.setAttributeValue("description", description); ldapTemplate.modifyAttributes(dn, ctx.getModificationItems()); }
/** * {@inheritDoc} */ @Override public void updatePassword(Person person, String newPassword) { ModificationItem[] modifications = new ModificationItem[1]; BasicAttribute userPasswordAttribute = new BasicAttribute(MappingHelper.getLdapFieldName(person, "userPassword"), newPassword); modifications[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute); this.template.modifyAttributes(person.getDn(), modifications); }
public void update(Organisation orga) { Name dn = this.buildDn(orga.getId()); DirContextOperations context = ldapTemplateEcriture.lookupContext(dn); context = this.prepareContextForUpdate(context,orga); ldapTemplateEcriture.modifyAttributes(context); }
public void modifyAttributes(String dn, String lastName, String description) { DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("sn", lastName); ctx.setAttributeValue("description", description); ldapTemplate.modifyAttributes(dn, ctx.getModificationItems()); }
@Test public void testModifyAttributes() throws Exception { expectGetReadWriteContext(); ModificationItem[] mods = new ModificationItem[0]; tested.modifyAttributes(nameMock, mods); verify(dirContextMock).modifyAttributes(nameMock, mods); verify(dirContextMock).close(); }
@Test public void testModifyAttributes_AddAttributeValueWithExistingValue() { DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups"); ctx.addAttributeValue("uniqueMember", "cn=Some Person,ou=company1,ou=Norway," + base); tested.modifyAttributes(ctx); assertThat(true).isTrue(); }
@Override public Object doInTransaction(TransactionStatus status) { ModificationItem modificationItem = new ModificationItem( DirContext.ADD_ATTRIBUTE, new BasicAttribute("member", buildUserRefDn("test" + 1501))); ldapTemplate.modifyAttributes(GROUP_DN, new ModificationItem[]{modificationItem}); // The below should cause a rollback throw new RuntimeException("Simulate some failure"); } });
public void update(OrgPerson person) { String dn = prepareDn(person); DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn); ctx.setAttributeValue("sn", person.getLastname()); ctx.setAttributeValue("description", person.getDescription()); ldapTemplate.modifyAttributes(ctx); this.getHibernateTemplate().saveOrUpdate(person); }
@Test public void verifyCompleteReplacementOfUniqueMemberAttribute_Ldap119Workaround() { DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups"); ctx.setAttributeValues("uniqueMember", new String[]{"cn=Some Person,ou=company1,ou=Norway," + base}, true); ctx.getModificationItems(); tested.modifyAttributes(ctx); }
@Override public void updateUser(final UserOrg user) { final DirContextOperations context = template .lookupContext(org.springframework.ldap.support.LdapUtils.newLdapName(user.getDn())); mapToContext(user, context); template.modifyAttributes(context); // Also, update the cache final UserOrg userLdap = findById(user.getId()); user.copy((SimpleUser) userLdap); userLdap.setMails(user.getMails()); cacheRepository.update(user); }
@Test public void testModifyAttributes_Plain() { ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description", "Some other description")); tested.modifyAttributes(PERSON4_DN, new ModificationItem[] { item }); verifyBoundCorrectData(); }
@Test public void testModifyAttributes_LdapName() { ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description", "Some other description")); tested.modifyAttributes(LdapUtils.newLdapName(PERSON4_DN), new ModificationItem[] { item }); verifyBoundCorrectData(); }