Search in sources :

Example 21 with DefaultRegisteredServiceProperty

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

the class DefaultDelegatedAuthenticationNavigationControllerTests method verifyRedirectWithServiceSaml2Properties.

@Test
public void verifyRedirectWithServiceSaml2Properties() {
    val request = new MockHttpServletRequest();
    request.setAttribute(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "SAML2Client");
    val service = RegisteredServiceTestUtils.getService("https://github.com/apereo/cas");
    servicesManager.save(RegisteredServiceTestUtils.getRegisteredService("https://github.com/apereo/cas"));
    val registeredService = servicesManager.findServiceBy(service);
    val property1 = new DefaultRegisteredServiceProperty("class1", "class2");
    registeredService.getProperties().put(RegisteredServiceProperties.DELEGATED_AUTHN_SAML2_AUTHN_CONTEXT_CLASS_REFS.getPropertyName(), property1);
    val property2 = new DefaultRegisteredServiceProperty("true");
    registeredService.getProperties().put(RegisteredServiceProperties.DELEGATED_AUTHN_SAML2_WANTS_RESPONSES_SIGNED.getPropertyName(), property2);
    servicesManager.save(registeredService);
    request.setParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
    val response = new MockHttpServletResponse();
    assertTrue(controller.redirectToProvider(request, response) instanceof DynamicHtmlView);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DynamicHtmlView(org.apereo.cas.web.view.DynamicHtmlView) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with DefaultRegisteredServiceProperty

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

the class ScimV2PrincipalProvisionerTests method verifyScimServicePerApp.

@Test
public void verifyScimServicePerApp() {
    val provisioner = new ScimV2PrincipalProvisioner(new ScimProperties(), new DefaultScimV2PrincipalAttributeMapper());
    assertFalse(provisioner.provision(CoreAuthenticationTestUtils.getPrincipal(), CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword()));
    val props = new LinkedHashMap<String, RegisteredServiceProperty>();
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.SCIM_OAUTH_TOKEN.getPropertyName(), new DefaultRegisteredServiceProperty("token"));
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.SCIM_TARGET.getPropertyName(), new DefaultRegisteredServiceProperty("https://localhost:9999"));
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.SCIM_USERNAME.getPropertyName(), new DefaultRegisteredServiceProperty(Set.of("username")));
    props.put(RegisteredServiceProperty.RegisteredServiceProperties.SCIM_PASSWORD.getPropertyName(), new DefaultRegisteredServiceProperty(Set.of("password")));
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
    when(registeredService.getProperties()).thenReturn(props);
    assertNotNull(provisioner.getScimService(Optional.of(registeredService)));
}
Also used : lombok.val(lombok.val) ScimProperties(org.apereo.cas.configuration.model.support.scim.ScimProperties) LinkedHashMap(java.util.LinkedHashMap) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) Test(org.junit.jupiter.api.Test)

Example 23 with DefaultRegisteredServiceProperty

use of org.apereo.cas.services.DefaultRegisteredServiceProperty 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 24 with DefaultRegisteredServiceProperty

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

the class OidcJwtAccessTokenEncoderTests method verifyEncodingWithoutEncryptionForService.

@Test
public void verifyEncodingWithoutEncryptionForService() throws Exception {
    val accessToken = getAccessToken();
    val registeredService = getOidcRegisteredService(accessToken.getClientId());
    registeredService.setJwtAccessToken(true);
    registeredService.setProperties(Map.of(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_ENCRYPTION_ENABLED.getPropertyName(), new DefaultRegisteredServiceProperty("false")));
    this.servicesManager.save(registeredService);
    val token1 = getAccessTokenEncoder(accessToken, registeredService).encode();
    val token2 = getAccessTokenEncoder(accessToken, registeredService).encode();
    assertEquals(token1, token2);
}
Also used : lombok.val(lombok.val) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) Test(org.junit.jupiter.api.Test)

Example 25 with DefaultRegisteredServiceProperty

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

the class OidcRegisteredServiceJwtAccessTokenCipherExecutorTests method verifyNoSigningKey.

@Test
public void verifyNoSigningKey() throws Exception {
    val service = getOidcRegisteredService("whatever");
    service.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_SIGNING_ENABLED.getPropertyName(), new DefaultRegisteredServiceProperty(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_SIGNING_ENABLED.getDefaultValue()));
    val key = EncodingUtils.generateJsonWebKey(512);
    service.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_SIGNING_KEY.getPropertyName(), new DefaultRegisteredServiceProperty(key));
    val at = getAccessToken();
    val encoded = oidcRegisteredServiceJwtAccessTokenCipherExecutor.encode(at.getId(), Optional.of(service));
    assertNotNull(encoded);
}
Also used : lombok.val(lombok.val) 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