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));
}
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()));
}
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());
}
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));
}
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()));
}
Aggregations