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);
}
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();
}
Aggregations