Search in sources :

Example 16 with ValueWrapper

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;
}
Also used : ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) Set(java.util.Set) HashSet(java.util.HashSet) UUID(java.util.UUID)

Example 17 with ValueWrapper

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();
}
Also used : Script(groovy.lang.Script) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper)

Example 18 with ValueWrapper

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;
}
Also used : Serializable(java.io.Serializable) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) HashSet(java.util.HashSet) Set(java.util.Set) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 19 with ValueWrapper

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;
}
Also used : ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Aggregations

ValueWrapper (eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper)19 UUID (java.util.UUID)7 Set (java.util.Set)5 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 IdmAuthorizationPolicyService (eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService)3 IdmCacheManager (eu.bcvsolutions.idm.core.api.service.IdmCacheManager)3 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)3 AuthorizableType (eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType)3 AuthorizationEvaluatorDto (eu.bcvsolutions.idm.core.security.api.dto.AuthorizationEvaluatorDto)3 AuthorizationManager (eu.bcvsolutions.idm.core.security.api.service.AuthorizationManager)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 RoleConfiguration (eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration)2 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)2 ContractState (eu.bcvsolutions.idm.core.api.domain.ContractState)2 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)2