Search in sources :

Example 36 with Service

use of org.apereo.cas.authentication.principal.Service in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyGrantingOfServiceTicketUsingDefaultTicketIdGen.

@Test
public void verifyGrantingOfServiceTicketUsingDefaultTicketIdGen() {
    final Service mockService = RegisteredServiceTestUtils.getService("testDefault");
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), mockService);
    final TicketGrantingTicket ticketId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicketId = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), mockService, ctx);
    assertNotNull(serviceTicketId);
}
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 37 with Service

use of org.apereo.cas.authentication.principal.Service in project cas by apereo.

the class CentralAuthenticationServiceImplWithMockitoTests method verifyChainedAuthenticationsOnValidation.

@Test
public void verifyChainedAuthenticationsOnValidation() {
    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(PRINCIPAL, assertion.getPrimaryAuthentication().getPrincipal().getId());
    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) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 38 with Service

use of org.apereo.cas.authentication.principal.Service in project cas by apereo.

the class GatewayServicesManagementCheck method doExecute.

@Override
protected Event doExecute(final RequestContext context) {
    final Service service = WebUtils.getService(context);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
    if (registeredService == null) {
        final String msg = String.format("Service Management: Unauthorized Service Access. " + "Service [%s] does not match entries in service registry.", service.getId());
        LOGGER.warn(msg);
        throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, msg);
    }
    if (!registeredService.getAccessStrategy().isServiceAccessAllowed()) {
        final String msg = String.format("Service Management: Access to service [%s] " + "is disabled by the service registry.", service.getId());
        LOGGER.warn(msg);
        WebUtils.putUnauthorizedRedirectUrlIntoFlowScope(context, registeredService.getAccessStrategy().getUnauthorizedRedirectUrl());
        throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, msg);
    }
    return success();
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) RegisteredService(org.apereo.cas.services.RegisteredService) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException)

Example 39 with Service

use of org.apereo.cas.authentication.principal.Service in project cas by apereo.

the class RestConsentRepositoryTests method verifyConsentDecisionIsFound.

@Test
public void verifyConsentDecisionIsFound() throws Exception {
    final ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
    final DefaultConsentDecisionBuilder builder = new DefaultConsentDecisionBuilder(CipherExecutor.noOpOfSerializableToString());
    final AbstractRegisteredService regSvc = RegisteredServiceTestUtils.getRegisteredService("test");
    final Service svc = RegisteredServiceTestUtils.getService();
    final ConsentDecision decision = builder.build(svc, regSvc, "casuser", CollectionUtils.wrap("attribute", "value"));
    final String body = mapper.writeValueAsString(decision);
    server.expect(manyTimes(), requestTo("/consent")).andExpect(method(HttpMethod.GET)).andRespond(withSuccess(body, MediaType.APPLICATION_JSON));
    final RestConsentRepository repo = new RestConsentRepository(this.restTemplate, "/consent");
    final ConsentDecision d = repo.findConsentDecision(svc, regSvc, CoreAuthenticationTestUtils.getAuthentication());
    assertNotNull(d);
    assertEquals("casuser", d.getPrincipal());
    server.verify();
}
Also used : AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Service(org.apereo.cas.authentication.principal.Service) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 40 with Service

use of org.apereo.cas.authentication.principal.Service in project cas by apereo.

the class AbstractTicketRegistryTests method verifyDeleteTicketWithChildren.

@Test
public void verifyDeleteTicketWithChildren() {
    try {
        this.ticketRegistry.addTicket(new TicketGrantingTicketImpl(TicketGrantingTicket.PREFIX + "1", CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
        final TicketGrantingTicket tgt = this.ticketRegistry.getTicket(TicketGrantingTicket.PREFIX + "1", TicketGrantingTicket.class);
        final Service service = RegisteredServiceTestUtils.getService("TGT_DELETE_TEST");
        final ServiceTicket st1 = tgt.grantServiceTicket("ST11", service, new NeverExpiresExpirationPolicy(), false, false);
        final ServiceTicket st2 = tgt.grantServiceTicket("ST21", service, new NeverExpiresExpirationPolicy(), false, false);
        final ServiceTicket st3 = tgt.grantServiceTicket("ST31", service, new NeverExpiresExpirationPolicy(), false, false);
        this.ticketRegistry.addTicket(st1);
        this.ticketRegistry.addTicket(st2);
        this.ticketRegistry.addTicket(st3);
        assertNotNull(this.ticketRegistry.getTicket(TicketGrantingTicket.PREFIX + "1", TicketGrantingTicket.class));
        assertNotNull(this.ticketRegistry.getTicket("ST11", ServiceTicket.class));
        assertNotNull(this.ticketRegistry.getTicket("ST21", ServiceTicket.class));
        assertNotNull(this.ticketRegistry.getTicket("ST31", ServiceTicket.class));
        this.ticketRegistry.updateTicket(tgt);
        assertSame(4, this.ticketRegistry.deleteTicket(tgt.getId()));
        assertNull(this.ticketRegistry.getTicket(TicketGrantingTicket.PREFIX + "1", TicketGrantingTicket.class));
        assertNull(this.ticketRegistry.getTicket("ST11", ServiceTicket.class));
        assertNull(this.ticketRegistry.getTicket("ST21", ServiceTicket.class));
        assertNull(this.ticketRegistry.getTicket("ST31", ServiceTicket.class));
    } catch (final Exception e) {
        throw new AssertionError(CAUGHT_AN_EXCEPTION_BUT_WAS_NOT_EXPECTED + e.getMessage(), e);
    }
}
Also used : NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Service(org.apereo.cas.authentication.principal.Service) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Test(org.junit.Test)

Aggregations

Service (org.apereo.cas.authentication.principal.Service)162 lombok.val (lombok.val)54 RegisteredService (org.apereo.cas.services.RegisteredService)53 Authentication (org.apereo.cas.authentication.Authentication)44 Test (org.junit.Test)36 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)34 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)31 Slf4j (lombok.extern.slf4j.Slf4j)30 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)26 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)25 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)25 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)25 Test (org.junit.jupiter.api.Test)25 Optional (java.util.Optional)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)23 StringUtils (org.apache.commons.lang3.StringUtils)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)17 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)17 HashMap (java.util.HashMap)16