Search in sources :

Example 21 with RegisteredServiceAccessStrategyAuditableEnforcer

use of org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer in project cas by apereo.

the class RegisteredServiceAccessStrategyAuditableEnforcerTests method verifyAuthAndServiceAndRegisteredServicePresentButDisabled.

@Test
public void verifyAuthAndServiceAndRegisteredServicePresentButDisabled() {
    val service = createRegisteredService(false);
    val context = AuditableContext.builder().registeredService(service).service(createService()).authentication(createAuthentication()).build();
    val result = new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties()).execute(context);
    assertTrue(result.isExecutionFailure());
    assertTrue(result.getException().isPresent());
}
Also used : lombok.val(lombok.val) RegisteredServiceAccessStrategyAuditableEnforcer(org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Test(org.junit.jupiter.api.Test)

Example 22 with RegisteredServiceAccessStrategyAuditableEnforcer

use of org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer in project cas by apereo.

the class RegisteredServiceAccessStrategyAuditableEnforcerTests method verifyRegisteredServicePresentAndEnabled.

@Test
public void verifyRegisteredServicePresentAndEnabled() {
    val service = createRegisteredService(true);
    val context = AuditableContext.builder().registeredService(service).build();
    val result = new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties()).execute(context);
    assertFalse(result.isExecutionFailure());
    assertFalse(result.getException().isPresent());
}
Also used : lombok.val(lombok.val) RegisteredServiceAccessStrategyAuditableEnforcer(org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Test(org.junit.jupiter.api.Test)

Example 23 with RegisteredServiceAccessStrategyAuditableEnforcer

use of org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer in project cas by apereo.

the class RegisteredServiceAccessStrategyAuditableEnforcerTests method verifyServiceAndRegisteredServicePresentButDisabled.

@Test
public void verifyServiceAndRegisteredServicePresentButDisabled() {
    val service = createRegisteredService(false);
    val context = AuditableContext.builder().registeredService(service).service(createService()).build();
    val result = new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties()).execute(context);
    assertTrue(result.isExecutionFailure());
    assertTrue(result.getException().isPresent());
}
Also used : lombok.val(lombok.val) RegisteredServiceAccessStrategyAuditableEnforcer(org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Test(org.junit.jupiter.api.Test)

Example 24 with RegisteredServiceAccessStrategyAuditableEnforcer

use of org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer in project cas by apereo.

the class RegisteredServiceAccessStrategyAuditableEnforcerTests method verifyTgtAndServiceAndRegisteredServicePresentAndEnabled.

@Test
public void verifyTgtAndServiceAndRegisteredServicePresentAndEnabled() {
    val service = createRegisteredService(true);
    val context = AuditableContext.builder().registeredService(service).service(createService()).ticketGrantingTicket(createTicketGrantingTicket()).build();
    val result = new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties()).execute(context);
    assertFalse(result.isExecutionFailure());
    assertFalse(result.getException().isPresent());
}
Also used : lombok.val(lombok.val) RegisteredServiceAccessStrategyAuditableEnforcer(org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Test(org.junit.jupiter.api.Test)

Example 25 with RegisteredServiceAccessStrategyAuditableEnforcer

use of org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer in project cas by apereo.

the class RegisteredServiceResponseHeadersEnforcementFilterTests method getFilterForProperty.

private static RegisteredServiceResponseHeadersEnforcementFilter getFilterForProperty(final Pair<RegisteredServiceProperties, String>... properties) {
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val context = ServicesManagerConfigurationContext.builder().serviceRegistry(new InMemoryServiceRegistry(appCtx)).applicationContext(appCtx).environments(new HashSet<>(0)).servicesCache(Caffeine.newBuilder().build()).registeredServiceLocators(List.of(new DefaultServicesManagerRegisteredServiceLocator())).build();
    val servicesManager = new DefaultServicesManager(context);
    val argumentExtractor = new DefaultArgumentExtractor(new WebApplicationServiceFactory());
    val service = RegisteredServiceTestUtils.getRegisteredService("service-0");
    val props1 = new LinkedHashMap<String, RegisteredServiceProperty>();
    for (val p : properties) {
        val prop1 = new DefaultRegisteredServiceProperty();
        prop1.addValue(p.getValue());
        props1.put(p.getKey().getPropertyName(), prop1);
    }
    service.setProperties(props1);
    servicesManager.save(service);
    return new RegisteredServiceResponseHeadersEnforcementFilter(servicesManager, argumentExtractor, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()), new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties()));
}
Also used : lombok.val(lombok.val) RegisteredServiceAccessStrategyAuditableEnforcer(org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) RegisteredServiceResponseHeadersEnforcementFilter(org.apereo.cas.services.web.support.RegisteredServiceResponseHeadersEnforcementFilter) DefaultServicesManagerRegisteredServiceLocator(org.apereo.cas.services.DefaultServicesManagerRegisteredServiceLocator) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) LinkedHashMap(java.util.LinkedHashMap) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) DefaultArgumentExtractor(org.apereo.cas.web.support.DefaultArgumentExtractor) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) DefaultServicesManager(org.apereo.cas.services.DefaultServicesManager) HashSet(java.util.HashSet)

Aggregations

lombok.val (lombok.val)25 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)25 RegisteredServiceAccessStrategyAuditableEnforcer (org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer)25 Test (org.junit.jupiter.api.Test)22 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)6 DefaultRegisteredServiceAccessStrategy (org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy)6 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)4 JEEContext (org.pac4j.core.context.JEEContext)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 BeforeEach (org.junit.jupiter.api.BeforeEach)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)1 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)1 DefaultRegisteredServiceProperty (org.apereo.cas.services.DefaultRegisteredServiceProperty)1 DefaultServicesManager (org.apereo.cas.services.DefaultServicesManager)1 DefaultServicesManagerRegisteredServiceLocator (org.apereo.cas.services.DefaultServicesManagerRegisteredServiceLocator)1 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)1 RegisteredServiceResponseHeadersEnforcementFilter (org.apereo.cas.services.web.support.RegisteredServiceResponseHeadersEnforcementFilter)1