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;
}
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;
}
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);
}
}
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;
}
Aggregations