"ou=roles", "roleoccupant={0}", new String[] { "uid=suzy,ou=users,dc=pentaho,dc=org", "suzy" }, "cn" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
GrantedAuthority[] authorities = new GrantedAuthority[extraRoles.size()];
int i = 0;
for ( String extraRole : extraRoles ) {
authorities[i++] = new GrantedAuthorityImpl( extraRole );
}
// use the mapper to create a UserDetails instance
UserDetails userDetails = mapper.mapUserFromContext( ctx, "suzy", authorities ); //$NON-NLS-1$
System.out.println( userDetails );
// this asserts the ordering too; not strictly necessary
GrantedAuthority[] expected =
new GrantedAuthority[] { new GrantedAuthorityImpl( "A" ), new GrantedAuthorityImpl( "cto" ), //$NON-NLS-1$ //$NON-NLS-2$
new GrantedAuthorityImpl( "is" ), new GrantedAuthorityImpl( "Authenticated" ) }; //$NON-NLS-1$//$NON-NLS-2$
assertTrue( Arrays.equals( expected, userDetails.getAuthorities() ) );
}