Search in sources :

Example 66 with Service

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

the class ConfirmConsentAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    final HttpServletRequest request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
    final Service service = this.authenticationRequestServiceSelectionStrategies.resolveService(WebUtils.getService(requestContext));
    final RegisteredService registeredService = getRegisteredServiceForConsent(requestContext, service);
    final Authentication authentication = WebUtils.getAuthentication(requestContext);
    final int optionValue = Integer.parseInt(request.getParameter("option"));
    final ConsentOptions option = ConsentOptions.valueOf(optionValue);
    final long reminder = Long.parseLong(request.getParameter("reminder"));
    final String reminderTimeUnit = request.getParameter("reminderTimeUnit");
    final ChronoUnit unit = ChronoUnit.valueOf(reminderTimeUnit.toUpperCase());
    consentEngine.storeConsentDecision(service, registeredService, authentication, reminder, unit, option);
    return new EventFactorySupport().success(this);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentOptions(org.apereo.cas.consent.ConsentOptions) RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) ChronoUnit(java.time.temporal.ChronoUnit)

Example 67 with Service

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

the class ImmutableAssertionTests method verifyGetService.

@Test
public void verifyGetService() {
    final Service service = RegisteredServiceTestUtils.getService();
    final List<Authentication> list = new ArrayList<>();
    list.add(CoreAuthenticationTestUtils.getAuthentication());
    final Assertion assertion = new ImmutableAssertion(CoreAuthenticationTestUtils.getAuthentication(), list, false, service);
    assertEquals(service, assertion.getService());
}
Also used : Authentication(org.apereo.cas.authentication.Authentication) ArrayList(java.util.ArrayList) Service(org.apereo.cas.authentication.principal.Service) Test(org.junit.Test)

Example 68 with Service

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

the class AnonymousRegisteredServiceUsernameAttributeProviderTests method verifyPrincipalResolution.

@Test
public void verifyPrincipalResolution() {
    final AnonymousRegisteredServiceUsernameAttributeProvider provider = new AnonymousRegisteredServiceUsernameAttributeProvider(new ShibbolethCompatiblePersistentIdGenerator(CASROX));
    final Service service = mock(Service.class);
    when(service.getId()).thenReturn("id");
    final Principal principal = mock(Principal.class);
    when(principal.getId()).thenReturn("uid");
    final String id = provider.resolveUsername(principal, service, RegisteredServiceTestUtils.getRegisteredService("id"));
    assertNotNull(id);
}
Also used : ShibbolethCompatiblePersistentIdGenerator(org.apereo.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator) Service(org.apereo.cas.authentication.principal.Service) Principal(org.apereo.cas.authentication.principal.Principal) Test(org.junit.Test)

Example 69 with Service

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

the class AbstractTicketRegistry method deleteChildren.

/**
 * Delete TGT's service tickets.
 *
 * @param ticket the ticket
 * @return the count of tickets that were removed including child tickets and zero if the ticket was not deleted
 */
protected int deleteChildren(final TicketGrantingTicket ticket) {
    final AtomicInteger count = new AtomicInteger(0);
    final Map<String, Service> services = ticket.getServices();
    if (services != null && !services.isEmpty()) {
        services.keySet().stream().forEach(ticketId -> {
            if (deleteSingleTicket(ticketId)) {
                LOGGER.debug("Removed ticket [{}]", ticketId);
                count.incrementAndGet();
            } else {
                LOGGER.debug("Unable to remove ticket [{}]", ticketId);
            }
        });
    }
    return count.intValue();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.apereo.cas.authentication.principal.Service)

Example 70 with Service

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

the class TicketGrantingTicketImplTests method verifyWebApplicationServices.

@Test
public void verifyWebApplicationServices() {
    final Service testService = RegisteredServiceTestUtils.getService(TGT_ID);
    final TicketGrantingTicket t = new TicketGrantingTicketImpl(TGT_ID, null, null, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
    t.grantServiceTicket(ID_GENERATOR.getNewTicketId(ServiceTicket.PREFIX), testService, new NeverExpiresExpirationPolicy(), false, true);
    Map<String, Service> services = t.getServices();
    assertEquals(1, services.size());
    final String ticketId = services.keySet().iterator().next();
    assertEquals(testService, services.get(ticketId));
    t.removeAllServices();
    services = t.getServices();
    assertEquals(0, services.size());
}
Also used : NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) Service(org.apereo.cas.authentication.principal.Service) Test(org.junit.Test)

Aggregations

Service (org.apereo.cas.authentication.principal.Service)173 RegisteredService (org.apereo.cas.services.RegisteredService)67 Test (org.junit.Test)61 Authentication (org.apereo.cas.authentication.Authentication)47 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)44 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)42 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)35 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)32 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)29 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)21 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)15 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)15 Credential (org.apereo.cas.authentication.Credential)13 Principal (org.apereo.cas.authentication.principal.Principal)13 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)12 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)12 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)12