Search in sources :

Example 21 with DefaultAuthenticationServiceSelectionStrategy

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy in project cas by apereo.

the class DefaultSingleSignOnParticipationStrategyTests method verifyDoesNotParticipateForService.

@Test
public void verifyDoesNotParticipateForService() {
    val mgr = mock(ServicesManager.class);
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
    when(registeredService.getAccessStrategy().isServiceAccessAllowedForSso()).thenReturn(false);
    when(mgr.findServiceBy(any(Service.class))).thenReturn(registeredService);
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
    val plan = new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy());
    val sso = new SingleSignOnProperties().setCreateSsoCookieOnRenewAuthn(false).setRenewAuthnEnabled(true);
    val strategy = new DefaultSingleSignOnParticipationStrategy(mgr, sso, mock(TicketRegistrySupport.class), plan);
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication("casuser"), context);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertFalse(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Service(org.apereo.cas.authentication.principal.Service) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) SingleSignOnProperties(org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties) Test(org.junit.jupiter.api.Test)

Example 22 with DefaultAuthenticationServiceSelectionStrategy

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy 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)

Example 23 with DefaultAuthenticationServiceSelectionStrategy

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy in project cas by apereo.

the class DefaultSingleLogoutServiceMessageHandlerTests method verifyEmpty.

@Test
public void verifyEmpty() {
    val servicesManager = mock(ServicesManager.class);
    val service = new RegexRegisteredService();
    service.setServiceId(UUID.randomUUID().toString());
    when(servicesManager.findServiceBy(any(Service.class))).thenReturn(service);
    val handler = new DefaultSingleLogoutServiceMessageHandler(new SimpleHttpClientFactoryBean().getObject(), new DefaultSingleLogoutMessageCreator(), servicesManager, new DefaultSingleLogoutServiceLogoutUrlBuilder(servicesManager, mock(UrlValidator.class)), false, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    assertTrue(handler.handle(CoreAuthenticationTestUtils.getWebApplicationService(), UUID.randomUUID().toString(), SingleLogoutExecutionRequest.builder().build()).isEmpty());
}
Also used : lombok.val(lombok.val) SimpleHttpClientFactoryBean(org.apereo.cas.util.http.SimpleHttpClientFactoryBean) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) DefaultSingleLogoutServiceMessageHandler(org.apereo.cas.logout.slo.DefaultSingleLogoutServiceMessageHandler) DefaultSingleLogoutServiceLogoutUrlBuilder(org.apereo.cas.logout.slo.DefaultSingleLogoutServiceLogoutUrlBuilder) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) Service(org.apereo.cas.authentication.principal.Service) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) Test(org.junit.jupiter.api.Test)

Example 24 with DefaultAuthenticationServiceSelectionStrategy

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy in project cas by apereo.

the class ServiceAuthorizationCheckMockitoActionTests method verifyEmptyRegistry.

@Test
public void verifyEmptyRegistry() {
    val mockRequestContext = new MockRequestContext();
    WebUtils.putServiceIntoFlowScope(mockRequestContext, RegisteredServiceTestUtils.getService());
    when(servicesManager.getAllServices()).thenReturn(List.of());
    val action = new ServiceAuthorizationCheckAction(servicesManager, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    assertThrows(UnauthorizedServiceException.class, () -> action.execute(mockRequestContext));
}
Also used : lombok.val(lombok.val) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test)

Example 25 with DefaultAuthenticationServiceSelectionStrategy

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy in project cas by apereo.

the class ServiceAuthorizationCheckMockitoActionTests method getAction.

private Action getAction() {
    val authorizedRegisteredService = new RegexRegisteredService();
    val unauthorizedRegisteredService = new RegexRegisteredService();
    unauthorizedRegisteredService.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(false, false));
    val list = new ArrayList<RegisteredService>();
    list.add(authorizedRegisteredService);
    list.add(unauthorizedRegisteredService);
    when(this.servicesManager.findServiceBy(this.authorizedService)).thenReturn(authorizedRegisteredService);
    when(this.servicesManager.findServiceBy(this.unauthorizedService)).thenReturn(unauthorizedRegisteredService);
    when(this.servicesManager.findServiceBy(this.undefinedService)).thenReturn(null);
    when(this.servicesManager.getAllServices()).thenReturn(list);
    return new ServiceAuthorizationCheckAction(this.servicesManager, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
}
Also used : lombok.val(lombok.val) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) ArrayList(java.util.ArrayList) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy)

Aggregations

DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)25 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)25 lombok.val (lombok.val)19 Test (org.junit.jupiter.api.Test)13 DefaultAuthenticationTransactionFactory (org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory)9 RegisteredServiceAuthenticationPolicyResolver (org.apereo.cas.authentication.policy.RegisteredServiceAuthenticationPolicyResolver)7 Service (org.apereo.cas.authentication.principal.Service)7 Before (org.junit.Before)5 HashMap (java.util.HashMap)4 RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)4 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)4 URL (java.net.URL)3 HashSet (java.util.HashSet)3 AuditableExecutionResult (org.apereo.cas.audit.AuditableExecutionResult)3 SimpleUrlValidatorFactoryBean (org.apereo.cas.web.SimpleUrlValidatorFactoryBean)3 MockRequestContext (org.springframework.webflow.test.MockRequestContext)3 ArrayList (java.util.ArrayList)2