Search in sources :

Example 1 with Service

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

the class AbstractServicesManager method load.

/**
 * For the duration of the read, the cache store should not remain empty.
 * Otherwise, lookup operations during that loading time window might produce
 * unauthorized failure errors. Invalidation attempts must happen after the load
 * to minimize chances of failures.
 */
@Override
public synchronized Collection<RegisteredService> load() {
    LOGGER.trace("Loading services from [{}]", configurationContext.getServiceRegistry().getName());
    val servicesMap = configurationContext.getServiceRegistry().load().stream().filter(this::supports).filter(this::validateAndFilterServiceByEnvironment).peek(this::loadInternal).collect(Collectors.toMap(r -> {
        LOGGER.trace("Adding registered service [{}] with name [{}] and internal identifier [{}]", r.getServiceId(), r.getName(), r.getId());
        return r.getId();
    }, Function.identity(), (r, s) -> s));
    configurationContext.getServicesCache().invalidateAll();
    configurationContext.getServicesCache().putAll(servicesMap);
    loadInternal();
    publishEvent(new CasRegisteredServicesLoadedEvent(this, getAllServices()));
    evaluateExpiredServiceDefinitions();
    LOGGER.info("Loaded [{}] service(s) from [{}].", configurationContext.getServicesCache().asMap().size(), configurationContext.getServiceRegistry().getName());
    return configurationContext.getServicesCache().asMap().values();
}
Also used : lombok.val(lombok.val) Getter(lombok.Getter) Predicate(java.util.function.Predicate) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) CasRegisteredServiceExpiredEvent(org.apereo.cas.support.events.service.CasRegisteredServiceExpiredEvent) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) CasRegisteredServicePreDeleteEvent(org.apereo.cas.support.events.service.CasRegisteredServicePreDeleteEvent) CasRegisteredServicesDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServicesDeletedEvent) ApplicationEvent(org.springframework.context.ApplicationEvent) Consumer(java.util.function.Consumer) Slf4j(lombok.extern.slf4j.Slf4j) AccessLevel(lombok.AccessLevel) Stream(java.util.stream.Stream) Service(org.apereo.cas.authentication.principal.Service) Optional(java.util.Optional) CasRegisteredServiceSavedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent) CasRegisteredServicePreSaveEvent(org.apereo.cas.support.events.service.CasRegisteredServicePreSaveEvent) CasRegisteredServicesLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServicesLoadedEvent) CasRegisteredServicesLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServicesLoadedEvent)

Example 2 with Service

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

the class DefaultCasAttributeEncoderTests method checkAttributesEncodedCorrectly.

@Test
public void checkAttributesEncodedCorrectly() {
    final Service service = RegisteredServiceTestUtils.getService("testencryption");
    final ProtocolAttributeEncoder encoder = new DefaultCasProtocolAttributeEncoder(this.servicesManager, NoOpCipherExecutor.getInstance());
    final Map<String, Object> encoded = encoder.encodeAttributes(this.attributes, this.servicesManager.findServiceBy(service));
    assertEquals(encoded.size(), this.attributes.size());
    checkEncryptedValues(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL_CREDENTIAL, encoded);
    checkEncryptedValues(CasViewConstants.MODEL_ATTRIBUTE_NAME_PROXY_GRANTING_TICKET, encoded);
}
Also used : Service(org.apereo.cas.authentication.principal.Service) ProtocolAttributeEncoder(org.apereo.cas.authentication.ProtocolAttributeEncoder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Service

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

the class DefaultCasAttributeEncoderTests method checkNoPublicKeyDefined.

@Test
public void checkNoPublicKeyDefined() {
    final Service service = RegisteredServiceTestUtils.getService("testDefault");
    final ProtocolAttributeEncoder encoder = new DefaultCasProtocolAttributeEncoder(this.servicesManager, NoOpCipherExecutor.getInstance());
    final Map<String, Object> encoded = encoder.encodeAttributes(this.attributes, this.servicesManager.findServiceBy(service));
    assertEquals(encoded.size(), this.attributes.size() - 2);
}
Also used : Service(org.apereo.cas.authentication.principal.Service) ProtocolAttributeEncoder(org.apereo.cas.authentication.ProtocolAttributeEncoder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Service

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

the class LogoutManagerImpl method performLogoutForTicket.

private void performLogoutForTicket(final TicketGrantingTicket ticket, final List<LogoutRequest> logoutRequests) {
    ticket.getServices().entrySet().stream().filter(entry -> entry.getValue() instanceof WebApplicationService).forEach(entry -> {
        final Service service = entry.getValue();
        LOGGER.debug("Handling single logout callback for [{}]", service);
        final LogoutRequest logoutRequest = this.singleLogoutServiceMessageHandler.handle((WebApplicationService) service, entry.getKey());
        if (logoutRequest != null) {
            LOGGER.debug("Captured logout request [{}]", logoutRequest);
            logoutRequests.add(logoutRequest);
        }
    });
    final Collection<ProxyGrantingTicket> proxyGrantingTickets = ticket.getProxyGrantingTickets();
    if (proxyGrantingTickets.isEmpty()) {
        LOGGER.debug("There are no proxy-granting tickets associated with [{}] to process for single logout", ticket.getId());
    } else {
        proxyGrantingTickets.forEach(proxyGrantingTicket -> performLogoutForTicket(proxyGrantingTicket, logoutRequests));
    }
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) List(java.util.List) Logger(org.slf4j.Logger) Service(org.apereo.cas.authentication.principal.Service) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) CompressionUtils(org.apereo.cas.util.CompressionUtils) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Collections(java.util.Collections) ArrayList(java.util.ArrayList) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Service(org.apereo.cas.authentication.principal.Service) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket)

Example 5 with Service

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

the class DefaultServicesManagerTests method verifyMatchesExistingService.

@Test
public void verifyMatchesExistingService() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setId(1000);
    r.setName(TEST);
    r.setServiceId(TEST);
    final Service service = new SimpleService(TEST);
    final Service service2 = new SimpleService("fdfa");
    this.defaultServicesManager.save(r);
    assertTrue(this.defaultServicesManager.matchesExistingService(service));
    assertEquals(r, this.defaultServicesManager.findServiceBy(service));
    assertNull(this.defaultServicesManager.findServiceBy(service2));
}
Also used : Service(org.apereo.cas.authentication.principal.Service) 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