Search in sources :

Example 11 with ServiceTicket

use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.

the class CentralAuthenticationServiceImplWithMockitoTests method verifyChainedAuthenticationsOnValidation.

@Test
public void verifyChainedAuthenticationsOnValidation() throws Exception {
    final Service svc = RegisteredServiceTestUtils.getService(SVC2_ID);
    final ServiceTicket st = this.cas.grantServiceTicket(TGT2_ID, svc, getAuthenticationContext());
    assertNotNull(st);
    final Assertion assertion = this.cas.validateServiceTicket(st.getId(), svc);
    assertNotNull(assertion);
    assertEquals(assertion.getService(), svc);
    assertEquals(assertion.getPrimaryAuthentication().getPrincipal().getId(), PRINCIPAL);
    assertSame(2, assertion.getChainedAuthentications().size());
    IntStream.range(0, assertion.getChainedAuthentications().size()).forEach(i -> assertEquals(assertion.getChainedAuthentications().get(i), authentication));
}
Also used : Assertion(org.apereo.cas.validation.Assertion) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Test(org.junit.Test)

Example 12 with ServiceTicket

use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.

the class MultifactorAuthenticationTests method verifyAllowsAccessToNormalSecurityServiceWithPassword.

@Test
public void verifyAllowsAccessToNormalSecurityServiceWithPassword() throws Exception {
    final AuthenticationResult ctx = processAuthenticationAttempt(NORMAL_SERVICE, newUserPassCredentials(ALICE, ALICE));
    final TicketGrantingTicket tgt = cas.createTicketGrantingTicket(ctx);
    assertNotNull(tgt);
    final ServiceTicket st = cas.grantServiceTicket(tgt.getId(), NORMAL_SERVICE, ctx);
    assertNotNull(st);
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with ServiceTicket

use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.

the class MultifactorAuthenticationTests method verifyAllowsAccessToNormalSecurityServiceWithOTP.

@Test
public void verifyAllowsAccessToNormalSecurityServiceWithOTP() throws Exception {
    final AuthenticationResult ctx = processAuthenticationAttempt(NORMAL_SERVICE, new OneTimePasswordCredential(ALICE, PASSWORD_31415));
    final TicketGrantingTicket tgt = cas.createTicketGrantingTicket(ctx);
    assertNotNull(tgt);
    final ServiceTicket st = cas.grantServiceTicket(tgt.getId(), NORMAL_SERVICE, ctx);
    assertNotNull(st);
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) OneTimePasswordCredential(org.apereo.cas.authentication.OneTimePasswordCredential) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with ServiceTicket

use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketNoAttributesReturned.

@Test
public void verifyValidateServiceTicketNoAttributesReturned() throws Exception {
    final Service service = getService();
    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(0, 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 15 with ServiceTicket

use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketWithInvalidUsernameAttribute.

@Test
public void verifyValidateServiceTicketWithInvalidUsernameAttribute() throws Exception {
    final Service svc = getService("eduPersonTestInvalid");
    final UsernamePasswordCredential cred = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    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);
    final Authentication auth = assertion.getPrimaryAuthentication();
    /*
         * The attribute specified for this service does not resolve.
         * Therefore, we expect the default to be returned.
         */
    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) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Aggregations

ServiceTicket (org.apereo.cas.ticket.ServiceTicket)70 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)59 Test (org.junit.Test)53 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)45 Service (org.apereo.cas.authentication.principal.Service)32 Authentication (org.apereo.cas.authentication.Authentication)17 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)14 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)12 Assertion (org.apereo.cas.validation.Assertion)12 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)12 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)10 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 Credential (org.apereo.cas.authentication.Credential)9 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)8 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)8 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 RegisteredService (org.apereo.cas.services.RegisteredService)6 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)6