Search in sources :

Example 1 with WebKeysConfiguration

use of io.jans.as.model.config.WebKeysConfiguration 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 WebKeysConfiguration

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

the class JwksResource method getKeyById.

@GET
@ProtectedApi(scopes = { ApiAccessConstants.JWKS_READ_ACCESS })
@Path(ApiConstants.KID_PATH)
public Response getKeyById(@PathParam(ApiConstants.KID) @NotNull String kid) {
    log.debug("Fetch JWK details by kid = " + kid);
    WebKeysConfiguration webkeys = configurationService.findConf().getWebKeys();
    log.debug("WebKeysConfiguration before addding new key =" + webkeys);
    JSONWebKey jwk = getJSONWebKey(webkeys, kid);
    return Response.ok(jwk).build();
}
Also used : JSONWebKey(io.jans.as.model.jwk.JSONWebKey) WebKeysConfiguration(io.jans.as.model.config.WebKeysConfiguration) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 3 with WebKeysConfiguration

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

the class JwkRestWebServiceImpl method requestJwk.

@Override
public Response requestJwk(SecurityContext sec) {
    log.debug("Attempting to request JWK, Is Secure = {}", sec.isSecure());
    Response.ResponseBuilder builder = Response.ok();
    try {
        WebKeysConfiguration webKeysConfiguration = new WebKeysConfiguration();
        webKeysConfiguration.setKeys(this.filterKeys(this.webKeysConfiguration.getKeys()));
        builder.entity(webKeysConfiguration.toString());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        // 500
        builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    return builder.build();
}
Also used : Response(javax.ws.rs.core.Response) WebKeysConfiguration(io.jans.as.model.config.WebKeysConfiguration)

Example 4 with WebKeysConfiguration

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

the class ConfigurationFactory method initWebKeys.

private void initWebKeys(Conf conf) {
    final String jwksUri = conf.getDynamic().getJwksUri();
    if (jwksUri.startsWith(conf.getDynamic().getIssuer())) {
        if (conf.getWebKeys() != null) {
            jwks = conf.getWebKeys();
        } else {
            generateWebKeys();
        }
        return;
    }
    // external jwks
    final JSONObject keys = JwtUtil.getJSONWebKeys(jwksUri);
    log.trace("Downloaded external keys from {}, keys: {}", jwksUri, keys);
    final JSONWebKeySet keySet = JSONWebKeySet.fromJSONObject(keys);
    jwks = new WebKeysConfiguration();
    jwks.setKeys(keySet.getKeys());
}
Also used : JSONObject(org.json.JSONObject) WebKeysConfiguration(io.jans.as.model.config.WebKeysConfiguration) JSONWebKeySet(io.jans.as.model.jwk.JSONWebKeySet)

Example 5 with WebKeysConfiguration

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

the class ConfigurationTest method createLatestTestConfInLdapFromFiles.

/*
     * Useful test method to get create newest test configuration. It shouldn't
     * be used directly for testing.
     */
// @Test
public void createLatestTestConfInLdapFromFiles() throws Exception {
    final String prefix = "U:\\own\\project\\jans-auth\\server\\src\\test\\resources\\conf";
    final String errorsFile = prefix + "\\oxauth-errors.json";
    final String staticFile = prefix + "\\oxauth-static-conf.json";
    final String webKeysFile = prefix + "\\oxauth-web-keys.json";
    final String configFile = prefix + "\\oxauth-config.xml";
    final String errorsJson = IOUtils.toString(new FileInputStream(errorsFile));
    final String staticConfJson = IOUtils.toString(new FileInputStream(staticFile));
    final String webKeysJson = IOUtils.toString(new FileInputStream(webKeysFile));
    final StaticConfiguration staticConf = ServerUtil.createJsonMapper().readValue(staticConfJson, StaticConfiguration.class);
    final ErrorMessages errorConf = ServerUtil.createJsonMapper().readValue(errorsJson, ErrorMessages.class);
    final WebKeysConfiguration webKeys = ServerUtil.createJsonMapper().readValue(webKeysJson, WebKeysConfiguration.class);
    final AppConfiguration configJson = loadConfFromFile(configFile);
    final Conf c = new Conf();
    c.setDn("ou=testconfiguration,o=jans");
    c.setDynamic(configJson);
    c.setErrors(errorConf);
    c.setStatics(staticConf);
    c.setWebKeys(webKeys);
    ldapEntryManager.persist(c);
}
Also used : ErrorMessages(io.jans.as.model.error.ErrorMessages) WebKeysConfiguration(io.jans.as.model.config.WebKeysConfiguration) Conf(io.jans.as.model.config.Conf) AppConfiguration(io.jans.as.model.configuration.AppConfiguration) StaticConfiguration(io.jans.as.model.config.StaticConfiguration) FileInputStream(java.io.FileInputStream)

Aggregations

WebKeysConfiguration (io.jans.as.model.config.WebKeysConfiguration)7 Conf (io.jans.as.model.config.Conf)4 ProtectedApi (io.jans.configapi.core.rest.ProtectedApi)4 JSONWebKey (io.jans.as.model.jwk.JSONWebKey)2 StaticConfiguration (io.jans.as.model.config.StaticConfiguration)1 AppConfiguration (io.jans.as.model.configuration.AppConfiguration)1 ErrorMessages (io.jans.as.model.error.ErrorMessages)1 JSONWebKeySet (io.jans.as.model.jwk.JSONWebKeySet)1 FileInputStream (java.io.FileInputStream)1 Response (javax.ws.rs.core.Response)1 JSONObject (org.json.JSONObject)1