src/main/java/fr/xebia/springframework/security/core/userdetails/memory/ExtendedUserMapBuilder.java
/**
     * Build an {@link fr.xebia.springframework.security.core.userdetails.ExtendedUser} from user attributes.
     * Protected for test purpose.
     * @param userAttributes a list.
     * @return the build {@link fr.xebia.springframework.security.core.userdetails.ExtendedUser}.
     */
Build an  fr.xebia.springframework.security.core.userdetails.ExtendedUser from user attributes.
Protected for test purpose.
@param userAttributes a list.
Build an fr . xebia . springframework . security . core . userdetails . ExtendedUser from user attributes . Protected for test purpose . @param userAttributes a list .
protected static ExtendedUser buildExtendedUser(String userAttributes) {
        if (userAttributes == null) {
            return null;
        }
        String[] userAttributesStringArray = StringUtils.delimitedListToStringArray(userAttributes, "=");
        if (userAttributesStringArray.length != 2) {
            return null; 
        }
        String username = userAttributesStringArray[0].trim();
        Pattern pattern = Pattern.compile("(enabled|disabled){1}$");
        Matcher matcher = pattern.matcher(userAttributesStringArray[1].trim());
        boolean activated = true;
        if (matcher.find()) {
            activated = ENABLED.equals(matcher.group());
        }
        String allowedIpAddresses = "";
        pattern = Pattern.compile("@\\(.*\\)");
        matcher = pattern.matcher(userAttributesStringArray[1]);
        if (matcher.find()) {
            allowedIpAddresses = StringUtils.deleteAny(matcher.group(), "@() ");
        }
        pattern = Pattern.compile("((,\\ *@\\(.*\\)){0,1}(\\ *,\\ *(enabled|disabled)\\ *){0,1})$");
        String[] remainingAttributes = pattern.split(userAttributesStringArray[1]);
        if (remainingAttributes.length != 1) {
            return null; 
        }
        String[] attributes = StringUtils.commaDelimitedListToStringArray(remainingAttributes[0]);
        if (attributes.length < 2) {
            return null; 
        }
        String password = attributes[0].trim();
        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        for (int i = 1; i < attributes.length; i++) {
            authorities.add(new GrantedAuthorityImpl(attributes[i].trim()));
        }
        ExtendedUser extendedUser = new ExtendedUser(username, password, activated, true, true, true, authorities);
        extendedUser.setAllowedRemoteAddresses(allowedIpAddresses);
        return extendedUser;
    }
protected static ExtendedUser buildExtendedUser ( String userAttributes ) { if ( userAttributes == null ) { return null ; } String [ ] userAttributesStringArray = StringUtils . delimitedListToStringArray ( userAttributes , "=" ) ; if ( userAttributesStringArray . length != 2 ) { return null ; } String username = userAttributesStringArray [ 0 ] . trim ( ) ; Pattern pattern = Pattern . compile ( "(enabled|disabled){1}$" ) ; Matcher matcher = pattern . matcher ( userAttributesStringArray [ 1 ] . trim ( ) ) ; boolean activated = true ; if ( matcher . find ( ) ) { activated = ENABLED . equals ( matcher . group ( ) ) ; } String allowedIpAddresses = "" ; pattern = Pattern . compile ( "@\\(.*\\)" ) ; matcher = pattern . matcher ( userAttributesStringArray [ 1 ] ) ; if ( matcher . find ( ) ) { allowedIpAddresses = StringUtils . deleteAny ( matcher . group ( ) , "@() " ) ; } pattern = Pattern . compile ( "((,\\ *@\\(.*\\)){0,1}(\\ *,\\ *(enabled|disabled)\\ *){0,1})$" ) ; String [ ] remainingAttributes = pattern . split ( userAttributesStringArray [ 1 ] ) ; if ( remainingAttributes . length != 1 ) { return null ; } String [ ] attributes = StringUtils . commaDelimitedListToStringArray ( remainingAttributes [ 0 ] ) ; if ( attributes . length < 2 ) { return null ; } String password = attributes [ 0 ] . trim ( ) ; List < GrantedAuthority > authorities = new ArrayList < GrantedAuthority > ( ) ; for ( int i = 1 ; i < attributes . length ; i ++ ) { authorities . add ( new GrantedAuthorityImpl ( attributes [ i ] . trim ( ) ) ) ; } ExtendedUser extendedUser = new ExtendedUser ( username , password , activated , true , true , true , authorities ) ; extendedUser . setAllowedRemoteAddresses ( allowedIpAddresses ) ; return extendedUser ; }
Build an {@link fr.xebia.springframework.security.core.userdetails.ExtendedUser} from user attributes.
Build an { @link fr . xebia . springframework . security . core . userdetails . ExtendedUser } from user attributes .
// we need a username and some attributes. // Check activated attribute // Check authorized IP addresses // Get user password and roles : // password and role(s) must have been defined. // we need at least one password and one role.