cancel
Showing results for 
Search instead for 
Did you mean: 

LDAP check email is null

olegpavliv
Champ in-the-making
Champ in-the-making
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("");
       }
    }
  }
1 REPLY 1

jbarrez
Star Contributor
Star Contributor