RolePreprocessingMapper extends LdapUserDetailsMapper implements InitializingBean { protected Object preprocessRole( final Object role ) { final String COMPONENT_SEPARATOR = ","; final String NAME_VALUE_PAIR_SEPARATOR = "="; if ( role instanceof String ) { String roleString = (String) role; String[] tokens = roleString.split( COMPONENT_SEPARATOR ); for ( String rdnString : tokens ) { String[] rdnTokens = rdnString.split( NAME_VALUE_PAIR_SEPARATOR ); if ( rdnTokens[0].trim().equals( tokenName ) ) { return rdnTokens[1].trim(); } } if ( RolePreprocessingMapper.logger.isWarnEnabled() ) { RolePreprocessingMapper.logger.warn( Messages.getInstance().getString( "RolePreprocessingMapper.WARN_TOKEN_NOT_FOUND", tokenName ) ); } return null; } else { return role; } } RolePreprocessingMapper();  RolePreprocessingMapper( final String tokenName ); void setTokenName( final String tokenName ); String getTokenName(); void afterPropertiesSet();  }
@Test public void testPreprocessRole() throws Exception { roleMapper = new RolePreprocessingMapper( "ou" ); assertEquals( "users", roleMapper.preprocessRole( "uid=suzy,ou=users,dc=pentaho,dc=org" ) ); }
@Test public void testPreprocessRole_noRoleFound() throws Exception { roleMapper = new RolePreprocessingMapper( "xx" ); assertNull( roleMapper.preprocessRole( "uid=suzy,ou=users,dc=pentaho,dc=org" ) ); }