ShibbolethPreAuthenticatedProcessingFilter extends AbstractPreAuthenticatedProcessingFilter { @Override protected Object getPreAuthenticatedPrincipal(final HttpServletRequest request) { Optional<FederatedUser> federatedUser = federatedUserBuilder.shibUser(request); if (!federatedUser.isPresent()) { return null; } if (hasText(getHeader(X_IMPERSONATE, request))) { federatedUser = federatedUserBuilder.basicAuthUser(request, apiAuthorities); } return federatedUser.isPresent() ? federatedUser.get() : null; } ShibbolethPreAuthenticatedProcessingFilter(AuthenticationManager authenticationManager, Manage manage);   }
@Test public void testGetPreAuthenticatedShibPrincipal() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); addShibHeaders(request); FederatedUser principal = (FederatedUser) filter.getPreAuthenticatedPrincipal(request); assertPrincipal(principal, "[ROLE_ADMIN, ROLE_USER]"); assertFalse(principal.isPolicyIdpAccessEnforcementRequired()); }
@Test public void testGetPreAuthenticatedTrustedApiPrincipal() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); addShibHeaders(request); request.addHeader(X_UNSPECIFIED_NAME_ID, "urn:collab:person:example.com:admin"); request.addHeader(X_IDP_ENTITY_ID, PolicyLoader.authenticatingAuthority); request.addHeader(X_DISPLAY_NAME, "John Doe"); request.addHeader(X_IMPERSONATE, true); RunAsFederatedUser principal = (RunAsFederatedUser) filter.getPreAuthenticatedPrincipal(request); assertPrincipal(principal, "[ROLE_PEP, ROLE_USER]"); assertTrue(principal.isPolicyIdpAccessEnforcementRequired()); }
@Test public void testEmptyGetPreAuthenticatedPrincipal() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); FederatedUser principal = (FederatedUser) filter.getPreAuthenticatedPrincipal(request); assertNull(principal); }