Search in sources :

Example 6 with DefaultRegisteredServiceProperty

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

the class WsFederationNavigationControllerTests method verifyOperation.

@Test
public void verifyOperation() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "Mozilla/5.0 (Windows NT 10.0; WOW64)");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val config = wsFederationConfigurations.toList().get(0);
    val registeredService = RegisteredServiceTestUtils.getRegisteredService("https://wsfedservice");
    registeredService.setProperties(Map.of(RegisteredServiceProperty.RegisteredServiceProperties.WSFED_RELYING_PARTY_ID.getPropertyName(), new DefaultRegisteredServiceProperty(config.getRelyingPartyIdentifier())));
    val service = RegisteredServiceTestUtils.getService(registeredService.getServiceId());
    servicesManager.save(registeredService);
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
    val id = config.getId();
    request.addParameter(WsFederationNavigationController.PARAMETER_NAME, id);
    val view = wsFederationNavigationController.redirectToProvider(request, response);
    assertTrue(view instanceof RedirectView);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) RedirectView(org.springframework.web.servlet.view.RedirectView) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) Test(org.junit.jupiter.api.Test)

Example 7 with DefaultRegisteredServiceProperty

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

the class OidcRegisteredServiceJwtAccessTokenCipherExecutorTests method verifyEncKey.

@Test
public void verifyEncKey() throws Exception {
    val service = getOidcRegisteredService("whatever");
    service.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_ENCRYPTION_ENABLED.getPropertyName(), new DefaultRegisteredServiceProperty("true"));
    val key = EncodingUtils.newJsonWebKey(2048);
    service.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_ENCRYPTION_KEY.getPropertyName(), new DefaultRegisteredServiceProperty(key.toJson(JsonWebKey.OutputControlLevel.INCLUDE_PRIVATE)));
    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)

Example 8 with DefaultRegisteredServiceProperty

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

the class OidcRegisteredServiceJwtAccessTokenCipherExecutorTests method verifyNoEncKey.

@Test
public void verifyNoEncKey() throws Exception {
    val service = getOidcRegisteredService("whatever");
    service.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_ENCRYPTION_ENABLED.getPropertyName(), new DefaultRegisteredServiceProperty("true"));
    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)

Example 9 with DefaultRegisteredServiceProperty

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

the class OidcJwtAccessTokenEncoderTests method getRegisteredServiceForJwtAccessTokenWithKeys.

private OidcRegisteredService getRegisteredServiceForJwtAccessTokenWithKeys(final OAuth20AccessToken accessToken) {
    val registeredService = getOidcRegisteredService(accessToken.getClientId());
    registeredService.setJwtAccessToken(true);
    val property = new DefaultRegisteredServiceProperty("false");
    registeredService.setProperties(Map.of(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_ENCRYPTION_ENABLED.getPropertyName(), property, RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_SIGNING_ENABLED.getPropertyName(), property));
    this.servicesManager.save(registeredService);
    return registeredService;
}
Also used : lombok.val(lombok.val) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty)

Example 10 with DefaultRegisteredServiceProperty

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

the class OidcRegisteredServiceJwtAccessTokenCipherExecutorNoCacheTests method verifyEmptyCacheOperation.

@Test
public void verifyEmptyCacheOperation() {
    val id = UUID.randomUUID().toString();
    val defaultCache = mock(LoadingCache.class);
    when(defaultCache.get(any())).thenReturn(Optional.empty());
    val serviceCache = mock(LoadingCache.class);
    when(serviceCache.get(any())).thenReturn(Optional.empty());
    val cipher = new OidcRegisteredServiceJwtAccessTokenCipherExecutor(defaultCache, serviceCache, OidcIssuerService.immutable(id));
    val service = getOidcRegisteredService("whatever");
    assertTrue(cipher.getSigningKey(service).isEmpty());
    service.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.ACCESS_TOKEN_AS_JWT_ENCRYPTION_ENABLED.getPropertyName(), new DefaultRegisteredServiceProperty("true"));
    assertTrue(cipher.getEncryptionKey(service).isEmpty());
    when(serviceCache.get(any())).thenReturn(Optional.of(new JsonWebKeySet(mock(PublicJsonWebKey.class))));
    assertTrue(cipher.getEncryptionKey(service).isEmpty());
}
Also used : lombok.val(lombok.val) JsonWebKeySet(org.jose4j.jwk.JsonWebKeySet) DefaultRegisteredServiceProperty(org.apereo.cas.services.DefaultRegisteredServiceProperty) PublicJsonWebKey(org.jose4j.jwk.PublicJsonWebKey) 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