Java Code Examples for org.springframework.ldap.core.DirContextOperations#setAttributeValue()

The following examples show how to use org.springframework.ldap.core.DirContextOperations#setAttributeValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LdapAuthRepositoryCustomImpl.java    From Spring-5.0-Projects with MIT License 6 votes vote down vote up
@Override
public void createByBindOperation(LdapAuthUser ldapAuthUser) {
	
	DirContextOperations ctx = new DirContextAdapter();
	ctx.setAttributeValues("objectclass", new String[] {"top", "person", "organizationalPerson","inetOrgPerson"});
	ctx.setAttributeValue("cn", ldapAuthUser.getFirstName());
	ctx.setAttributeValue("sn", ldapAuthUser.getSurName());
	ctx.setAttributeValue("uid", ldapAuthUser.getUserName());
	ctx.setAttributeValue("userPassword", ldapAuthUser.getPassword());
	
	Name dn = LdapNameBuilder.newInstance()
		      .add("ou=users")
		      .add("uid=bpatel")
		      .build();
	
	ctx.setDn(dn);
	ldapTemplate.bind(ctx);
	
}
 
Example 2
Source File: ScimToLdapAttributeMapping.java    From osiam with MIT License 5 votes vote down vote up
private void checkMapping() {
    DirContextOperations ldapUserData = new DirContextAdapter();
    for (String scimAttribute : scimToLdapAttributes.keySet()) {
        if (scimAttribute.equalsIgnoreCase("password")) {
            throw new LdapConfigurationException(
                    "The password can not be mapped to the SCIM user. Please delete the password mapping from"
                            + "the configuration!"
            );
        }
        ldapUserData.setAttributeValue(scimToLdapAttributes.get(scimAttribute), "[email protected]");
    }
    OsiamLdapUserContextMapper contextMapper = new OsiamLdapUserContextMapper(this);
    User user = contextMapper.mapUser(ldapUserData);
    contextMapper.mapUpdateUser(user, ldapUserData);
}
 
Example 3
Source File: LdapClient.java    From tutorials with MIT License 5 votes vote down vote up
public void modify(final String username, final String password) {
    Name dn = LdapNameBuilder
      .newInstance()
      .add("ou", "users")
      .add("cn", username)
      .build();
    DirContextOperations context = ldapTemplate.lookupContext(dn);

    context.setAttributeValues("objectclass", new String[]{"top", "person", "organizationalPerson", "inetOrgPerson"});
    context.setAttributeValue("cn", username);
    context.setAttributeValue("sn", username);
    context.setAttributeValue("userPassword", digestSHA(password));

    ldapTemplate.modifyAttributes(context);
}