Search in sources :

Example 51 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class RedisAccountCachePlugin method getGroupURIs.

/**
 * {@inheritDoc}
 */
@Override
public Set<URI<AccountGroup>> getGroupURIs(final URI<Account> accountURI) {
    Assertion.checkNotNull(accountURI);
    // -----
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(AccountGroup.class);
    final Set<URI<AccountGroup>> set = new HashSet<>();
    try (final Jedis jedis = redisConnector.getResource()) {
        final Set<String> ids = jedis.smembers(SGROUPS_BY_ACCOUNT_START_KEY + accountURI.getId());
        for (final String id : ids) {
            set.add(new URI<AccountGroup>(dtDefinition, id));
        }
        return set;
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) AccountGroup(io.vertigo.account.account.AccountGroup) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) HashSet(java.util.HashSet)

Example 52 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class RedisAccountCachePlugin method getAccountURIs.

/**
 * {@inheritDoc}
 */
@Override
public Set<URI<Account>> getAccountURIs(final URI<AccountGroup> groupURI) {
    Assertion.checkNotNull(groupURI);
    // -----
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(Account.class);
    final Set<URI<Account>> set = new HashSet<>();
    try (final Jedis jedis = redisConnector.getResource()) {
        final Set<String> ids = jedis.smembers(SACCOUNTS_BY_GROUP_START_KEY + groupURI.getId());
        for (final String id : ids) {
            set.add(new URI<Account>(dtDefinition, id));
        }
        return set;
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Account(io.vertigo.account.account.Account) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) HashSet(java.util.HashSet)

Example 53 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class SecuredEntityDeserializer method deserialize.

/**
 * {@inheritDoc}
 */
@Override
public SecuredEntity deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) {
    final JsonObject jsonSecuredEntity = json.getAsJsonObject();
    final DtDefinition entityDefinition = findDtDefinition(jsonSecuredEntity.get("entity").getAsString());
    final List<DtField> securityFields = new ArrayList<>();
    for (final JsonElement securityField : jsonSecuredEntity.get("securityFields").getAsJsonArray()) {
        securityFields.add(deserializeDtField(entityDefinition, securityField.getAsString()));
    }
    final List<SecurityDimension> advancedDimensions = new ArrayList<>();
    for (final JsonElement advancedDimension : jsonSecuredEntity.get("securityDimensions").getAsJsonArray()) {
        // TODO if null ?
        advancedDimensions.add(deserializeSecurityDimensions(entityDefinition, advancedDimension.getAsJsonObject(), context));
    }
    // on garde la map des operations pour resoudre les grants
    final Map<String, Authorization> permissionPerOperations = new HashMap<>();
    for (final JsonElement operation : jsonSecuredEntity.get("operations").getAsJsonArray()) {
        // TODO if null ?
        final Authorization permission = deserializeOperations(entityDefinition, operation.getAsJsonObject(), context, permissionPerOperations);
        Assertion.checkArgument(!permissionPerOperations.containsKey(permission.getOperation().get()), "Operation {0} already declared on {1}", permission.getOperation().get(), entityDefinition.getName());
        permissionPerOperations.put(permission.getOperation().get(), permission);
    }
    return new SecuredEntity(entityDefinition, securityFields, advancedDimensions, new ArrayList<>(permissionPerOperations.values()));
}
Also used : HashMap(java.util.HashMap) SecuredEntity(io.vertigo.account.authorization.metamodel.SecuredEntity) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) DtField(io.vertigo.dynamo.domain.metamodel.DtField) Authorization(io.vertigo.account.authorization.metamodel.Authorization) JsonElement(com.google.gson.JsonElement) SecurityDimension(io.vertigo.account.authorization.metamodel.SecurityDimension)

Example 54 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class AuthorizationManagerImpl method getCriteriaSecurity.

/**
 * {@inheritDoc}
 */
@Override
public <K extends KeyConcept> Criteria<K> getCriteriaSecurity(final Class<K> keyConceptClass, final OperationName<K> operation) {
    Assertion.checkNotNull(keyConceptClass);
    Assertion.checkNotNull(operation);
    // ---
    final Optional<UserAuthorizations> userPermissionsOpt = getUserPermissionsOpt();
    if (!userPermissionsOpt.isPresent()) {
        // Si il n'y a pas de session alors pas d'autorisation.
        return Criterions.alwaysFalse();
    }
    final UserAuthorizations userPermissions = userPermissionsOpt.get();
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(keyConceptClass);
    final SecuredEntity securedEntity = findSecuredEntity(dtDefinition);
    final List<Criteria<K>> criterions = userPermissions.getEntityAuthorizations(dtDefinition).stream().filter(permission -> permission.getOperation().get().equals(operation.name()) || permission.getOverrides().contains(operation.name())).flatMap(permission -> permission.getRules().stream()).map(rule -> new CriteriaSecurityRuleTranslator<K>().on(securedEntity).withRule(rule).withCriteria(userPermissions.getSecurityKeys()).toCriteria()).collect(Collectors.toList());
    if (criterions.isEmpty()) {
        // Si il n'y a pas de droits alors pas d'autorisation.
        return Criterions.alwaysFalse();
    }
    Criteria<K> securityCriteria = null;
    for (final Criteria<K> ruleCriteria : criterions) {
        if (securityCriteria == null) {
            securityCriteria = ruleCriteria;
        } else {
            securityCriteria = securityCriteria.or(ruleCriteria);
        }
    }
    return securityCriteria;
}
Also used : RuleMultiExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression) CriteriaSecurityRuleTranslator(io.vertigo.account.impl.authorization.dsl.translator.CriteriaSecurityRuleTranslator) VSecurityManager(io.vertigo.persona.security.VSecurityManager) UserAuthorizations(io.vertigo.account.authorization.UserAuthorizations) AuthorizationName(io.vertigo.account.authorization.metamodel.AuthorizationName) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) Criteria(io.vertigo.dynamo.criteria.Criteria) AuthorizationManager(io.vertigo.account.authorization.AuthorizationManager) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) List(java.util.List) DefinitionUtil(io.vertigo.core.definition.DefinitionUtil) Criterions(io.vertigo.dynamo.criteria.Criterions) Assertion(io.vertigo.lang.Assertion) KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) Optional(java.util.Optional) Authorization(io.vertigo.account.authorization.metamodel.Authorization) OperationName(io.vertigo.account.authorization.metamodel.OperationName) Collections(java.util.Collections) SearchSecurityRuleTranslator(io.vertigo.account.impl.authorization.dsl.translator.SearchSecurityRuleTranslator) UserSession(io.vertigo.persona.security.UserSession) SecuredEntity(io.vertigo.account.authorization.metamodel.SecuredEntity) SecuredEntity(io.vertigo.account.authorization.metamodel.SecuredEntity) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) CriteriaSecurityRuleTranslator(io.vertigo.account.impl.authorization.dsl.translator.CriteriaSecurityRuleTranslator) Criteria(io.vertigo.dynamo.criteria.Criteria) UserAuthorizations(io.vertigo.account.authorization.UserAuthorizations)

