Search in sources :

Example 1 with OidcJsonWebKeystoreEntity

use of org.apereo.cas.oidc.jwks.generator.OidcJsonWebKeystoreEntity in project cas by apereo.

the class OidcJpaJsonWebKeystoreGeneratorService method store.

@Override
public JsonWebKeySet store(final JsonWebKeySet jsonWebKeySet) throws Exception {
    val issuer = oidcProperties.getCore().getIssuer();
    return transactionTemplate.execute(status -> {
        val result = jsonWebKeySet.toJson(JsonWebKey.OutputControlLevel.INCLUDE_PRIVATE);
        Optional.ofNullable(entityManager.find(OidcJsonWebKeystoreEntity.class, issuer)).ifPresentOrElse(entity -> {
            entity.setData(result);
            entityManager.merge(entity);
        }, () -> {
            val entity = new OidcJsonWebKeystoreEntity(issuer, result);
            entityManager.persist(entity);
        });
        return jsonWebKeySet;
    });
}
Also used : lombok.val(lombok.val) OidcJsonWebKeystoreEntity(org.apereo.cas.oidc.jwks.generator.OidcJsonWebKeystoreEntity)

Example 2 with OidcJsonWebKeystoreEntity

use of org.apereo.cas.oidc.jwks.generator.OidcJsonWebKeystoreEntity in project cas by apereo.

the class OidcMongoDbJsonWebKeystoreGeneratorService method store.

@Override
public JsonWebKeySet store(final JsonWebKeySet jsonWebKeySet) throws Exception {
    val issuer = oidcProperties.getCore().getIssuer();
    val collectionName = oidcProperties.getJwks().getMongo().getCollection();
    val result = mongoTemplate.findById(issuer, OidcJsonWebKeystoreEntity.class, collectionName);
    val json = jsonWebKeySet.toJson(JsonWebKey.OutputControlLevel.INCLUDE_PRIVATE);
    Optional.ofNullable(result).ifPresentOrElse(entity -> {
        val update = Update.update("data", json);
        val query = new Query(Criteria.where("issuer").is(entity.getIssuer()));
        mongoTemplate.updateFirst(query, update, collectionName);
    }, () -> {
        val entity = new OidcJsonWebKeystoreEntity(issuer, json);
        mongoTemplate.insert(entity, collectionName);
    });
    return jsonWebKeySet;
}
Also used : lombok.val(lombok.val) Query(org.springframework.data.mongodb.core.query.Query) OidcJsonWebKeystoreEntity(org.apereo.cas.oidc.jwks.generator.OidcJsonWebKeystoreEntity)

Aggregations

lombok.val (lombok.val)2 OidcJsonWebKeystoreEntity (org.apereo.cas.oidc.jwks.generator.OidcJsonWebKeystoreEntity)2 Query (org.springframework.data.mongodb.core.query.Query)1