use of org.springframework.security.authentication.AuthenticationDetailsSource in project syndesis by syndesisio.
the class SecurityConfiguration method requestHeaderAuthenticationFilter.
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
private RequestHeaderAuthenticationFilter requestHeaderAuthenticationFilter() throws Exception {
RequestHeaderAuthenticationFilter f = new RequestHeaderAuthenticationFilter();
f.setPrincipalRequestHeader("X-Forwarded-User");
f.setCredentialsRequestHeader("X-Forwarded-Access-Token");
f.setAuthenticationManager(authenticationManager());
f.setAuthenticationDetailsSource((AuthenticationDetailsSource<HttpServletRequest, PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails>) (request) -> new PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails(request, AuthorityUtils.createAuthorityList("ROLE_AUTHENTICATED")));
f.setAuthenticationFailureHandler(new SimpleUrlAuthenticationFailureHandler());
f.setExceptionIfHeaderMissing(false);
return f;
}
use of org.springframework.security.authentication.AuthenticationDetailsSource in project spring-security by spring-projects.
the class MiscHttpConfigTests method loginWhenUsingCustomAuthenticationDetailsSourceRefThenAuthenticationSourcesDetailsAccordingly.
@Test
public void loginWhenUsingCustomAuthenticationDetailsSourceRefThenAuthenticationSourcesDetailsAccordingly() throws Exception {
this.spring.configLocations(xml("CustomAuthenticationDetailsSourceRef")).autowire();
Object details = mock(Object.class);
AuthenticationDetailsSource source = this.spring.getContext().getBean(AuthenticationDetailsSource.class);
given(source.buildDetails(any(Object.class))).willReturn(details);
RequestPostProcessor x509 = x509("classpath:org/springframework/security/config/http/MiscHttpConfigTests-certificate.pem");
// @formatter:off
this.mvc.perform(get("/details").with(userCredentials())).andExpect(content().string(details.getClass().getName()));
this.mvc.perform(get("/details").with(x509)).andExpect(content().string(details.getClass().getName()));
MockHttpServletRequestBuilder loginRequest = post("/login").param("username", "user").param("password", "password").with(csrf());
MockHttpSession session = (MockHttpSession) this.mvc.perform(loginRequest).andReturn().getRequest().getSession(false);
this.mvc.perform(get("/details").session(session)).andExpect(content().string(details.getClass().getName()));
// @formatter:on
}
use of org.springframework.security.authentication.AuthenticationDetailsSource in project spring-security by spring-projects.
the class AbstractRememberMeServicesTests method setAndGetAreConsistent.
@Test
public void setAndGetAreConsistent() throws Exception {
MockRememberMeServices services = new MockRememberMeServices(this.uds);
assertThat(services.getCookieName()).isNotNull();
assertThat(services.getParameter()).isNotNull();
assertThat(services.getKey()).isEqualTo("xxxx");
services.setParameter("rm");
assertThat(services.getParameter()).isEqualTo("rm");
services.setCookieName("kookie");
assertThat(services.getCookieName()).isEqualTo("kookie");
services.setTokenValiditySeconds(600);
assertThat(services.getTokenValiditySeconds()).isEqualTo(600);
assertThat(services.getUserDetailsService()).isSameAs(this.uds);
AuthenticationDetailsSource ads = Mockito.mock(AuthenticationDetailsSource.class);
services.setAuthenticationDetailsSource(ads);
assertThat(services.getAuthenticationDetailsSource()).isSameAs(ads);
services.afterPropertiesSet();
}
use of org.springframework.security.authentication.AuthenticationDetailsSource in project spring-security by spring-projects.
the class Saml2WebSsoAuthenticationFilterTests method attemptAuthenticationAddsDetails.
@Test
public void attemptAuthenticationAddsDetails() {
AuthenticationConverter authenticationConverter = mock(AuthenticationConverter.class);
final Saml2AuthenticationToken token = TestSaml2AuthenticationTokens.token();
given(authenticationConverter.convert(this.request)).willReturn(token);
final AuthenticationDetailsSource authenticationDetailsSource = mock(AuthenticationDetailsSource.class);
final WebAuthenticationDetails details = mock(WebAuthenticationDetails.class);
given(authenticationDetailsSource.buildDetails(this.request)).willReturn(details);
this.filter = new Saml2WebSsoAuthenticationFilter(authenticationConverter, "/some/other/path/{registrationId}");
this.filter.setAuthenticationManager((authentication) -> null);
this.filter.setAuthenticationDetailsSource(authenticationDetailsSource);
this.request.setPathInfo("/some/other/path/idp-registration-id");
this.filter.attemptAuthentication(this.request, this.response);
Assertions.assertEquals(details, token.getDetails());
}
use of org.springframework.security.authentication.AuthenticationDetailsSource in project spring-security by spring-projects.
the class Saml2WebSsoAuthenticationFilterTests method attemptAuthenticationWhenAuthenticationNotAbstractAuthenticationTokenDoesNotAddDetails.
@Test
public void attemptAuthenticationWhenAuthenticationNotAbstractAuthenticationTokenDoesNotAddDetails() {
AuthenticationConverter authenticationConverter = mock(AuthenticationConverter.class);
final Authentication authenticationWithoutDetails = mock(Authentication.class);
given(authenticationConverter.convert(this.request)).willReturn(authenticationWithoutDetails);
final AuthenticationDetailsSource authenticationDetailsSource = mock(AuthenticationDetailsSource.class);
this.filter = new Saml2WebSsoAuthenticationFilter(authenticationConverter, "/some/other/path/{registrationId}");
this.filter.setAuthenticationManager((authentication) -> null);
this.filter.setAuthenticationDetailsSource(authenticationDetailsSource);
this.request.setPathInfo("/some/other/path/idp-registration-id");
assertThatNoException().isThrownBy(() -> this.filter.attemptAuthentication(this.request, this.response));
verifyNoInteractions(authenticationDetailsSource);
}
Aggregations