Search in sources :

Example 1 with RegisteredServiceAccessStrategyAuditableEnforcer

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

the class RegisteredServiceAccessStrategyAuditableEnforcerTests method verifyStRejectedPrincipalAttributes.

@Test
public void verifyStRejectedPrincipalAttributes() {
    val service = createRegisteredService(true);
    ((DefaultRegisteredServiceAccessStrategy) service.getAccessStrategy()).setRejectedAttributes(reject(false));
    val context = AuditableContext.builder().registeredService(service).serviceTicket(createServiceTicket()).authenticationResult(createAuthenticationResult()).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) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) Test(org.junit.jupiter.api.Test)

Example 2 with RegisteredServiceAccessStrategyAuditableEnforcer

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

the class RegisteredServiceAccessStrategyAuditableEnforcerTests method verifyRejectedPrincipalAttributesNoFail.

@Test
public void verifyRejectedPrincipalAttributesNoFail() {
    val service = createRegisteredService(true);
    ((DefaultRegisteredServiceAccessStrategy) service.getAccessStrategy()).setRejectedAttributes(reject(true));
    val context = AuditableContext.builder().registeredService(service).service(createService()).authentication(createAuthentication()).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) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) Test(org.junit.jupiter.api.Test)

Example 3 with RegisteredServiceAccessStrategyAuditableEnforcer

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

the class RegisteredServiceAccessStrategyAuditableEnforcerTests method verifyRejectedPrincipalAttributes.

@Test
public void verifyRejectedPrincipalAttributes() {
    val service = createRegisteredService(true);
    ((DefaultRegisteredServiceAccessStrategy) service.getAccessStrategy()).setRejectedAttributes(reject(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) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) Test(org.junit.jupiter.api.Test)

Example 4 with RegisteredServiceAccessStrategyAuditableEnforcer

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

the class RegisteredServiceAccessStrategyAuditableEnforcerTests method verifyTgtRejectedPrincipalAttributesNoFail.

@Test
public void verifyTgtRejectedPrincipalAttributesNoFail() {
    val service = createRegisteredService(true);
    ((DefaultRegisteredServiceAccessStrategy) service.getAccessStrategy()).setRejectedAttributes(reject(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) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) Test(org.junit.jupiter.api.Test)

Example 5 with RegisteredServiceAccessStrategyAuditableEnforcer

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

the class RegisteredServiceAccessStrategyAuditableEnforcerTests method verifyGroovyScriptAccessStrategy.

@Test
public void verifyGroovyScriptAccessStrategy() {
    val service = createRegisteredService(true);
    val context = AuditableContext.builder().registeredService(service).build();
    val props = new CasConfigurationProperties();
    props.getAccessStrategy().getGroovy().setLocation(new ClassPathResource("GroovyAccessStrategy.groovy"));
    val result = new RegisteredServiceAccessStrategyAuditableEnforcer(props).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) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

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