Search in sources :

Example 21 with RegexRegisteredService

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

the class RegisteredServiceSimpleFormControllerTests method verifyAddRegisteredServiceWithValues.

@Test
public void verifyAddRegisteredServiceWithValues() throws Exception {
    final RegexRegisteredService svc = new RegexRegisteredService();
    svc.setDescription(DESCRIPTION);
    svc.setServiceId(SERVICE_ID);
    svc.setName(NAME);
    svc.setEvaluationOrder(123);
    assertTrue(this.manager.getAllServices().isEmpty());
    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 22 with RegexRegisteredService

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

the class RegisteredServiceSimpleFormControllerTests method verifyAddMultipleRegisteredServiceTypes.

@Test
public void verifyAddMultipleRegisteredServiceTypes() throws Exception {
    AbstractRegisteredService 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));
    svc = new RegexRegisteredService();
    svc.setDescription(DESCRIPTION);
    svc.setServiceId("^serviceId");
    svc.setName(NAME);
    svc.setId(100);
    svc.setEvaluationOrder(100);
    final RegisteredServiceEditBean.ServiceData data2 = registeredServiceFactory.createServiceData(svc);
    this.controller.saveService(new MockHttpServletRequest(), new MockHttpServletResponse(), data2, mock(BindingResult.class));
    final Collection<RegisteredService> services = this.manager.getAllServices();
    assertEquals(2, services.size());
}
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) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) 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 23 with RegexRegisteredService

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

the class ManageRegisteredServicesMultiActionController method ensureDefaultServiceExists.

/**
     * Ensure default service exists.
     */
private void ensureDefaultServiceExists() {
    this.servicesManager.load();
    final Collection<RegisteredService> c = this.servicesManager.getAllServices();
    if (c == null) {
        throw new IllegalStateException("Services cannot be empty");
    }
    if (!this.servicesManager.matchesExistingService(this.defaultService)) {
        final RegexRegisteredService svc = new RegexRegisteredService();
        svc.setServiceId('^' + this.defaultService.getId());
        svc.setName("Services Management Web Application");
        svc.setDescription(svc.getName());
        this.servicesManager.save(svc);
        this.servicesManager.load();
    }
}
Also used : RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService)

Example 24 with RegexRegisteredService

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

the class ManageRegisteredServicesMultiActionControllerTests method verifyManage.

@Test
public void verifyManage() throws Exception {
    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));
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 25 with RegexRegisteredService

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

the class ManageRegisteredServicesMultiActionControllerTests method updateEvaluationOrderInvalidServiceId.

@Test
public void updateEvaluationOrderInvalidServiceId() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setId(1200);
    r.setName(NAME);
    r.setServiceId("test");
    r.setEvaluationOrder(2);
    this.thrown.expect(IllegalArgumentException.class);
    this.thrown.expectMessage("Service id 5000 cannot be found.");
    this.servicesManager.save(r);
    this.controller.updateRegisteredServiceEvaluationOrder(new MockHttpServletResponse(), 5000, 1000);
}
Also used : RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

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