Search in sources :

Example 1 with JwtTicketCipherExecutor

use of org.apereo.cas.token.cipher.JwtTicketCipherExecutor in project cas by apereo.

the class TokenWebApplicationServiceResponseBuilderTests method verifyDecrypt.

@Test
public void verifyDecrypt() {
    val signingSecret = "EihBwA3OuDQMm4gdWzkqRJ87596G7o7a_naJAJipxFoRJbXK7APRcnCA91Y30rJdh4q-C2dmpfV6eNhQT0bR5A";
    val encryptionSecret = "dJ2YpUd-r_Qd7e3nDm79WiIHkqaLT8yZt6nN5eG0YnE";
    val cipher = new JwtTicketCipherExecutor(encryptionSecret, signingSecret, true, 0, 0);
    val result = cipher.decode(cipher.encode("ThisIsValue"));
    assertEquals("ThisIsValue", result);
}
Also used : lombok.val(lombok.val) JwtTicketCipherExecutor(org.apereo.cas.token.cipher.JwtTicketCipherExecutor) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with JwtTicketCipherExecutor

use of org.apereo.cas.token.cipher.JwtTicketCipherExecutor in project cas by apereo.

the class OidcRegisteredServiceJwtAccessTokenCipherExecutor method createCipherExecutorInstance.

@Override
protected JwtTicketCipherExecutor createCipherExecutorInstance(final String encryptionKey, final String signingKey, final RegisteredService registeredService, final CipherOperationsStrategyType type) {
    val cipher = new InternalJwtAccessTokenCipherExecutor(encryptionKey, signingKey);
    Unchecked.consumer(c -> {
        if (EncodingUtils.isJsonWebKey(encryptionKey)) {
            val jsonWebKey = toJsonWebKey(encryptionKey);
            cipher.setEncryptionKey(jsonWebKey.getPublicKey());
            cipher.setEncryptionWebKey(jsonWebKey);
        }
        if (EncodingUtils.isJsonWebKey(signingKey)) {
            val jsonWebKey = toJsonWebKey(signingKey);
            cipher.setSigningKey(jsonWebKey.getPrivateKey());
            cipher.setSigningWebKey(jsonWebKey);
        }
    }).accept(cipher);
    if (EncodingUtils.isJsonWebKey(encryptionKey) || EncodingUtils.isJsonWebKey(signingKey)) {
        cipher.setEncryptionAlgorithm(KeyManagementAlgorithmIdentifiers.RSA_OAEP_256);
    }
    cipher.setCustomHeaders(CollectionUtils.wrap(CUSTOM_HEADER_REGISTERED_SERVICE_ID, registeredService.getId()));
    cipher.setStrategyType(type);
    return cipher;
}
Also used : lombok.val(lombok.val) KeyManagementAlgorithmIdentifiers(org.jose4j.jwe.KeyManagementAlgorithmIdentifiers) Setter(lombok.Setter) OAuth20RegisteredServiceJwtAccessTokenCipherExecutor(org.apereo.cas.support.oauth.web.response.accesstoken.response.OAuth20RegisteredServiceJwtAccessTokenCipherExecutor) Getter(lombok.Getter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apereo.cas.util.CollectionUtils) PublicJsonWebKey(org.jose4j.jwk.PublicJsonWebKey) OidcJsonWebKeyCacheKey(org.apereo.cas.oidc.jwks.OidcJsonWebKeyCacheKey) Unchecked(org.jooq.lambda.Unchecked) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) JsonWebKey(org.jose4j.jwk.JsonWebKey) lombok.val(lombok.val) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) JsonWebKeySet(org.jose4j.jwk.JsonWebKeySet) Collectors(java.util.stream.Collectors) RegisteredService(org.apereo.cas.services.RegisteredService) JwtTicketCipherExecutor(org.apereo.cas.token.cipher.JwtTicketCipherExecutor) Serializable(java.io.Serializable) Key(java.security.Key) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) OidcRegisteredService(org.apereo.cas.services.OidcRegisteredService) OidcIssuerService(org.apereo.cas.oidc.issuer.OidcIssuerService) Optional(java.util.Optional) EncodingUtils(org.apereo.cas.util.EncodingUtils) OidcJsonWebKeyUsage(org.apereo.cas.oidc.jwks.OidcJsonWebKeyUsage)

Aggregations

lombok.val (lombok.val)2 JwtTicketCipherExecutor (org.apereo.cas.token.cipher.JwtTicketCipherExecutor)2 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1 Serializable (java.io.Serializable)1 Key (java.security.Key)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Getter (lombok.Getter)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Setter (lombok.Setter)1 Slf4j (lombok.extern.slf4j.Slf4j)1 StringUtils (org.apache.commons.lang3.StringUtils)1 OidcIssuerService (org.apereo.cas.oidc.issuer.OidcIssuerService)1 OidcJsonWebKeyCacheKey (org.apereo.cas.oidc.jwks.OidcJsonWebKeyCacheKey)1 OidcJsonWebKeyUsage (org.apereo.cas.oidc.jwks.OidcJsonWebKeyUsage)1 OidcRegisteredService (org.apereo.cas.services.OidcRegisteredService)1 RegisteredService (org.apereo.cas.services.RegisteredService)1 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)1 OAuth20RegisteredServiceJwtAccessTokenCipherExecutor (org.apereo.cas.support.oauth.web.response.accesstoken.response.OAuth20RegisteredServiceJwtAccessTokenCipherExecutor)1