@Test public void testIsValid_valid() throws Exception { Role adminRole = createRole(Roles.ADMIN_ROLE_ID); Role parentRole = createRole("parentRole", "childRole"); Role childRole = createRole("childRole", "grandchildRole"); Role grandchildRole = createRole("grandchildRole", Roles.ADMIN_ROLE_ID); when(authorizationManager.getRole(Roles.ADMIN_ROLE_ID)).thenReturn(adminRole); when(authorizationManager.getRole("parentRole")).thenReturn(parentRole); when(authorizationManager.getRole("childRole")).thenReturn(childRole); when(authorizationManager.getRole("grandchildRole")).thenReturn(grandchildRole); assertThat(underTest.isValid(new TestObj("parentRole", Collections.singleton("childRole")), context), is(true)); }
@Override public boolean isValid(final Object value, final ConstraintValidatorContext context) { log.trace("Validating role doesn't contain itself: {}", value); String id = getId(value); if (Strings2.isEmpty(id)) { return true; } Set<String> processedRoleIds = new HashSet<>(); Collection<String> roleIds = getRoleIds(value); for (String roleId : roleIds) { if (containsRole(id, roleId, processedRoleIds)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); return false; } } return true; }
RoleNotContainSelfValidator extends ConstraintValidatorSupport<RoleNotContainSelf, Object> { @Override public boolean isValid(final Object value, final ConstraintValidatorContext context) { log.trace("Validating role doesn't contain itself: {}", value); String id = getId(value); if (Strings2.isEmpty(id)) { return true; } Set<String> processedRoleIds = new HashSet<>(); Collection<String> roleIds = getRoleIds(value); for (String roleId : roleIds) { if (containsRole(id, roleId, processedRoleIds)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); return false; } } return true; } }
RoleNotContainSelfValidator extends ConstraintValidatorSupport<RoleNotContainSelf, Object> { @Override public boolean isValid(final Object value, final ConstraintValidatorContext context) { log.trace("Validating role doesn't contain itself: {}", value); String id = getId(value); if (Strings2.isEmpty(id)) { return true; } Set<String> processedRoleIds = new HashSet<>(); Collection<String> roleIds = getRoleIds(value); for (String roleId : roleIds) { if (containsRole(id, roleId, processedRoleIds)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); return false; } } return true; } @Inject  RoleNotContainSelfValidator(final SecuritySystem securitySystem); }
RoleNotContainSelfValidator extends ConstraintValidatorSupport<RoleNotContainSelf, Object> { @Override public boolean isValid(final Object value, final ConstraintValidatorContext context) { log.trace("Validating role doesn't contain itself: {}", value); String id = getId(value); if (Strings2.isEmpty(id)) { return true; } Set<String> processedRoleIds = new HashSet<>(); Collection<String> roleIds = getRoleIds(value); for (String roleId : roleIds) { if (containsRole(id, roleId, processedRoleIds)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); return false; } } return true; } @Inject  RoleNotContainSelfValidator(final SecuritySystem securitySystem); @Override void initialize(RoleNotContainSelf constraintAnnotation); @Override boolean isValid(final Object value, final ConstraintValidatorContext context); }
RoleNotContainSelfValidator extends ConstraintValidatorSupport<RoleNotContainSelf, Object> { @Override public boolean isValid(final Object value, final ConstraintValidatorContext context) { log.trace("Validating role doesn't contain itself: {}", value); String id = getId(value); if (Strings2.isEmpty(id)) { return true; } Set<String> processedRoleIds = new HashSet<>(); Collection<String> roleIds = getRoleIds(value); for (String roleId : roleIds) { if (containsRole(id, roleId, processedRoleIds)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); return false; } } return true; } @Inject  RoleNotContainSelfValidator(final SecuritySystem securitySystem); @Override void initialize(RoleNotContainSelf constraintAnnotation); @Override boolean isValid(final Object value, final ConstraintValidatorContext context);  }