Search in sources :

Example 16 with Assertion

use of org.apereo.cas.validation.Assertion in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketReturnAllAttributes.

@Test
public void verifyValidateServiceTicketReturnAllAttributes() throws Exception {
    final Service service = getService("eduPersonTest");
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), service);
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(), service, ctx);
    final Assertion assertion = getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(), service);
    final Authentication auth = assertion.getPrimaryAuthentication();
    assertEquals(4, auth.getPrincipal().getAttributes().size());
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Authentication(org.apereo.cas.authentication.Authentication) Assertion(org.apereo.cas.validation.Assertion) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 17 with Assertion

use of org.apereo.cas.validation.Assertion in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketWithoutUsernameAttribute.

@Test
public void verifyValidateServiceTicketWithoutUsernameAttribute() throws Exception {
    final UsernamePasswordCredential cred = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), getService());
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(), getService(), ctx);
    final Assertion assertion = getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(), getService());
    final Authentication auth = assertion.getPrimaryAuthentication();
    assertEquals(auth.getPrincipal().getId(), cred.getUsername());
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Authentication(org.apereo.cas.authentication.Authentication) Assertion(org.apereo.cas.validation.Assertion) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 18 with Assertion

use of org.apereo.cas.validation.Assertion in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketWithUsernameAttribute.

@Test
public void verifyValidateServiceTicketWithUsernameAttribute() throws Exception {
    final Service svc = getService("eduPersonTest");
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), svc);
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(), svc, ctx);
    final Assertion assertion = getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(), svc);
    assertEquals("developer", assertion.getPrimaryAuthentication().getPrincipal().getId());
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Assertion(org.apereo.cas.validation.Assertion) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Aggregations

Assertion (org.apereo.cas.validation.Assertion)18 Test (org.junit.Test)14 Authentication (org.apereo.cas.authentication.Authentication)12 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)12 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)12 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)10 Service (org.apereo.cas.authentication.principal.Service)10 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)8 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)5 HashMap (java.util.HashMap)4 Principal (org.apereo.cas.authentication.principal.Principal)4 ImmutableAssertion (org.apereo.cas.validation.ImmutableAssertion)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 RegisteredService (org.apereo.cas.services.RegisteredService)2 AbstractTicketException (org.apereo.cas.ticket.AbstractTicketException)2 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)2 Counted (com.codahale.metrics.annotation.Counted)1 Metered (com.codahale.metrics.annotation.Metered)1