Search in sources :

Example 6 with RegexRegisteredService

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

the class ManageRegisteredServicesMultiActionControllerTests method verifyCustomComponents.

@Test
public void verifyCustomComponents() throws Exception {
    // override the RegisteredServiceMapper
    this.registeredServiceFactory = new DefaultRegisteredServiceFactory(new DefaultAccessStrategyMapper(), policyMapper, new DefaultProxyPolicyMapper(), new CustomRegisteredServiceMapper(), new DefaultUsernameAttributeProviderMapper(), Collections.emptyList());
    this.controller = new ManageRegisteredServicesMultiActionController(this.servicesManager, this.registeredServiceFactory, new WebApplicationServiceFactory(), "https://cas.example.org");
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setId(1200);
    r.setName(NAME);
    r.setDescription(UNIQUE_DESCRIPTION);
    r.setServiceId("test");
    r.setEvaluationOrder(2);
    this.servicesManager.save(r);
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final ModelAndView mv = this.controller.manage(response);
    assertTrue(mv.getModel().containsKey("defaultServiceUrl"));
    assertTrue(mv.getModel().containsKey("status"));
    this.controller.getServices(response);
    final String content = response.getContentAsString();
    assertTrue(content.contains(SERVICES));
    assertTrue(content.contains(UNIQUE_DESCRIPTION));
    assertTrue(content.contains("customComponent1"));
    assertTrue(content.contains("key2"));
}
Also used : WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) ModelAndView(org.springframework.web.servlet.ModelAndView) DefaultAccessStrategyMapper(org.apereo.cas.mgmt.services.web.factory.DefaultAccessStrategyMapper) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) DefaultRegisteredServiceFactory(org.apereo.cas.mgmt.services.web.factory.DefaultRegisteredServiceFactory) DefaultProxyPolicyMapper(org.apereo.cas.mgmt.services.web.factory.DefaultProxyPolicyMapper) DefaultUsernameAttributeProviderMapper(org.apereo.cas.mgmt.services.web.factory.DefaultUsernameAttributeProviderMapper) ManageRegisteredServicesMultiActionController(org.apereo.cas.mgmt.services.web.ManageRegisteredServicesMultiActionController) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 7 with RegexRegisteredService

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

the class BaseWSFederationRequestController method registerCallback.

/**
     * Register callback service.
     *
     * @param callbackUrl the callback url
     * @return the service
     */
private Service registerCallback(final String callbackUrl) {
    final Service callbackService = this.webApplicationServiceFactory.createService(callbackUrl);
    if (!this.servicesManager.matchesExistingService(callbackService)) {
        LOGGER.debug("Initializing callback service [{}]", callbackService);
        final RegexRegisteredService service = new RegexRegisteredService();
        service.setId(Math.abs(new SecureRandom().nextLong()));
        service.setEvaluationOrder(0);
        service.setName(service.getClass().getSimpleName());
        service.setDescription("WS-Federation Authentication Request");
        service.setServiceId(callbackService.getId().concat(".+"));
        LOGGER.debug("Saving callback service [{}] into the registry", service);
        this.servicesManager.save(service);
        this.servicesManager.load();
    }
    return callbackService;
}
Also used : RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) WSFederationRegisteredService(org.apereo.cas.ws.idp.services.WSFederationRegisteredService) Service(org.apereo.cas.authentication.principal.Service) SecureRandom(java.security.SecureRandom) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService)

Example 8 with RegexRegisteredService

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

the class RegisteredServiceSimpleFormControllerTests method verifyAddRegexRegisteredService.

@Test
public void verifyAddRegexRegisteredService() throws Exception {
    final RegexRegisteredService svc = new RegexRegisteredService();
    svc.setDescription(DESCRIPTION);
    svc.setServiceId("^serviceId");
    svc.setName(NAME);
    svc.setId(1000);
    svc.setEvaluationOrder(1000);
    final RegisteredServiceEditBean.ServiceData data = registeredServiceFactory.createServiceData(svc);
    this.controller.saveService(new MockHttpServletRequest(), new MockHttpServletResponse(), data, mock(BindingResult.class));
    final Collection<RegisteredService> services = this.manager.getAllServices();
    assertEquals(1, services.size());
    this.manager.getAllServices().forEach(rs -> assertTrue(rs instanceof RegexRegisteredService));
}
Also used : BindingResult(org.springframework.validation.BindingResult) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredServiceEditBean(org.apereo.cas.mgmt.services.web.beans.RegisteredServiceEditBean) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 9 with RegexRegisteredService

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

the class LogoutActionTests method verifyLogoutForServiceWithFollowRedirectsAndMatchingService.

@Test
public void verifyLogoutForServiceWithFollowRedirectsAndMatchingService() throws Exception {
    this.request.addParameter("service", TEST_SERVICE_ID);
    final RegexRegisteredService impl = new RegexRegisteredService();
    impl.setServiceId(TEST_SERVICE_ID);
    impl.setName(TEST_SERVICE_ID);
    this.serviceManager.save(impl);
    final LogoutProperties properties = new LogoutProperties();
    properties.setFollowServiceRedirects(true);
    this.logoutAction = new LogoutAction(getWebApplicationServiceFactory(), this.serviceManager, properties);
    final Event event = this.logoutAction.doExecute(this.requestContext);
    assertEquals(CasWebflowConstants.TRANSITION_ID_FINISH, event.getId());
    assertEquals(TEST_SERVICE_ID, this.requestContext.getFlowScope().get("logoutRedirectUrl"));
}
Also used : LogoutProperties(org.apereo.cas.configuration.model.core.logout.LogoutProperties) LogoutAction(org.apereo.cas.web.flow.logout.LogoutAction) Event(org.springframework.webflow.execution.Event) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) Test(org.junit.Test)

Example 10 with RegexRegisteredService

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

the class ServiceAuthorizationCheckTests method setUpMocks.

@Before
public void setUpMocks() {
    final RegexRegisteredService authorizedRegisteredService = new RegexRegisteredService();
    final RegexRegisteredService unauthorizedRegisteredService = new RegexRegisteredService();
    unauthorizedRegisteredService.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(false, false));
    final List<RegisteredService> list = new ArrayList<>();
    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);
    this.serviceAuthorizationCheck = new ServiceAuthorizationCheck(this.servicesManager, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
}
Also used : DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) ArrayList(java.util.ArrayList) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) Before(org.junit.Before)

Aggregations

RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)42 lombok.val (lombok.val)12 Test (org.junit.Test)12 AbstractRegisteredService (org.apereo.cas.services.AbstractRegisteredService)10 RegisteredService (org.apereo.cas.services.RegisteredService)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 Service (org.apereo.cas.authentication.principal.Service)6 Test (org.junit.jupiter.api.Test)6 RegisteredServiceEditBean (org.apereo.cas.mgmt.services.web.beans.RegisteredServiceEditBean)5 DefaultRegisteredServiceAccessStrategy (org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 URL (java.net.URL)3 SecureRandom (java.security.SecureRandom)3 HashMap (java.util.HashMap)3 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)3 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)3 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)3 AnonymousRegisteredServiceUsernameAttributeProvider (org.apereo.cas.services.AnonymousRegisteredServiceUsernameAttributeProvider)3