Search in sources :

Example 1 with OperationName

use of io.vertigo.account.authorization.metamodel.OperationName in project vertigo by KleeGroup.

the class AuthorizationManagerImpl method isAuthorized.

/**
 * {@inheritDoc}
 */
@Override
public <K extends KeyConcept> boolean isAuthorized(final K keyConcept, final OperationName<K> operationName) {
    Assertion.checkNotNull(keyConcept);
    Assertion.checkNotNull(operationName);
    // ---
    final Optional<UserAuthorizations> userPermissionsOpt = getUserPermissionsOpt();
    if (!userPermissionsOpt.isPresent()) {
        // Si il n'y a pas de session alors pas d'autorisation.
        return false;
    }
    final UserAuthorizations userPermissions = userPermissionsOpt.get();
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(keyConcept);
    final SecuredEntity securedEntity = findSecuredEntity(dtDefinition);
    return userPermissions.getEntityAuthorizations(dtDefinition).stream().filter(permission -> permission.getOperation().get().equals(operationName.name()) || permission.getOverrides().contains(operationName.name())).flatMap(permission -> permission.getRules().stream()).anyMatch(rule -> new CriteriaSecurityRuleTranslator<K>().on(securedEntity).withRule(rule).withCriteria(userPermissions.getSecurityKeys()).toCriteria().toPredicate().test(keyConcept));
}
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) UserAuthorizations(io.vertigo.account.authorization.UserAuthorizations)

Example 2 with OperationName

use of io.vertigo.account.authorization.metamodel.OperationName 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 3 with OperationName

use of io.vertigo.account.authorization.metamodel.OperationName 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

AuthorizationManager (io.vertigo.account.authorization.AuthorizationManager)3 UserAuthorizations (io.vertigo.account.authorization.UserAuthorizations)3 Authorization (io.vertigo.account.authorization.metamodel.Authorization)3 AuthorizationName (io.vertigo.account.authorization.metamodel.AuthorizationName)3 OperationName (io.vertigo.account.authorization.metamodel.OperationName)3 SecuredEntity (io.vertigo.account.authorization.metamodel.SecuredEntity)3 RuleMultiExpression (io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression)3 CriteriaSecurityRuleTranslator (io.vertigo.account.impl.authorization.dsl.translator.CriteriaSecurityRuleTranslator)3 SearchSecurityRuleTranslator (io.vertigo.account.impl.authorization.dsl.translator.SearchSecurityRuleTranslator)3 Home (io.vertigo.app.Home)3 DefinitionUtil (io.vertigo.core.definition.DefinitionUtil)3 Criteria (io.vertigo.dynamo.criteria.Criteria)3 Criterions (io.vertigo.dynamo.criteria.Criterions)3 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)3 KeyConcept (io.vertigo.dynamo.domain.model.KeyConcept)3 DtObjectUtil (io.vertigo.dynamo.domain.util.DtObjectUtil)3 Assertion (io.vertigo.lang.Assertion)3 UserSession (io.vertigo.persona.security.UserSession)3 VSecurityManager (io.vertigo.persona.security.VSecurityManager)3 Collections (java.util.Collections)3