public static final User readUserForIdentifier ( final User u ) { if ( u == null || StringUtils . isBlank ( u . getIdentifier ( ) ) ) { return null ; } User user = null ; String password = null ; String identifier = u . getIdentifier ( ) ; // Try to read the identifier object first, then read the user object linked to it. Sysprop s = CoreUtils . getInstance ( ) . getDao ( ) . read ( u . getAppid ( ) , identifier ) ; if ( s != null && s . getCreatorid ( ) != null ) { user = CoreUtils . getInstance ( ) . getDao ( ) . read ( u . getAppid ( ) , s . getCreatorid ( ) ) ; password = ( String ) s . getProperty ( Config . _PASSWORD ) ; } // Try to find the user by email if already created, but with a different identifier. // This prevents users with identical emails to have separate accounts by signing in through // different identity providers. if ( user == null && ! StringUtils . isBlank ( u . getEmail ( ) ) ) { HashMap < String , Object > terms = new HashMap <> ( 2 ) ; terms . put ( Config . _EMAIL , u . getEmail ( ) ) ; terms . put ( Config . _APPID , u . getAppid ( ) ) ; List < User > users = CoreUtils . getInstance ( ) . getSearch ( ) . findTerms ( u . getAppid ( ) , u . getType ( ) , terms , true , new Pager ( 1 ) ) ; if ( ! users . isEmpty ( ) ) { user = users . get ( 0 ) ; password = Utils . generateSecurityToken ( ) ; user . createIdentifier ( u . getIdentifier ( ) , password ) ; } } if ( user != null ) { if ( password != null ) { user . setPassword ( password ) ; } if ( ! identifier . equals ( user . getIdentifier ( ) ) ) { logger . info ( "Identifier changed for user '{}', from {} to {}." , user . getId ( ) , user . getIdentifier ( ) , identifier ) ; // the main identifier was changed - update user . setIdentifier ( identifier ) ; CoreUtils . getInstance ( ) . getDao ( ) . update ( user . getAppid ( ) , user ) ; } return user ; } logger . debug ( "User not found for identifier {}/{}, {}." , u . getAppid ( ) , identifier , u . getId ( ) ) ; return null ; }
Returns a user object for a given identifier .