protected String getDnForUser(String userId) {
   LdapUserEntity user =
       (LdapUserEntity)
           createUserQuery(org.camunda.bpm.engine.impl.context.Context.getCommandContext())
               .userId(userId)
               .singleResult();
   if (user == null) {
     return "";
   } else {
     return user.getDn();
   }
 }
  public boolean checkPassword(String userId, String password) {

    // prevent a null password
    if (password == null) {
      return false;
    }

    // engine can't work without users
    if (userId == null || userId.isEmpty()) {
      return false;
    }

    /*
     * We only allow login with no password if anonymous login is set.
     * RFC allows such a behavior but discourages the usage so we provide it for
     * user which have an ldap with anonymous login.
     */
    if (!ldapConfiguration.isAllowAnonymousLogin() && password.equals("")) {
      return false;
    }

    // first search for user using manager DN
    LdapUserEntity user = (LdapUserEntity) findUserById(userId);
    close();

    if (user == null) {
      return false;
    } else {

      try {
        // bind authenticate for user + supplied password
        openContext(user.getDn(), password);
        return true;

      } catch (LdapAuthenticationException e) {
        return false;
      }
    }
  }