Search in sources :

Example 26 with Assertion

use of org.jasig.cas.client.validation.Assertion in project spring-security by spring-projects.

the class CasAuthenticationTokenTests method testEqualsWhenEqual.

@Test
public void testEqualsWhenEqual() {
    final Assertion assertion = new AssertionImpl("test");
    CasAuthenticationToken token1 = new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES, makeUserDetails(), assertion);
    CasAuthenticationToken token2 = new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES, makeUserDetails(), assertion);
    assertThat(token2).isEqualTo(token1);
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) Assertion(org.jasig.cas.client.validation.Assertion) Test(org.junit.Test)

Example 27 with Assertion

use of org.jasig.cas.client.validation.Assertion in project spring-security by spring-projects.

the class CasAuthenticationTokenTests method testNotEqualsDueToAbstractParentEqualsCheck.

@Test
public void testNotEqualsDueToAbstractParentEqualsCheck() {
    final Assertion assertion = new AssertionImpl("test");
    CasAuthenticationToken token1 = new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES, makeUserDetails(), assertion);
    CasAuthenticationToken token2 = new CasAuthenticationToken("key", makeUserDetails("OTHER_NAME"), "Password", ROLES, makeUserDetails(), assertion);
    assertThat(!token1.equals(token2)).isTrue();
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) Assertion(org.jasig.cas.client.validation.Assertion) Test(org.junit.Test)

Example 28 with Assertion

use of org.jasig.cas.client.validation.Assertion in project spring-security by spring-projects.

the class CasAuthenticationProvider method authenticateNow.

private CasAuthenticationToken authenticateNow(final Authentication authentication) throws AuthenticationException {
    try {
        final Assertion assertion = this.ticketValidator.validate(authentication.getCredentials().toString(), getServiceUrl(authentication));
        final UserDetails userDetails = loadUserByAssertion(assertion);
        userDetailsChecker.check(userDetails);
        return new CasAuthenticationToken(this.key, userDetails, authentication.getCredentials(), authoritiesMapper.mapAuthorities(userDetails.getAuthorities()), userDetails, assertion);
    } catch (final TicketValidationException e) {
        throw new BadCredentialsException(e.getMessage(), e);
    }
}
Also used : Assertion(org.jasig.cas.client.validation.Assertion) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) TicketValidationException(org.jasig.cas.client.validation.TicketValidationException)

Example 29 with Assertion

use of org.jasig.cas.client.validation.Assertion in project spring-security by spring-projects.

the class GrantedAuthorityFromAssertionAttributesUserDetailsServiceTests method correctlyExtractsNamedAttributesFromAssertionAndConvertsThemToAuthorities.

@Test
public void correctlyExtractsNamedAttributesFromAssertionAndConvertsThemToAuthorities() {
    GrantedAuthorityFromAssertionAttributesUserDetailsService uds = new GrantedAuthorityFromAssertionAttributesUserDetailsService(new String[] { "a", "b", "c", "d" });
    uds.setConvertToUpperCase(false);
    Assertion assertion = mock(Assertion.class);
    AttributePrincipal principal = mock(AttributePrincipal.class);
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("a", Arrays.asList("role_a1", "role_a2"));
    attributes.put("b", "role_b");
    attributes.put("c", "role_c");
    attributes.put("d", null);
    attributes.put("someother", "unused");
    when(assertion.getPrincipal()).thenReturn(principal);
    when(principal.getAttributes()).thenReturn(attributes);
    when(principal.getName()).thenReturn("somebody");
    CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, "ticket");
    UserDetails user = uds.loadUserDetails(token);
    Set<String> roles = AuthorityUtils.authorityListToSet(user.getAuthorities());
    assertThat(roles.size()).isEqualTo(4);
    assertThat(roles).contains("role_a1");
    assertThat(roles).contains("role_a2");
    assertThat(roles).contains("role_b");
    assertThat(roles).contains("role_c");
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) HashMap(java.util.HashMap) Assertion(org.jasig.cas.client.validation.Assertion) CasAssertionAuthenticationToken(org.springframework.security.cas.authentication.CasAssertionAuthenticationToken) AttributePrincipal(org.jasig.cas.client.authentication.AttributePrincipal) Test(org.junit.Test)

Example 30 with Assertion

use of org.jasig.cas.client.validation.Assertion in project ddf by codice.

the class CasHandler method getNormalizedToken.

@Override
public HandlerResult getNormalizedToken(ServletRequest request, ServletResponse response, FilterChain chain, boolean resolve) throws ServletException {
    // Default to NO_ACTION and set the source as this handler
    HandlerResult handlerResult = new HandlerResult(HandlerResult.Status.NO_ACTION, null);
    handlerResult.setSource(realm + "-" + SOURCE);
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String path = httpRequest.getServletPath();
    LOGGER.debug("Doing CAS authentication and authorization for path {}", path);
    // if the request contains the principal, return it
    Assertion assertion = getAssertion(httpRequest);
    try {
        if (resolve && assertion == null) {
            proxyFilter.doFilter(request, response, new ProxyFilterChain(null));
        }
    } catch (IOException e) {
        throw new ServletException(e);
    }
    if (assertion != null) {
        LOGGER.debug("Found previous CAS attribute, using that same session.");
        CASAuthenticationToken token = getAuthenticationToken(assertion);
        if (token != null) {
            handlerResult.setToken(token);
            handlerResult.setStatus(HandlerResult.Status.COMPLETED);
            //update cache with new information
            LOGGER.debug("Adding new CAS assertion for session {}", httpRequest.getSession(false).getId());
            httpRequest.getSession(false).setAttribute(AbstractCasFilter.CONST_CAS_ASSERTION, assertion);
            LOGGER.debug("Successfully set authentication token, returning result with token.");
        } else {
            LOGGER.debug("Could not create authentication token, returning NO_ACTION result.");
        }
    } else {
        if (resolve) {
            LOGGER.debug("Calling cas authentication and validation filters to perform redirects.");
            handlerResult.setStatus(HandlerResult.Status.REDIRECTED);
        } else {
            LOGGER.debug("No cas authentication information found and resolve is not enabled, returning NO_ACTION.");
        }
    }
    return handlerResult;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Assertion(org.jasig.cas.client.validation.Assertion) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) IOException(java.io.IOException) ProxyFilterChain(org.codice.ddf.security.handler.cas.filter.ProxyFilterChain)

Aggregations

Assertion (org.jasig.cas.client.validation.Assertion)41 AssertionImpl (org.jasig.cas.client.validation.AssertionImpl)14 Test (org.junit.Test)13 AttributePrincipal (org.jasig.cas.client.authentication.AttributePrincipal)10 HashMap (java.util.HashMap)5 TicketValidationException (org.jasig.cas.client.validation.TicketValidationException)5 MessageContext (org.opensaml.messaging.context.MessageContext)5 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)5 ZonedDateTime (java.time.ZonedDateTime)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)3 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)3 LinkedHashMap (java.util.LinkedHashMap)2 HttpSession (javax.servlet.http.HttpSession)2 SneakyThrows (lombok.SneakyThrows)2 Authentication (org.apereo.cas.authentication.Authentication)2 AttributePrincipalImpl (org.jasig.cas.client.authentication.AttributePrincipalImpl)2 Cas30ServiceTicketValidator (org.jasig.cas.client.validation.Cas30ServiceTicketValidator)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2