Search in sources :

Example 1 with SearchSecurityRuleTranslator

use of io.vertigo.account.impl.authorization.dsl.translator.SearchSecurityRuleTranslator in project vertigo by KleeGroup.

the class DslSecurityRulesBuilderTest method testSearchQuery.

private void testSearchQuery(final String[] testParam, final int i) {
    final SearchSecurityRuleTranslator securityRuleTranslator = new SearchSecurityRuleTranslator().withRule(testParam[0]).withCriteria(Collections.singletonMap("query", Collections.singletonList(testParam[1])));
    final String result = securityRuleTranslator.toSearchQuery();
    final String expectedResult = testParam[Math.min(getSearchResult(), testParam.length - 1)];
    Assert.assertEquals("Built search query #" + i + " incorrect", expectedResult, result);
}
Also used : SearchSecurityRuleTranslator(io.vertigo.account.impl.authorization.dsl.translator.SearchSecurityRuleTranslator)

Example 2 with SearchSecurityRuleTranslator

use of io.vertigo.account.impl.authorization.dsl.translator.SearchSecurityRuleTranslator 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

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