use of io.vertigo.account.authorization.UserAuthorizations 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));
}
use of io.vertigo.account.authorization.UserAuthorizations in project vertigo by KleeGroup.
the class AuthorizationManagerImpl method getUserPermissionsOpt.
private Optional<UserAuthorizations> getUserPermissionsOpt() {
final Optional<UserSession> userSessionOpt = securityManager.getCurrentUserSession();
if (!userSessionOpt.isPresent()) {
// Si il n'y a pas de session alors pas d'autorisation.
return Optional.empty();
}
UserAuthorizations userAuthorizations = userSessionOpt.get().getAttribute(USER_SESSION_ACL_KEY);
if (userAuthorizations == null) {
userAuthorizations = new UserAuthorizations();
userSessionOpt.get().putAttribute(USER_SESSION_ACL_KEY, userAuthorizations);
}
return Optional.of(userAuthorizations);
}
use of io.vertigo.account.authorization.UserAuthorizations in project vertigo by KleeGroup.
the class AuthorizationManagerImpl method getAuthorizedOperations.
/**
* {@inheritDoc}
*/
@Override
public <K extends KeyConcept> List<String> getAuthorizedOperations(final K keyConcept) {
Assertion.checkNotNull(keyConcept);
// ---
final Optional<UserAuthorizations> userPermissionsOpt = getUserPermissionsOpt();
if (!userPermissionsOpt.isPresent()) {
// Si il n'y a pas de session alors pas d'autorisation.
return Collections.emptyList();
}
final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(keyConcept);
return userPermissionsOpt.get().getEntityAuthorizations(dtDefinition).stream().map(permission -> permission.getOperation().get()).collect(Collectors.toList());
}
use of io.vertigo.account.authorization.UserAuthorizations 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;
}
use of io.vertigo.account.authorization.UserAuthorizations 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