use of org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken in project midpoint by Evolveum.
the class Saml2ModuleAuthenticationImpl method clone.
@Override
public ModuleAuthenticationImpl clone() {
Saml2ModuleAuthenticationImpl module = new Saml2ModuleAuthenticationImpl();
module.setAdditionalConfiguration(this.getAdditionalConfiguration());
module.setProviders(this.getProviders());
Authentication actualAuth = SecurityContextHolder.getContext().getAuthentication();
Authentication newAuthentication = this.getAuthentication();
if (actualAuth instanceof MidpointAuthentication && ((MidpointAuthentication) actualAuth).getAuthentications() != null && !((MidpointAuthentication) actualAuth).getAuthentications().isEmpty()) {
ModuleAuthentication actualModule = ((MidpointAuthentication) actualAuth).getAuthentications().get(0);
if (actualModule instanceof Saml2ModuleAuthenticationImpl && actualModule.getAuthentication() instanceof Saml2AuthenticationToken) {
newAuthentication = actualModule.getAuthentication();
}
}
module.setAuthentication(newAuthentication);
super.clone(module);
return module;
}
use of org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken in project spring-security by spring-projects.
the class Saml2LoginConfigurerTests method authenticateWhenCustomAuthenticationConverterBeanThenUses.
@Test
public void authenticateWhenCustomAuthenticationConverterBeanThenUses() throws Exception {
this.spring.register(CustomAuthenticationConverterBean.class).autowire();
Saml2AuthenticationTokenConverter authenticationConverter = this.spring.getContext().getBean(Saml2AuthenticationTokenConverter.class);
RelyingPartyRegistration relyingPartyRegistration = TestRelyingPartyRegistrations.noCredentials().assertingPartyDetails((party) -> party.verificationX509Credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential()))).build();
String response = new String(Saml2Utils.samlDecode(SIGNED_RESPONSE));
given(authenticationConverter.convert(any(HttpServletRequest.class))).willReturn(new Saml2AuthenticationToken(relyingPartyRegistration, response));
// @formatter:off
MockHttpServletRequestBuilder request = post("/login/saml2/sso/" + relyingPartyRegistration.getRegistrationId()).param("SAMLResponse", SIGNED_RESPONSE);
// @formatter:on
this.mvc.perform(request).andExpect(redirectedUrl("/"));
verify(authenticationConverter).convert(any(HttpServletRequest.class));
}
use of org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken in project spring-security by spring-projects.
the class Saml2LoginConfigurerTests method authenticateWhenCustomAuthenticationConverterThenUses.
@Test
public void authenticateWhenCustomAuthenticationConverterThenUses() throws Exception {
this.spring.register(CustomAuthenticationConverter.class).autowire();
RelyingPartyRegistration relyingPartyRegistration = TestRelyingPartyRegistrations.noCredentials().assertingPartyDetails((party) -> party.verificationX509Credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential()))).build();
String response = new String(Saml2Utils.samlDecode(SIGNED_RESPONSE));
given(CustomAuthenticationConverter.authenticationConverter.convert(any(HttpServletRequest.class))).willReturn(new Saml2AuthenticationToken(relyingPartyRegistration, response));
// @formatter:off
MockHttpServletRequestBuilder request = post("/login/saml2/sso/" + relyingPartyRegistration.getRegistrationId()).param("SAMLResponse", SIGNED_RESPONSE);
// @formatter:on
this.mvc.perform(request).andExpect(redirectedUrl("/"));
verify(CustomAuthenticationConverter.authenticationConverter).convert(any(HttpServletRequest.class));
}
use of org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken in project spring-security by spring-projects.
the class Saml2AuthenticationTokenConverter method convert.
@Override
public Saml2AuthenticationToken convert(HttpServletRequest request) {
RelyingPartyRegistration relyingPartyRegistration = this.relyingPartyRegistrationResolver.convert(request);
if (relyingPartyRegistration == null) {
return null;
}
String saml2Response = request.getParameter(Saml2ParameterNames.SAML_RESPONSE);
if (saml2Response == null) {
return null;
}
byte[] b = samlDecode(saml2Response);
saml2Response = inflateIfRequired(request, b);
AbstractSaml2AuthenticationRequest authenticationRequest = loadAuthenticationRequest(request);
return new Saml2AuthenticationToken(relyingPartyRegistration, saml2Response, authenticationRequest);
}
use of org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken in project spring-security by spring-projects.
the class OpenSaml4AuthenticationProviderTests method authenticateWhenResponseAuthenticationConverterConfiguredThenUses.
@Test
public void authenticateWhenResponseAuthenticationConverterConfiguredThenUses() {
Converter<ResponseToken, Saml2Authentication> authenticationConverter = mock(Converter.class);
OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
provider.setResponseAuthenticationConverter(authenticationConverter);
Response response = TestOpenSamlObjects.signedResponseWithOneAssertion();
Saml2AuthenticationToken token = token(response, verifying(registration()));
provider.authenticate(token);
verify(authenticationConverter).convert(any());
}
Aggregations