private LdapAuthenticationProvider build() throws Exception { BaseLdapPathContextSource contextSource = getContextSource(); LdapAuthenticator ldapAuthenticator = createLdapAuthenticator(contextSource); LdapAuthoritiesPopulator authoritiesPopulator = getLdapAuthoritiesPopulator(); LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProviderProxy( ldapAuthenticator, authoritiesPopulator); SimpleAuthorityMapper simpleAuthorityMapper = new SimpleAuthorityMapper(); simpleAuthorityMapper.setPrefix(rolePrefix); simpleAuthorityMapper.afterPropertiesSet(); ldapAuthenticationProvider.setAuthoritiesMapper(simpleAuthorityMapper); if (userDetailsContextMapper != null) { ldapAuthenticationProvider .setUserDetailsContextMapper(userDetailsContextMapper); } return ldapAuthenticationProvider; }
@Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider(); SimpleAuthorityMapper grantedAuthorityMapper = new SimpleAuthorityMapper(); grantedAuthorityMapper.setPrefix("ROLE_"); grantedAuthorityMapper.setConvertToUpperCase(true); keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(grantedAuthorityMapper); auth.authenticationProvider(keycloakAuthenticationProvider); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); SimpleAuthorityMapper roleMapper = new SimpleAuthorityMapper(); roleMapper.setConvertToUpperCase(true); grantedAuthoritiesMapper = roleMapper; PowerMockito.mockStatic(AdapterUtils.class); when(AdapterUtils.getRolesFromSecurityContext(any(RefreshableKeycloakSecurityContext.class))).thenReturn(AUTHORITIES); when(AdapterUtils.createPrincipal(eq(deployment), eq(context))).thenReturn(principal); }