Search in sources :

Example 66 with AuthenticationResult

use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketWithUsernameAttribute.

@Test
public void verifyValidateServiceTicketWithUsernameAttribute() {
    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)

Example 67 with AuthenticationResult

use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyGrantProxyTicketWithValidTicketGrantingTicket.

@Test
public void verifyGrantProxyTicketWithValidTicketGrantingTicket() {
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport());
    final TicketGrantingTicket ticketId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicketId = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), getService(), ctx);
    final AuthenticationResult ctx2 = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), RegisteredServiceTestUtils.getHttpBasedServiceCredentials());
    final TicketGrantingTicket pgt = getCentralAuthenticationService().createProxyGrantingTicket(serviceTicketId.getId(), ctx2);
    final ProxyTicket pt = getCentralAuthenticationService().grantProxyTicket(pgt.getId(), getService());
    assertTrue(pt.getId().startsWith(ProxyTicket.PROXY_TICKET_PREFIX));
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 68 with AuthenticationResult

use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyProxyGrantingTicketHasRootAuthenticationAsPrincipal.

@Test
public void verifyProxyGrantingTicketHasRootAuthenticationAsPrincipal() {
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), getService());
    final TicketGrantingTicket ticket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicketId = getCentralAuthenticationService().grantServiceTicket(ticket.getId(), getService(), ctx);
    final AbstractWebApplicationService service = AbstractWebApplicationService.class.cast(serviceTicketId.getService());
    assertEquals(service.getPrincipal(), ticket.getAuthentication().getPrincipal().getId());
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 69 with AuthenticationResult

use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyGrantServiceTicketWithCredsAndSsoFalse.

@Test
public void verifyGrantServiceTicketWithCredsAndSsoFalse() {
    final Service svc = getService("TestSsoFalse");
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), svc);
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(), svc, ctx);
    assertNotNull(serviceTicket);
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) 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 70 with AuthenticationResult

use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyGrantServiceTicketPassesAuthzRule.

@Test
public void verifyGrantServiceTicketPassesAuthzRule() {
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), getService("TestServiceAttributeForAuthzPasses"));
    final TicketGrantingTicket ticketId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), getService("TestServiceAttributeForAuthzPasses"), ctx);
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Aggregations

AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)92 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)66 Test (org.junit.Test)66 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)47 Service (org.apereo.cas.authentication.principal.Service)41 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)21 Authentication (org.apereo.cas.authentication.Authentication)17 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)16 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)15 Credential (org.apereo.cas.authentication.Credential)13 Assertion (org.apereo.cas.validation.Assertion)12 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)9 RegisteredService (org.apereo.cas.services.RegisteredService)8 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 AuthenticationResultBuilder (org.apereo.cas.authentication.AuthenticationResultBuilder)5 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4