Search in sources :

Example 21 with TicketGrantingTicket

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

the class MultifactorAuthenticationTests method verifyDeniesAccessToHighSecurityServiceWithPassword.

@Test
public void verifyDeniesAccessToHighSecurityServiceWithPassword() throws Exception {
    final AuthenticationResult ctx = processAuthenticationAttempt(HIGH_SERVICE, newUserPassCredentials(ALICE, ALICE));
    this.thrown.expect(UnsatisfiedAuthenticationPolicyException.class);
    final TicketGrantingTicket tgt = cas.createTicketGrantingTicket(ctx);
    assertNotNull(tgt);
    cas.grantServiceTicket(tgt.getId(), HIGH_SERVICE, ctx);
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with TicketGrantingTicket

use of org.apereo.cas.ticket.TicketGrantingTicket 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 23 with TicketGrantingTicket

use of org.apereo.cas.ticket.TicketGrantingTicket 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 24 with TicketGrantingTicket

use of org.apereo.cas.ticket.TicketGrantingTicket 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)

Example 25 with TicketGrantingTicket

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

the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketWithInvalidServiceTicket.

@Test
public void verifyValidateServiceTicketWithInvalidServiceTicket() throws Exception {
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), getService());
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(), getService(), ctx);
    getCentralAuthenticationService().destroyTicketGrantingTicket(ticketGrantingTicket.getId());
    this.thrown.expect(AbstractTicketException.class);
    getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(), getService());
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Aggregations

TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)113 Test (org.junit.Test)88 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)61 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)59 Service (org.apereo.cas.authentication.principal.Service)34 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)25 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)23 Authentication (org.apereo.cas.authentication.Authentication)19 Credential (org.apereo.cas.authentication.Credential)19 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)18 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)15 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)12 Assertion (org.apereo.cas.validation.Assertion)12 HttpBasedServiceCredential (org.apereo.cas.authentication.HttpBasedServiceCredential)11 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)11 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)11 MockServletContext (org.springframework.mock.web.MockServletContext)10 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)8