Search in sources :

Example 1 with OidcSamlAuthentication

use of oidc.user.OidcSamlAuthentication in project OpenConext-oidcng by OpenConext.

the class ConcurrentSavedRequestAwareAuthenticationSuccessHandler method onAuthenticationSuccess.

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
    OidcSamlAuthentication samlAuthentication = (OidcSamlAuthentication) authentication;
    AuthenticationRequest authenticationRequest = authenticationRequestRepository.findById(samlAuthentication.getAuthenticationRequestID()).orElseThrow(() -> new IllegalArgumentException("No Authentication Request found for ID: " + samlAuthentication.getAuthenticationRequestID()));
    String originalRequestUrl = authenticationRequest.getOriginalRequestUrl();
    getRedirectStrategy().sendRedirect(request, response, originalRequestUrl);
}
Also used : AuthenticationRequest(oidc.model.AuthenticationRequest) OidcSamlAuthentication(oidc.user.OidcSamlAuthentication)

Example 2 with OidcSamlAuthentication

use of oidc.user.OidcSamlAuthentication in project OpenConext-oidcng by OpenConext.

the class ResponseAuthenticationConverterTest method login.

@Test
public void login() throws XMLParserException, UnmarshallingException, IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    when(authenticationRequestRepository.findById(anyString())).thenReturn(Optional.of(new AuthenticationRequest("id", new Date(), "clientId", "http://some")));
    OidcSamlAuthentication oidcSamlAuthentication = doLogin("saml/authn_response.xml");
    User user = oidcSamlAuthentication.getUser();
    String sub = user.getSub();
    assertEquals("270E4CB4-1C2A-4A96-9AD3-F28C39AD1110", sub);
    assertEquals("urn:collab:person:example.com:admin", oidcSamlAuthentication.getName());
    assertEquals(3, ((List) user.getAttributes().get("eduperson_affiliation")).size());
}
Also used : User(oidc.model.User) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthenticationRequest(oidc.model.AuthenticationRequest) Date(java.util.Date) OidcSamlAuthentication(oidc.user.OidcSamlAuthentication) Test(org.junit.Test)

Example 3 with OidcSamlAuthentication

use of oidc.user.OidcSamlAuthentication in project OpenConext-oidcng by OpenConext.

the class ResponseAuthenticationConverterTest method loginWithNoAuthnContext.

@Test
public void loginWithNoAuthnContext() throws XMLParserException, UnmarshallingException, IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    when(authenticationRequestRepository.findById(anyString())).thenReturn(Optional.of(new AuthenticationRequest("id", new Date(), "clientId", "http://some")));
    OidcSamlAuthentication oidcSamlAuthentication = doLogin("saml/no_authn_context_response.xml");
    assertEquals("urn:collab:person:example.com:admin", oidcSamlAuthentication.getName());
    List<String> acrClaims = oidcSamlAuthentication.getUser().getAcrClaims();
    assertEquals(1, acrClaims.size());
    assertEquals("urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified", acrClaims.get(0));
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthenticationRequest(oidc.model.AuthenticationRequest) Date(java.util.Date) OidcSamlAuthentication(oidc.user.OidcSamlAuthentication) Test(org.junit.Test)

Example 4 with OidcSamlAuthentication

use of oidc.user.OidcSamlAuthentication in project OpenConext-oidcng by OpenConext.

the class ConcurrentSavedRequestAwareAuthenticationSuccessHandlerTest method onAuthenticationSuccess.

@Test
public void onAuthenticationSuccess() throws IOException {
    AuthenticationRequestRepository authenticationRequestRepository = mock(AuthenticationRequestRepository.class);
    ConcurrentSavedRequestAwareAuthenticationSuccessHandler subject = new ConcurrentSavedRequestAwareAuthenticationSuccessHandler(authenticationRequestRepository);
    when(authenticationRequestRepository.findById(isNull())).thenReturn(Optional.of(new AuthenticationRequest("ID", new Date(), "client_id", "http://localhost")));
    MockHttpServletResponse response = new MockHttpServletResponse();
    subject.onAuthenticationSuccess(new MockHttpServletRequest(), response, new OidcSamlAuthentication());
    assertEquals("http://localhost", response.getHeader("Location"));
    assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AuthenticationRequestRepository(oidc.repository.AuthenticationRequestRepository) AuthenticationRequest(oidc.model.AuthenticationRequest) Date(java.util.Date) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) OidcSamlAuthentication(oidc.user.OidcSamlAuthentication) Test(org.junit.Test)

Example 5 with OidcSamlAuthentication

use of oidc.user.OidcSamlAuthentication in project OpenConext-oidcng by OpenConext.

the class FakeSamlAuthenticationFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    String requestURI = ((HttpServletRequest) request).getRequestURI();
    boolean authorizeFlow = authorizeEndpoints.stream().anyMatch(requestURI::contains);
    if (authorizeFlow && (authentication == null || !authentication.isAuthenticated()) && !(authentication instanceof OidcSamlAuthentication)) {
        User user = getUser(objectMapper, request);
        userRepository.deleteAll();
        userRepository.insert(user);
        request.setAttribute(REDIRECT_URI_VALID, true);
        OidcSamlAuthentication samlAuthentication = new OidcSamlAuthentication(getAssertion(), user, "http://localhost");
        SecurityContextHolder.getContext().setAuthentication(samlAuthentication);
    }
    chain.doFilter(request, response);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) User(oidc.model.User) OidcSamlAuthentication(oidc.user.OidcSamlAuthentication) Authentication(org.springframework.security.core.Authentication) OidcSamlAuthentication(oidc.user.OidcSamlAuthentication)

Aggregations

OidcSamlAuthentication (oidc.user.OidcSamlAuthentication)8 AuthenticationRequest (oidc.model.AuthenticationRequest)6 Date (java.util.Date)5 Test (org.junit.Test)5 User (oidc.model.User)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Matcher (java.util.regex.Matcher)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AuthenticationRequestRepository (oidc.repository.AuthenticationRequestRepository)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 Authentication (org.springframework.security.core.Authentication)1 Saml2Authentication (org.springframework.security.saml2.provider.service.authentication.Saml2Authentication)1 SessionAuthenticationException (org.springframework.security.web.authentication.session.SessionAuthenticationException)1