Example 55 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class AuthorizationManagerImpl method getSearchSecurity.

/**
 * {@inheritDoc}
 */
@Override
public <K extends KeyConcept> String getSearchSecurity(final Class<K> keyConceptClass, final OperationName<K> operationName) {
    Assertion.checkNotNull(keyConceptClass);
    Assertion.checkNotNull(operationName);
    // ---
    final Optional<UserAuthorizations> userPermissionsOpt = getUserPermissionsOpt();
    if (!userPermissionsOpt.isPresent()) {
        // Attention : pas de *:*
        return "";
    }
    final UserAuthorizations userPermissions = userPermissionsOpt.get();
    final SearchSecurityRuleTranslator securityRuleTranslator = new SearchSecurityRuleTranslator();
    securityRuleTranslator.withCriteria(userPermissions.getSecurityKeys());
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(keyConceptClass);
    final List<Authorization> permissions = userPermissions.getEntityAuthorizations(dtDefinition).stream().filter(permission -> permission.getOperation().get().equals(operationName.name())).collect(Collectors.toList());
    for (final Authorization permission : permissions) {
        for (final RuleMultiExpression ruleExpression : permission.getRules()) {
            securityRuleTranslator.withRule(ruleExpression);
        }
    }
    return securityRuleTranslator.toSearchQuery();
}
Also used : Authorization(io.vertigo.account.authorization.metamodel.Authorization) RuleMultiExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression) CriteriaSecurityRuleTranslator(io.vertigo.account.impl.authorization.dsl.translator.CriteriaSecurityRuleTranslator) VSecurityManager(io.vertigo.persona.security.VSecurityManager) UserAuthorizations(io.vertigo.account.authorization.UserAuthorizations) AuthorizationName(io.vertigo.account.authorization.metamodel.AuthorizationName) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) Criteria(io.vertigo.dynamo.criteria.Criteria) AuthorizationManager(io.vertigo.account.authorization.AuthorizationManager) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) List(java.util.List) DefinitionUtil(io.vertigo.core.definition.DefinitionUtil) Criterions(io.vertigo.dynamo.criteria.Criterions) Assertion(io.vertigo.lang.Assertion) KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) Optional(java.util.Optional) Authorization(io.vertigo.account.authorization.metamodel.Authorization) OperationName(io.vertigo.account.authorization.metamodel.OperationName) Collections(java.util.Collections) SearchSecurityRuleTranslator(io.vertigo.account.impl.authorization.dsl.translator.SearchSecurityRuleTranslator) UserSession(io.vertigo.persona.security.UserSession) SecuredEntity(io.vertigo.account.authorization.metamodel.SecuredEntity) SearchSecurityRuleTranslator(io.vertigo.account.impl.authorization.dsl.translator.SearchSecurityRuleTranslator) RuleMultiExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) UserAuthorizations(io.vertigo.account.authorization.UserAuthorizations)

Aggregations

DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)91 DtField (io.vertigo.dynamo.domain.metamodel.DtField)29 Test (org.junit.Test)21 URI (io.vertigo.dynamo.domain.model.URI)18 List (java.util.List)17 ArrayList (java.util.ArrayList)16 Assertion (io.vertigo.lang.Assertion)12 Collectors (java.util.stream.Collectors)11 Home (io.vertigo.app.Home)10 Optional (java.util.Optional)10 Domain (io.vertigo.dynamo.domain.metamodel.Domain)9 Collections (java.util.Collections)8 DefinitionUtil (io.vertigo.core.definition.DefinitionUtil)7 DtObjectUtil (io.vertigo.dynamo.domain.util.DtObjectUtil)7 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)7 Inject (javax.inject.Inject)7 Authorization (io.vertigo.account.authorization.metamodel.Authorization)6 SecuredEntity (io.vertigo.account.authorization.metamodel.SecuredEntity)6 Criterions (io.vertigo.dynamo.criteria.Criterions)6 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)5