use of eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee in project CzechIdMng by bcvsolutions.
the class RoleGuaranteeEvaluator method getPredicate.
@Override
public Predicate getPredicate(Root<IdmRole> root, CriteriaQuery<?> query, CriteriaBuilder builder, AuthorizationPolicy policy, BasePermission... permission) {
AbstractAuthentication authentication = securityService.getAuthentication();
if (authentication == null || authentication.getCurrentIdentity() == null) {
return null;
}
//
if (hasPermission(policy, permission)) {
Subquery<IdmRoleGuarantee> subquery = query.subquery(IdmRoleGuarantee.class);
Root<IdmRoleGuarantee> subRoot = subquery.from(IdmRoleGuarantee.class);
subquery.select(subRoot);
subquery.where(builder.and(// correlation attr
builder.equal(subRoot.get(IdmRoleGuarantee_.role), root), builder.equal(subRoot.get(IdmRoleGuarantee_.guarantee).get(AbstractEntity_.id), authentication.getCurrentIdentity().getId())));
return builder.exists(subquery);
}
return null;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee in project CzechIdMng by bcvsolutions.
the class RoleGuaranteeEvaluatorUnitTest method testEvaluateReadOnly.
@Test
public void testEvaluateReadOnly() {
IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
UUID uuid = UUID.randomUUID();
IdmRole authorizable = new IdmRole();
IdmRoleGuarantee guarantee = new IdmRoleGuarantee();
guarantee.setGuarantee(new IdmIdentity(uuid));
authorizable.getGuarantees().add(guarantee);
policy.setPermissions(IdmBasePermission.READ);
//
when(securityService.getAuthentication()).thenReturn(getAuthentication(uuid));
//
assertTrue(evaluator.evaluate(authorizable, policy, IdmBasePermission.READ));
assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.UPDATE));
assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.ADMIN));
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee in project CzechIdMng by bcvsolutions.
the class RoleGuaranteeEvaluatorUnitTest method testEvaluateFalse.
@Test
public void testEvaluateFalse() {
IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
IdmRole authorizable = new IdmRole();
IdmRoleGuarantee guarantee = new IdmRoleGuarantee();
guarantee.setGuarantee(new IdmIdentity(UUID.randomUUID()));
authorizable.getGuarantees().add(guarantee);
policy.setPermissions(IdmBasePermission.READ);
//
when(securityService.getAuthentication()).thenReturn(getAuthentication());
//
assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.READ));
assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.UPDATE));
assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.ADMIN));
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee in project CzechIdMng by bcvsolutions.
the class DefaultGroovyScriptServiceTest method testSecurityScriptListDeepUnvalid.
@Test(expected = IdmSecurityException.class)
public void testSecurityScriptListDeepUnvalid() {
String script = "return entity.guarantees.get(0);";
groovyScriptService.validateScript(script);
IdmRole role = new IdmRole();
List<IdmRoleGuarantee> guarantees = new ArrayList<>();
guarantees.add(new IdmRoleGuarantee());
role.setGuarantees(guarantees);
role.setName(TEST_ONE);
groovyScriptService.evaluate(script, ImmutableMap.of("entity", role));
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee in project CzechIdMng by bcvsolutions.
the class DefaultGroovyScriptServiceTest method testSecurityScriptListValid.
@Test
public void testSecurityScriptListValid() {
String script = "return list;";
groovyScriptService.validateScript(script);
IdmRole role = new IdmRole();
List<IdmRoleGuarantee> guarantees = new ArrayList<>();
guarantees.add(new IdmRoleGuarantee());
role.setGuarantees(guarantees);
role.setName(TEST_ONE);
Object result = groovyScriptService.evaluate(script, ImmutableMap.of("entity", role, "list", guarantees));
assertEquals(role.getGuarantees(), result);
}
Aggregations