Search in sources :

Example 16 with DefaultRegisteredServiceProperty

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

the class RegisteredServiceCorsConfigurationSourceTests method verifyService.

@Test
public void verifyService() {
    val props = new LinkedHashMap<String, RegisteredServiceProperty>();
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.CORS_ALLOW_CREDENTIALS.getPropertyName(), new DefaultRegisteredServiceProperty("false"));
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.CORS_MAX_AGE.getPropertyName(), new DefaultRegisteredServiceProperty("1000"));
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.CORS_ALLOWED_HEADERS.getPropertyName(), new DefaultRegisteredServiceProperty(Set.of("12345")));
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.CORS_ALLOWED_ORIGINS.getPropertyName(), new DefaultRegisteredServiceProperty(Set.of("12345")));
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.CORS_ALLOWED_ORIGIN_PATTERNS.getPropertyName(), new DefaultRegisteredServiceProperty(Set.of("12345")));
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.CORS_ALLOWED_METHODS.getPropertyName(), new DefaultRegisteredServiceProperty(Set.of("12345")));
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.CORS_EXPOSED_HEADERS.getPropertyName(), new DefaultRegisteredServiceProperty(Set.of("12345")));
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
    when(registeredService.getProperties()).thenReturn(props);
    val servicesManager = mock(ServicesManager.class);
    when(servicesManager.findServiceBy(any(Service.class))).thenReturn(registeredService);
    val argumentExtractor = mock(ArgumentExtractor.class);
    when(argumentExtractor.extractService(any())).thenReturn(RegisteredServiceTestUtils.getService());
    val source = new RegisteredServiceCorsConfigurationSource(casProperties, servicesManager, argumentExtractor);
    val request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, "example");
    val config = source.getCorsConfiguration(request);
    assertFalse(config.getAllowCredentials().booleanValue());
    assertEquals(1000, config.getMaxAge().intValue());
    assertEquals(List.of("12345"), config.getAllowedHeaders());
    assertEquals(List.of("12345"), config.getAllowedOrigins());
    assertEquals(List.of("12345"), config.getAllowedMethods());
    assertEquals(List.of("12345"), config.getExposedHeaders());
    assertEquals(List.of("12345"), config.getAllowedOriginPatterns());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RegisteredServiceCorsConfigurationSource(org.apereo.cas.services.web.support.RegisteredServiceCorsConfigurationSource) Service(org.apereo.cas.authentication.principal.Service) LinkedHashMap(java.util.LinkedHashMap) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with DefaultRegisteredServiceProperty

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

the class DefaultDelegatedAuthenticationNavigationControllerTests method verifyRedirectWithServiceOidcProperties.

@Test
public void verifyRedirectWithServiceOidcProperties() {
    val request = new MockHttpServletRequest();
    request.setAttribute(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "OidcClient");
    val service = RegisteredServiceTestUtils.getService("https://github.com/apereo/cas2");
    servicesManager.save(RegisteredServiceTestUtils.getRegisteredService("https://github.com/apereo/cas2"));
    val registeredService = servicesManager.findServiceBy(service);
    val property1 = new DefaultRegisteredServiceProperty("1000");
    registeredService.getProperties().put(RegisteredServiceProperties.DELEGATED_AUTHN_OIDC_MAX_AGE.getPropertyName(), property1);
    val property2 = new DefaultRegisteredServiceProperty("openid one two three");
    registeredService.getProperties().put(RegisteredServiceProperties.DELEGATED_AUTHN_OIDC_SCOPE.getPropertyName(), property2);
    servicesManager.save(registeredService);
    request.setParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
    val response = new MockHttpServletResponse();
    assertTrue(controller.redirectToProvider(request, response) instanceof RedirectView);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RedirectView(org.springframework.web.servlet.view.RedirectView) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with DefaultRegisteredServiceProperty

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

the class BaseLdapServiceRegistryTests method getRegexRegisteredService.

private static RegisteredService getRegexRegisteredService() {
    final AbstractRegisteredService rs = new RegexRegisteredService();
    rs.setName("Service Name Regex");
    rs.setProxyPolicy(new RefuseRegisteredServiceProxyPolicy());
    rs.setUsernameAttributeProvider(new AnonymousRegisteredServiceUsernameAttributeProvider(new ShibbolethCompatiblePersistentIdGenerator("hello")));
    rs.setDescription("Service description");
    rs.setServiceId("^http?://.+");
    rs.setTheme("the theme name");
    rs.setEvaluationOrder(123);
    rs.setDescription("Here is another description");
    rs.setRequiredHandlers(CollectionUtils.wrapHashSet("handler1", "handler2"));
    final Map<String, RegisteredServiceProperty> propertyMap = new HashMap<>();
    final DefaultRegisteredServiceProperty property = new DefaultRegisteredServiceProperty();
    final Set<String> values = new HashSet<>();
    values.add("value1");
    values.add("value2");
    property.setValues(values);
    propertyMap.put("field1", property);
    rs.setProperties(propertyMap);
    return rs;
}
Also used : AnonymousRegisteredServiceUsernameAttributeProvider(org.apereo.cas.services.AnonymousRegisteredServiceUsernameAttributeProvider) RegisteredServiceProperty(org.apereo.cas.services.RegisteredServiceProperty) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) HashMap(java.util.HashMap) ShibbolethCompatiblePersistentIdGenerator(org.apereo.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RefuseRegisteredServiceProxyPolicy(org.apereo.cas.services.RefuseRegisteredServiceProxyPolicy) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) HashSet(java.util.HashSet)

