container-common/src/main/java/com/streamsets/datacollector/http/LdapLoginModule.java
private LdapEntry authenticate(String username,Object password)
  {
    try {
      SearchDnResolver dnResolver = new SearchDnResolver(new DefaultConnectionFactory(connConfig));

      dnResolver.setBaseDn(_userBaseDn);
      dnResolver.setSubtreeSearch(true);
      String userFilter = buildFilter(_userFilter, _userObjectClass, _userIdAttribute);
      LOG.debug("Searching a user with filter {} where user is {}", userFilter, username);
      dnResolver.setUserFilter(userFilter);

      // Set Authenticator with username and password. It will return the user if username/password matches.
      BindAuthenticationHandler authHandler = new BindAuthenticationHandler(new DefaultConnectionFactory(connConfig));
      Authenticator auth = new Authenticator(dnResolver, authHandler);
      AuthenticationRequest authRequest = new AuthenticationRequest();
      authRequest.setUser(username);
      if (password instanceof char[]) {
        authRequest.setCredential(new org.ldaptive.Credential(new String((char[]) password)));
      } else if (password instanceof String){
        authRequest.setCredential(new org.ldaptive.Credential((String)password));
      } else {
        LOG.error("Unexpected type for password '{}'", (password != null) ? password.getClass() : "NULL");
        return null;
      }
      String[] userRoleAttribute = ReturnAttributes.ALL.value();
      authRequest.setReturnAttributes(userRoleAttribute);

      LOG.debug("Retrieved authenticator from factory: {}", auth);
      LOG.debug("Retrieved authentication request from factory: {}", authRequest);

      AuthenticationResponse response = auth.authenticate(authRequest);
      LOG.info("Found user?: {}", response.getResult());
      if (response.getResult()) {
        LdapEntry entry = response.getLdapEntry();
        return entry;
      } else {
        // User not found. Most likely username/password didn't match. Log the reason.
        LOG.error("Result code: {} - {}", response.getResultCode(), response.getMessage());
      }
    }
private LdapEntry authenticate(String username,Object password)
  {
    try {
      SearchDnResolver dnResolver = new SearchDnResolver(new DefaultConnectionFactory(connConfig));

      dnResolver.setBaseDn(_userBaseDn);
      dnResolver.setSubtreeSearch(true);
      String userFilter = buildFilter(_userFilter, _userObjectClass, _userIdAttribute);
      LOG.debug("Searching a user with filter {} where user is {}", userFilter, username);
      dnResolver.setUserFilter(userFilter);

      // Set Authenticator with username and password. It will return the user if username/password matches.
      BindAuthenticationHandler authHandler = new BindAuthenticationHandler(new DefaultConnectionFactory(connConfig));
      Authenticator auth = new Authenticator(dnResolver, authHandler);
      AuthenticationRequest authRequest = new AuthenticationRequest();
      authRequest.setUser(username);
      if (password instanceof char[]) {
        authRequest.setCredential(new org.ldaptive.Credential(new String((char[]) password)));
      } else if (password instanceof String){
        authRequest.setCredential(new org.ldaptive.Credential((String)password));
      } else {
        LOG.error("Unexpected type for password '{}'", (password != null) ? password.getClass() : "NULL");
        return null;
      }
      String[] userRoleAttribute = ReturnAttributes.ALL.value();
      authRequest.setReturnAttributes(userRoleAttribute);

      LOG.debug("Retrieved authenticator from factory: {}", auth);
      LOG.debug("Retrieved authentication request from factory: {}", authRequest);

      AuthenticationResponse response = auth.authenticate(authRequest);
      LOG.info("Found user?: {}", response.getResult());
      if (response.getResult()) {
        LdapEntry entry = response.getLdapEntry();
        return entry;
      } else {
        // User not found. Most likely username/password didn't match. Log the reason.
        LOG.error("Result code: {} - {}", response.getResultCode(), response.getMessage());
      }
    }
private LdapEntry authenticate ( String username , Object password ) { try { SearchDnResolver dnResolver = new SearchDnResolver ( new DefaultConnectionFactory ( connConfig ) ) ; dnResolver . setBaseDn ( _userBaseDn ) ; dnResolver . setSubtreeSearch ( true ) ; String userFilter = buildFilter ( _userFilter , _userObjectClass , _userIdAttribute ) ; LOG . debug ( "Searching a user with filter {} where user is {}" , userFilter , username ) ; dnResolver . setUserFilter ( userFilter ) ; // Set Authenticator with username and password. It will return the user if username/password matches. BindAuthenticationHandler authHandler = new BindAuthenticationHandler ( new DefaultConnectionFactory ( connConfig ) ) ; Authenticator auth = new Authenticator ( dnResolver , authHandler ) ; AuthenticationRequest authRequest = new AuthenticationRequest ( ) ; authRequest . setUser ( username ) ; if ( password instanceof char [ ] ) { authRequest . setCredential ( new org . ldaptive . Credential ( new String ( ( char [ ] ) password ) ) ) ; } else if ( password instanceof String ) { authRequest . setCredential ( new org . ldaptive . Credential ( ( String ) password ) ) ; } else { LOG . error ( "Unexpected type for password '{}'" , ( password != null ) ? password . getClass ( ) : "NULL" ) ; return null ; } String [ ] userRoleAttribute = ReturnAttributes . ALL . value ( ) ; authRequest . setReturnAttributes ( userRoleAttribute ) ; LOG . debug ( "Retrieved authenticator from factory: {}" , auth ) ; LOG . debug ( "Retrieved authentication request from factory: {}" , authRequest ) ; AuthenticationResponse response = auth . authenticate ( authRequest ) ; LOG . info ( "Found user?: {}" , response . getResult ( ) ) ; if ( response . getResult ( ) ) { LdapEntry entry = response . getLdapEntry ( ) ; return entry ; } else { // User not found. Most likely username/password didn't match. Log the reason. LOG . error ( "Result code: {} - {}" , response . getResultCode ( ) , response . getMessage ( ) ) ; } }
Perform authentication with given username and password.
Receive the result from Ldap server
@param username Username that user entered to login
@param password Password that user entered to login
@return LdapEntry which contains all user attributes
Perform authentication with given username and password . Receive the result from Ldap server