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);
}
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());
}
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));
}
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());
}
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);
}
Aggregations