Search in sources :

Example 1 with ExpiredObject

use of io.jans.ca.common.ExpiredObject in project jans by JanssenProject.

the class KeyGeneratorService method getKeysFromStorage.

public JSONWebKeySet getKeysFromStorage() {
    ExpiredObject expiredObject = persistenceService.getExpiredObject(ExpiredObjectType.JWKS.getValue());
    if (expiredObject == null || Strings.isNullOrEmpty(expiredObject.getValue())) {
        return null;
    }
    JSONObject keysInJson = new JSONObject(expiredObject.getValue());
    JSONWebKeySet keys = JSONWebKeySet.fromJSONObject(keysInJson);
    try {
        if (hasKeysExpired(expiredObject)) {
            LOG.trace("The keys in storage got expired. Deleting the expired keys from storage.");
            deleteKeysFromStorage();
            return null;
        }
    } catch (Exception e) {
        LOG.error("Error in reading expiry date or deleting expired keys from storage. Trying to delete the keys from storage.", e);
        deleteKeysFromStorage();
        return null;
    }
    return keys;
}
Also used : JSONObject(org.json.JSONObject) JSONWebKeySet(io.jans.as.model.jwk.JSONWebKeySet) ExpiredObject(io.jans.ca.common.ExpiredObject) CryptoProviderException(io.jans.as.model.exception.CryptoProviderException) HttpException(io.jans.ca.server.HttpException)

Example 2 with ExpiredObject

use of io.jans.ca.common.ExpiredObject in project jans by JanssenProject.

the class JansPersistenceService method getExpiredObject.

public ExpiredObject getExpiredObject(String key) {
    try {
        ExpiredObject expiredObject = (ExpiredObject) this.persistenceEntryManager.find(getDnForExpiredObj(key), ExpiredObject.class, null);
        if (expiredObject != null) {
            expiredObject.setType(ExpiredObjectType.fromValue(expiredObject.getTypeString()));
            LOG.debug("Found ExpiredObject id: {} , ExpiredObject : {} ", key, expiredObject);
            return expiredObject;
        }
        LOG.error("Failed to fetch ExpiredObject by id: {} ", key);
        return null;
    } catch (Exception e) {
        if (((e instanceof EntryPersistenceException)) && (e.getMessage().contains("Failed to find entry"))) {
            LOG.warn("Failed to fetch ExpiredObject by id: {}. {} ", key, e.getMessage());
            return null;
        }
        LOG.error("Failed to fetch ExpiredObject by id: {} ", key, e);
    }
    return null;
}
Also used : EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) ExpiredObject(io.jans.ca.common.ExpiredObject) SQLException(java.sql.SQLException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException)

Example 3 with ExpiredObject

use of io.jans.ca.common.ExpiredObject in project jans by JanssenProject.

the class SqlPersistenceServiceImpl method getExpiredObject.

public ExpiredObject getExpiredObject(String key) {
    Connection conn = null;
    PreparedStatement query = null;
    try {
        conn = provider.getConnection();
        conn.setAutoCommit(false);
        query = conn.prepareStatement("select obj_key, obj_value, type, iat, exp from expired_objects where obj_key = ?");
        query.setString(1, key.trim());
        ResultSet rs = query.executeQuery();
        ExpiredObject expiredObject = null;
        rs.next();
        if (!Strings.isNullOrEmpty(rs.getString("obj_key"))) {
            expiredObject = new ExpiredObject(rs.getString("obj_key"), rs.getString("obj_value"), ExpiredObjectType.fromValue(rs.getString("type")), new java.util.Date(rs.getTimestamp("iat").getTime()), new java.util.Date(rs.getTimestamp("exp").getTime()));
        }
        query.close();
        conn.commit();
        if (expiredObject != null) {
            LOG.debug("Found ExpiredObject: " + expiredObject.getKey());
            return expiredObject;
        } else {
            LOG.error("ExpiredObject not found: " + key);
            return expiredObject;
        }
    } catch (Exception e) {
        LOG.error("Failed to find ExpiredObject: " + key + ". Error: " + e.getMessage(), e);
        rollbackSilently(conn);
        return null;
    } finally {
        IOUtils.closeSilently(query);
        IOUtils.closeSilently(conn);
    }
}
Also used : ExpiredObject(io.jans.ca.common.ExpiredObject)

Example 4 with ExpiredObject

use of io.jans.ca.common.ExpiredObject in project jans by JanssenProject.

the class RedisPersistenceService method getExpiredObject.

public ExpiredObject getExpiredObject(String key) {
    String value = (String) redisProvider.get(key);
    if (!Strings.isNullOrEmpty(value)) {
        ExpiredObject expiredObjectFromDb = null;
        try {
            expiredObjectFromDb = Jackson2.createJsonMapper().readValue(value, ExpiredObject.class);
        } catch (IOException e) {
            LOG.error("Error in assigning json value to ExpiredObject value attribute.", e);
            expiredObjectFromDb = new ExpiredObject();
        }
        ExpiredObject expiredObject = new ExpiredObject(key, value, expiredObjectFromDb.getType(), expiredObjectFromDb.getIat(), expiredObjectFromDb.getExp());
        return expiredObject;
    }
    return null;
}
Also used : IOException(java.io.IOException) ExpiredObject(io.jans.ca.common.ExpiredObject)

Aggregations

ExpiredObject (io.jans.ca.common.ExpiredObject)4 CryptoProviderException (io.jans.as.model.exception.CryptoProviderException)1 JSONWebKeySet (io.jans.as.model.jwk.JSONWebKeySet)1 HttpException (io.jans.ca.server.HttpException)1 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 JSONObject (org.json.JSONObject)1