Смена пароля / сброс пароля LDAP через несвязанный API в Java с правами администратора - PullRequest
0 голосов
/ 10 июля 2020

Я новичок в LDAP. Мне удалось создать пользователя через Java, но возникла проблема со сбросом пароля.

Мои коды следующие:

LDAPUserUtility. java

private void setupServer() throws LDAPException, LDIFException
{
    this.log.info(UI.getCurrent().getSession().getAttribute(ConfigProperties.SESSION_KEY)
        + "::LDAPCreateUserUtility::setupServer::");

    final InMemoryDirectoryServerConfig config =
        new InMemoryDirectoryServerConfig(ConfigProperties.SECURITY_PRINCIPAL);
    config.addAdditionalBindCredentials(this.contextSetPropertiesUtilityPOJO.getLDAP_ROOT_LOGIN_USER(),
        this.contextSetPropertiesUtilityPOJO.getLDAP_ROOT_LOGIN_PASSWORD());
    
    // Configure an LDAP port
    config.setListenerConfigs(
        InMemoryListenerConfig.createLDAPConfig(this.contextSetPropertiesUtilityPOJO.getLDAP_PROVIDER_URL()));
    
    // Create and start the LDAP server
    this.server = new InMemoryDirectoryServer(config);
    this.server.startListening();
    
}

private void changeUserPasswordUtil(final LDAPPojo ldapPojo, final String newPassword) throws LDAPException
{
    this.log.info(UI.getCurrent().getSession().getAttribute(ConfigProperties.SESSION_KEY)
        + "::LDAPCreateUserUtility::changeUserPassword::");
    this.contextSetPropertiesUtilityPOJO =
        this.contextSetPropertiesUtility.ContextSetProperties(this.contextSetPropertiesUtilityPOJO);
    final LDAPConnection connection = this.server.getConnection();

    connection.bind(this.contextSetPropertiesUtilityPOJO.getLDAP_ROOT_LOGIN_USER(),
        this.contextSetPropertiesUtilityPOJO.getLDAP_ROOT_LOGIN_PASSWORD());

    final Modification modification = new Modification(
        ModificationType.REPLACE, "userPassword", newPassword);
    
    connection.modify(new ModifyRequest(ldapPojo.getUid(), modification));
    
    this.server.getConnection().bind(ldapPojo.getUid(), newPassword);
}

private void tearDown()
{
    this.server.shutDown(true);
}

public void changeUserPassword(final LDAPPojo ldapPojo, final String newPassword)
{
    try
    {
        this.setupServer();
        this.changeUserPasswordUtil(ldapPojo, newPassword);
        this.tearDown();
        
        ldapPojo.setReturnFlag(ResourceProperty.errorCodeBundle
            .getString("CHANGE_PASSWORD_PASSWORD_UPDATED_SUCCESSFULLY_CODE"));
    }
    catch(final Exception exception)
    {
        ldapPojo.setReturnFlag(ResourceProperty.messagesBundle
            .getString("CHANGE_PASSWORD_PASSWORD_ERROR_WHEN_UPDATING_MSG"));
        this.log.error(UI.getCurrent().getSession().getAttribute(ConfigProperties.SESSION_KEY)
            + "::LDAPCreateUserUtility::changeUserPassword::Exception: " + exception.getStackTrace(), exception);
    }
}

Где: -

  1. user dn (Distinguished Name): uid = prashantssadmin, cn = support-staff-admin, ou = canavans, dc = canavans, dc = local
  2. ConfigProperties.SECURITY_PRINCIPAL: dc = canavans, dc = local

enter image description here

When I call this method I get below error:

LDAPException(resultCode=32 (no such object), diagnosticMessage='Unable to modify entry 'uid=prashantssadmin,cn=support-staff-admin,ou=canavans,dc=canavans,dc=local' because it does not exist in the server.', ldapSDKVersion=5.0.1, revision=3290ee33d4aa17df1aadb4d814d6534375f395a9)
at com.unboundid.ldap.sdk.LDAPConnection.modify(LDAPConnection.java:2928)

Kindly help. Я добавил код, найденный здесь.

...