use of eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManager method removeEventCache.
/**
* ~ Complete event in transaction processing.
*
* @param eventId
* @param transactionId
* @return true => all events in transaction are processed
*/
@SuppressWarnings("unchecked")
private boolean removeEventCache(UUID eventId, UUID transactionId) {
LOG.trace("Remove event [{}] from cache under transaction [{}].", eventId, transactionId);
if (transactionId == null) {
return false;
}
//
ValueWrapper value = cacheManager.getValue(TRANSACTION_EVENT_CACHE_NAME, transactionId);
if (value == null) {
// transaction was not registered (~ synchronous processing)
return false;
}
Set<UUID> events = (Set<UUID>) value.get();
events.remove(eventId);
if (!events.isEmpty()) {
cacheManager.cacheValue(TRANSACTION_EVENT_CACHE_NAME, transactionId, events);
return false;
}
//
cacheManager.evictValue(TRANSACTION_EVENT_CACHE_NAME, transactionId);
// => asynchronous transaction is processed completely
return true;
}
use of eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper in project CzechIdMng by bcvsolutions.
the class DefaultGroovyScriptService method getScript.
private Script getScript(String source) {
// TODO: consider hashing source in order to not waste so much space
ValueWrapper value = cacheManager.getValue(CACHE_NAME, source);
if (value == null) {
Script script = buildScript(source);
cacheManager.cacheValue(CACHE_NAME, source, script);
return script;
}
return (Script) value.get();
}
use of eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper in project CzechIdMng by bcvsolutions.
the class DefaultAuthorizationManager method getPermissions.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public <E extends Identifiable> Set<String> getPermissions(E entity) {
Assert.notNull(entity, "Entity is required.");
final Set<String> permissions = new HashSet<>();
//
UUID loggedIdentityId = securityService.getCurrentId();
if (loggedIdentityId == null) {
// TODO: support setting policies to not logged user - e.g. public endpoints.
return permissions;
}
// try to get cached permissions
Serializable entityId = entity.getId();
Map<Serializable, Set<String>> cachedPermissions = null;
if (entityId != null) {
// TODO: support cache for newly created entities without id
ValueWrapper value = cacheManager.getValue(PERMISSION_CACHE_NAME, loggedIdentityId);
if (value != null) {
// cache value is never null
cachedPermissions = new HashMap<>((Map) value.get());
//
if (cachedPermissions.containsKey(entityId)) {
return cachedPermissions.get(entityId);
}
}
}
// load policies and get permissions
getEnabledDistinctPolicies(loggedIdentityId, entity.getClass()).forEach(policy -> {
permissions.addAll(getPermissions(entity, policy));
});
// cache permissions
if (entityId != null) {
if (cachedPermissions == null) {
cachedPermissions = new HashMap<>();
}
cachedPermissions.put(entityId, permissions);
cacheManager.cacheValue(PERMISSION_CACHE_NAME, loggedIdentityId, cachedPermissions);
}
//
return permissions;
}
use of eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManager method getLastResult.
/**
* Find last monitoring result.
*
* @param monitoringId monitoring evaluator identifier
* @return last result
*/
private IdmMonitoringResultDto getLastResult(UUID monitoringId, BasePermission... permission) {
// try to get cached value
ValueWrapper value = cacheManager.getValue(LAST_RESULT_CACHE_NAME, monitoringId);
if (value != null) {
return monitoringResultService.checkAccess((IdmMonitoringResultDto) value.get(), permission);
}
// or load from database
IdmMonitoringResultFilter resultFilter = new IdmMonitoringResultFilter();
resultFilter.setMonitoring(monitoringId);
List<IdmMonitoringResultDto> monitoringResults = monitoringResultService.find(resultFilter, PageRequest.of(0, 1, Sort.by(Direction.DESC, IdmMonitoringResult_.created.getName())), permission).getContent();
if (monitoringResults.isEmpty()) {
// null => prevent to load again
cacheManager.cacheValue(LAST_RESULT_CACHE_NAME, monitoringId, null);
//
return null;
}
//
IdmMonitoringResultDto lastResult = monitoringResults.get(0);
cacheManager.cacheValue(LAST_RESULT_CACHE_NAME, monitoringId, lastResult);
//
return lastResult;
}
Aggregations