use of io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression in project vertigo by KleeGroup.
the class AbstractSecurityRuleTranslator method withRule.
/**
* Set security pattern.
* @param securityRule security Pattern (not null, could be empty)
* @return this builder
*/
public final S withRule(final String securityRule) {
Assertion.checkNotNull(securityRule);
// -----
try {
final RuleMultiExpression myMultiExpression = DslParserUtil.parseMultiExpression(securityRule);
myMultiExpressions.add(myMultiExpression);
} catch (final PegNoMatchFoundException e) {
final String message = StringUtil.format("Echec de lecture de la securityRule {0}\n{1}", securityRule, e.getFullMessage());
throw WrappedException.wrap(e, message);
} catch (final Exception e) {
final String message = StringUtil.format("Echec de lecture de la securityRule {0}\n{1}", securityRule, e.getMessage());
throw WrappedException.wrap(e, message);
}
return (S) this;
}
use of io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression in project vertigo by KleeGroup.
the class SearchSecurityRuleTranslator method appendMultiExpression.
private void appendMultiExpression(final StringBuilder query, final RuleMultiExpression multiExpressionDefinition) {
String sep = "";
String boolSep;
if (multiExpressionDefinition.getBoolOperator() == BoolOperator.AND) {
boolSep = "+";
} else {
boolSep = "";
}
for (final RuleExpression expression : multiExpressionDefinition.getExpressions()) {
query.append(sep).append(boolSep);
appendExpression(query, expression);
sep = " ";
}
for (final RuleMultiExpression multiExpression : multiExpressionDefinition.getMultiExpressions()) {
query.append(sep).append(boolSep).append('(');
appendMultiExpression(query, multiExpression);
query.append(')');
sep = " ";
}
}
use of io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression in project vertigo by KleeGroup.
the class SqlSecurityRuleTranslator method appendMultiExpression.
private void appendMultiExpression(final StringBuilder query, final RuleMultiExpression multiExpressionDefinition) {
String sep = "";
final String boolSep = " " + multiExpressionDefinition.getBoolOperator() + " ";
if (multiExpressionDefinition.isBlock()) {
query.append('(');
}
for (final RuleExpression expression : multiExpressionDefinition.getExpressions()) {
query.append(sep);
appendExpression(query, expression);
sep = boolSep;
}
for (final RuleMultiExpression multiExpression : multiExpressionDefinition.getMultiExpressions()) {
query.append(sep);
appendMultiExpression(query, multiExpression);
sep = boolSep;
}
if (multiExpressionDefinition.isBlock()) {
query.append(')');
}
}
use of io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression 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();
}
use of io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression in project vertigo by KleeGroup.
the class DslMultiExpressionRule method handle.
/**
* {@inheritDoc}
*/
@Override
protected RuleMultiExpression handle(final PegChoice parsing) {
final List<Object> innerBlock;
switch(parsing.getChoiceIndex()) {
case 0:
final List<?> blockExpression = (List<?>) parsing.getValue();
innerBlock = (List<Object>) blockExpression.get(2);
break;
case 1:
innerBlock = (List<Object>) parsing.getValue();
break;
default:
throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
}
final List<RuleExpression> expressionDefinitions = new ArrayList<>();
final List<RuleMultiExpression> multiExpressionDefinitions = new ArrayList<>();
// first (expression1|multiExpression1)
final PegChoice firstExpressionChoice = (PegChoice) innerBlock.get(1);
switch(firstExpressionChoice.getChoiceIndex()) {
case 0:
expressionDefinitions.add((RuleExpression) firstExpressionChoice.getValue());
break;
case 1:
multiExpressionDefinitions.add((RuleMultiExpression) firstExpressionChoice.getValue());
break;
default:
throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
}
// manyNextExpressionsRule
final List<List<Object>> many = (List<List<Object>>) innerBlock.get(3);
// On récupère le produit de la règle many
BoolOperator operator = null;
for (final List<Object> item : many) {
if (operator != null && operator != item.get(1)) {
throw new IllegalArgumentException("Can't use different operator in same block, attempt to find " + operator);
}
operator = (BoolOperator) item.get(1);
// next (expression2|multiExpression2)
final PegChoice nextExpressionChoice = (PegChoice) item.get(3);
switch(nextExpressionChoice.getChoiceIndex()) {
case 0:
expressionDefinitions.add((RuleExpression) nextExpressionChoice.getValue());
break;
case 1:
multiExpressionDefinitions.add((RuleMultiExpression) nextExpressionChoice.getValue());
break;
default:
throw new IllegalArgumentException("case " + nextExpressionChoice.getChoiceIndex() + " not implemented");
}
}
final boolean block = parsing.getChoiceIndex() == 0;
// ---
return new RuleMultiExpression(block, operator != null ? operator : BoolOperator.AND, expressionDefinitions, multiExpressionDefinitions);
}
Aggregations