AnsweredAssumed Answered

LDAP check email is null

Question asked by olegpavliv on Jul 23, 2015
Latest reply on Jul 23, 2015 by jbarrez
In LDAPUserManager.java   mapSearchResultToUser() verifies that the query result returned First and Last user names. In case of NullPointerException it sets the correspondent value to the empty string.

The same verification should be done for email. Otherwise if a result entry does not have email then the NullPointerException is ignored and the application behavior is incorrect.


  protected void mapSearchResultToUser( SearchResult result, UserEntity user) throws NamingException {
    if (ldapConfigurator.getUserIdAttribute() != null) {
      user.setId(result.getAttributes().get(ldapConfigurator.getUserIdAttribute()).get().toString());
    }
    if (ldapConfigurator.getUserFirstNameAttribute() != null) {
       try{
          user.setFirstName(result.getAttributes().get(ldapConfigurator.getUserFirstNameAttribute()).get().toString());
       }catch(NullPointerException e){
          user.setFirstName("");
       }
    }
    if (ldapConfigurator.getUserLastNameAttribute() != null) {
       try{
          user.setLastName(result.getAttributes().get(ldapConfigurator.getUserLastNameAttribute()).get().toString());
       }catch(NullPointerException e){
          user.setLastName("");
       }
    }
    if (ldapConfigurator.getUserEmailAttribute() != null) {
     // here we need to catch NullPointerException as well
       try {
      user.setEmail(result.getAttributes().get(ldapConfigurator.getUserEmailAttribute()).get().toString());
       }catch(NullPointerException e){
          user.setEmail("");
       }
    }
  }

Outcomes