Search in sources :

Example 1 with Conf

use of io.jans.as.model.config.Conf in project jans by JanssenProject.

the class JwksResource method deleteKey.

@DELETE
@ProtectedApi(scopes = { ApiAccessConstants.JWKS_WRITE_ACCESS })
@Path(ApiConstants.KID_PATH)
public Response deleteKey(@PathParam(ApiConstants.KID) @NotNull String kid) {
    log.debug("Key to be to be deleted - kid = " + kid);
    final Conf conf = configurationService.findConf();
    WebKeysConfiguration webkeys = configurationService.findConf().getWebKeys();
    JSONWebKey jwk = getJSONWebKey(webkeys, kid);
    if (jwk == null) {
        throw new NotFoundException(getNotFoundError("JWK with kid - '" + kid + "' does not exist!"));
    }
    conf.getWebKeys().getKeys().removeIf(x -> x.getKid() != null && x.getKid().equals(kid));
    configurationService.merge(conf);
    return Response.noContent().build();
}
Also used : JSONWebKey(io.jans.as.model.jwk.JSONWebKey) Conf(io.jans.as.model.config.Conf) WebKeysConfiguration(io.jans.as.model.config.WebKeysConfiguration) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 2 with Conf

use of io.jans.as.model.config.Conf in project jans by JanssenProject.

the class JwksResource method put.

@PUT
@ProtectedApi(scopes = { ApiAccessConstants.JWKS_WRITE_ACCESS })
public Response put(WebKeysConfiguration webkeys) {
    log.debug("JWKS details to be updated - webkeys = " + webkeys);
    final Conf conf = configurationService.findConf();
    conf.setWebKeys(webkeys);
    configurationService.merge(conf);
    final String json = configurationService.findConf().getWebKeys().toString();
    return Response.ok(json).build();
}
Also used : Conf(io.jans.as.model.config.Conf) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 3 with Conf

use of io.jans.as.model.config.Conf in project jans by JanssenProject.

the class ConfigurationFactory method isRevisionIncreased.

private boolean isRevisionIncreased() {
    final Conf persistenceConf = loadConfigurationFromPersistence("jansRevision");
    if (persistenceConf == null) {
        return false;
    }
    log.trace("LDAP revision: {}, server revision: {}", persistenceConf.getRevision(), loadedRevision);
    return persistenceConf.getRevision() > this.loadedRevision;
}
Also used : Conf(io.jans.as.model.config.Conf)

Example 4 with Conf

use of io.jans.as.model.config.Conf in project jans by JanssenProject.

the class ConfigurationFactory method createFromLdap.

private boolean createFromLdap(boolean recoverFromFiles) {
    log.info("Loading configuration from '{}' DB...", baseConfiguration.getString("persistence.type"));
    try {
        final io.jans.as.model.config.Conf c = loadConfigurationFromPersistence();
        if (c != null) {
            init(c);
            // Destroy old configuration
            if (this.loaded) {
                destroy(AppConfiguration.class);
                destroy(io.jans.as.model.config.StaticConfiguration.class);
                destroy(io.jans.as.model.config.WebKeysConfiguration.class);
                destroy(ErrorResponseFactory.class);
            }
            this.loaded = true;
            configurationUpdateEvent.select(ConfigurationUpdate.Literal.INSTANCE).fire(conf);
            destroyCryptoProviderInstance();
            AbstractCryptoProvider newAbstractCryptoProvider = abstractCryptoProviderInstance.get();
            cryptoProviderEvent.select(CryptoProviderEvent.Literal.INSTANCE).fire(newAbstractCryptoProvider);
            return true;
        }
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }
    if (recoverFromFiles) {
        log.info("Unable to find configuration in LDAP, try to load configuration from file system... ");
        if (createFromFile()) {
            this.loadedFromLdap = false;
            return true;
        }
    }
    return false;
}
Also used : AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider) Conf(io.jans.as.model.config.Conf) ConfigurationException(io.jans.exception.ConfigurationException) BasePersistenceException(io.jans.orm.exception.BasePersistenceException)

Example 5 with Conf

use of io.jans.as.model.config.Conf in project jans by JanssenProject.

the class KeyGeneratorTimer method updateKeysImpl.

private void updateKeysImpl() throws Exception {
    log.info("Updating JWKS keys ...");
    String dn = configurationFactory.getBaseConfiguration().getString(Constants.SERVER_KEY_OF_CONFIGURATION_ENTRY);
    Conf conf = ldapEntryManager.find(Conf.class, dn);
    JSONObject jwks = conf.getWebKeys().toJSONObject();
    JSONObject updatedJwks = updateKeys(jwks);
    conf.setWebKeys(ServerUtil.createJsonMapper().readValue(updatedJwks.toString(), WebKeysConfiguration.class));
    long nextRevision = conf.getRevision() + 1;
    conf.setRevision(nextRevision);
    ldapEntryManager.merge(conf);
    log.info("Updated JWKS successfully");
    log.trace("JWKS keys: " + conf.getWebKeys().getKeys().stream().map(JSONWebKey::getKid).collect(Collectors.toList()));
    log.trace("KeyStore keys: " + cryptoProvider.getKeys());
}
Also used : Conf(io.jans.as.model.config.Conf) JSONObject(org.json.JSONObject) WebKeysConfiguration(io.jans.as.model.config.WebKeysConfiguration)

Aggregations

Conf (io.jans.as.model.config.Conf)13 WebKeysConfiguration (io.jans.as.model.config.WebKeysConfiguration)6 ProtectedApi (io.jans.configapi.core.rest.ProtectedApi)6 ConfigurationException (io.jans.exception.ConfigurationException)3 BasePersistenceException (io.jans.orm.exception.BasePersistenceException)3 AppConfiguration (io.jans.as.model.configuration.AppConfiguration)2 AbstractCryptoProvider (io.jans.as.model.crypto.AbstractCryptoProvider)2 JSONWebKey (io.jans.as.model.jwk.JSONWebKey)2 ApiConf (io.jans.configapi.model.configuration.ApiConf)2 JSONObject (org.json.JSONObject)2 StaticConfiguration (io.jans.as.model.config.StaticConfiguration)1 ErrorMessages (io.jans.as.model.error.ErrorMessages)1 OxIntializationException (io.jans.exception.OxIntializationException)1 PersistenceEntryManager (io.jans.orm.PersistenceEntryManager)1 FileInputStream (java.io.FileInputStream)1