Search in sources :

Example 1 with SimpleAttributes2GrantedAuthoritiesMapper

use of org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper in project spring-security by spring-projects.

the class J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests method getJ2eeUserRoles2GrantedAuthoritiesMapper.

private Attributes2GrantedAuthoritiesMapper getJ2eeUserRoles2GrantedAuthoritiesMapper() {
    SimpleAttributes2GrantedAuthoritiesMapper result = new SimpleAttributes2GrantedAuthoritiesMapper();
    result.setAddPrefixIfAlreadyExisting(false);
    result.setConvertAttributeToLowerCase(false);
    result.setConvertAttributeToUpperCase(false);
    result.setAttributePrefix("");
    return result;
}
Also used : SimpleAttributes2GrantedAuthoritiesMapper(org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper)

Example 2 with SimpleAttributes2GrantedAuthoritiesMapper

use of org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper in project spring-security by spring-projects.

the class WebSpherePreAuthenticatedProcessingFilterTests method principalsAndCredentialsAreExtractedCorrectly.

@Test
public void principalsAndCredentialsAreExtractedCorrectly() throws Exception {
    new WebSpherePreAuthenticatedProcessingFilter();
    WASUsernameAndGroupsExtractor helper = mock(WASUsernameAndGroupsExtractor.class);
    when(helper.getCurrentUserName()).thenReturn("jerry");
    WebSpherePreAuthenticatedProcessingFilter filter = new WebSpherePreAuthenticatedProcessingFilter(helper);
    assertThat(filter.getPreAuthenticatedPrincipal(new MockHttpServletRequest())).isEqualTo("jerry");
    assertThat(filter.getPreAuthenticatedCredentials(new MockHttpServletRequest())).isEqualTo("N/A");
    AuthenticationManager am = mock(AuthenticationManager.class);
    when(am.authenticate(any(Authentication.class))).thenAnswer(new Answer<Authentication>() {

        public Authentication answer(InvocationOnMock invocation) throws Throwable {
            return (Authentication) invocation.getArguments()[0];
        }
    });
    filter.setAuthenticationManager(am);
    WebSpherePreAuthenticatedWebAuthenticationDetailsSource ads = new WebSpherePreAuthenticatedWebAuthenticationDetailsSource(helper);
    ads.setWebSphereGroups2GrantedAuthoritiesMapper(new SimpleAttributes2GrantedAuthoritiesMapper());
    filter.setAuthenticationDetailsSource(ads);
    filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), mock(FilterChain.class));
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) SimpleAttributes2GrantedAuthoritiesMapper(org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Authentication(org.springframework.security.core.Authentication) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FilterChain(javax.servlet.FilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

SimpleAttributes2GrantedAuthoritiesMapper (org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper)2 FilterChain (javax.servlet.FilterChain)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 Authentication (org.springframework.security.core.Authentication)1