Example 19 with DefaultRegisteredServiceProperty

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

the class OAuth20DefaultAccessTokenResponseGeneratorTests method verifyAccessTokenAsJwtPerService.

@Test
public void verifyAccessTokenAsJwtPerService() throws Exception {
    val registeredService = getRegisteredService("example", "secret", new LinkedHashSet<>());
    registeredService.setJwtAccessToken(true);
    val signingKey = new DefaultRegisteredServiceProperty();
    signingKey.addValue("pR3Vizkn5FSY5xCg84cIS4m-b6jomamZD68C8ash-TlNmgGPcoLgbgquxHPoi24tRmGpqHgM4mEykctcQzZ-Xg");
    registeredService.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_SIGNING_KEY.getPropertyName(), signingKey);
    val encKey = new DefaultRegisteredServiceProperty();
    encKey.addValue("0KVXaN-nlXafRUwgsr3H_l6hkufY7lzoTy7OVI5pN0E");
    registeredService.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_ENCRYPTION_KEY.getPropertyName(), encKey);
    servicesManager.save(registeredService);
    val mv = generateAccessTokenResponseAndGetModelAndView(registeredService);
    assertTrue(mv.getModel().containsKey(OAuth20Constants.ACCESS_TOKEN));
    val at = mv.getModel().get(OAuth20Constants.ACCESS_TOKEN).toString();
    val jwt = JWTParser.parse(at);
    assertNotNull(jwt);
}
Also used : lombok.val(lombok.val) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) Test(org.junit.jupiter.api.Test)

Example 20 with DefaultRegisteredServiceProperty

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

the class RegexAttributeInterruptInquirerTests method verifyInterruptSkipped.

@Test
public void verifyInterruptSkipped() {
    val q = new RegexAttributeInterruptInquirer("member..", "CA.|system");
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
    val properties = new LinkedHashMap<String, RegisteredServiceProperty>();
    val value = new DefaultRegisteredServiceProperty();
    value.addValue(Boolean.TRUE.toString());
    properties.put(RegisteredServiceProperty.RegisteredServiceProperties.SKIP_INTERRUPT_NOTIFICATIONS.getPropertyName(), value);
    when(registeredService.getProperties()).thenReturn(properties);
    val response = q.inquire(CoreAuthenticationTestUtils.getAuthentication("casuser"), registeredService, CoreAuthenticationTestUtils.getService(), CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), new MockRequestContext());
    assertNotNull(response);
    assertFalse(response.isInterrupt());
}
Also used : lombok.val(lombok.val) MockRequestContext(org.springframework.webflow.test.MockRequestContext) LinkedHashMap(java.util.LinkedHashMap) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultRegisteredServiceProperty (org.apereo.cas.services.DefaultRegisteredServiceProperty)28 lombok.val (lombok.val)24 Test (org.junit.jupiter.api.Test)20 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 HashSet (java.util.HashSet)4 LinkedHashMap (java.util.LinkedHashMap)4 AbstractRegisteredService (org.apereo.cas.services.AbstractRegisteredService)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 HashMap (java.util.HashMap)3 Service (org.apereo.cas.authentication.principal.Service)3 AnonymousRegisteredServiceUsernameAttributeProvider (org.apereo.cas.services.AnonymousRegisteredServiceUsernameAttributeProvider)3 RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)3 ShibbolethCompatiblePersistentIdGenerator (org.apereo.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator)2 GoogleRecaptchaProperties (org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties)2 RefuseRegisteredServiceProxyPolicy (org.apereo.cas.services.RefuseRegisteredServiceProxyPolicy)2 RegisteredServiceProperty (org.apereo.cas.services.RegisteredServiceProperty)2 RegisteredServicePublicKeyImpl (org.apereo.cas.services.RegisteredServicePublicKeyImpl)2 ReturnAllAttributeReleasePolicy (org.apereo.cas.services.ReturnAllAttributeReleasePolicy)2 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)2