@Test public void isValid_ignoresJavaElExpression() { ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); when(context.buildConstraintViolationWithTemplate(any())) .thenReturn(mock(ConstraintValidatorContext.ConstraintViolationBuilder.class)); assertThat(underTest.isValid(Collections .singleton("dx27e${\"gggggggggggggggggggggggggggggggggggggggggggz\".toString().replace(\"g\", \"q\")}yv5rm"), context), is(false)); verify(context).buildConstraintViolationWithTemplate( "Missing roles: [dx27e{\"gggggggggggggggggggggggggggggggggggggggggggz\".toString().replace(\"g\", \"q\")}yv5rm]"); }
@Override public boolean isValid(final Collection<?> value, final ConstraintValidatorContext context) { log.trace("Validating roles exist: {}", value); List<Object> missing = new LinkedList<>(); for (Object item : value) { try { authorizationManager.getRole(String.valueOf(item)); } catch (NoSuchRoleException e) { missing.add(getEscapeHelper().stripJavaEl(item.toString())); } } if (missing.isEmpty()) { return true; } context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("Missing roles: " + missing) .addConstraintViolation(); return false; }
RolesExistValidator extends ConstraintValidatorSupport<RolesExist, Collection<?>> { @Override public boolean isValid(final Collection<?> value, final ConstraintValidatorContext context) { log.trace("Validating roles exist: {}", value); List<Object> missing = new LinkedList<>(); for (Object item : value) { try { authorizationManager.getRole(String.valueOf(item)); } catch (NoSuchRoleException e) { missing.add(getEscapeHelper().stripJavaEl(item.toString())); } } if (missing.isEmpty()) { return true; } context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("Missing roles: " + missing) .addConstraintViolation(); return false; } }
RolesExistValidator extends ConstraintValidatorSupport<RolesExist, Collection<?>> { @Override public boolean isValid(final Collection<?> value, final ConstraintValidatorContext context) { log.trace("Validating roles exist: {}", value); List<Object> missing = new LinkedList<>(); for (Object item : value) { try { authorizationManager.getRole(String.valueOf(item)); } catch (NoSuchRoleException e) { missing.add(getEscapeHelper().stripJavaEl(item.toString())); } } if (missing.isEmpty()) { return true; } context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("Missing roles: " + missing) .addConstraintViolation(); return false; } @Inject  RolesExistValidator(final SecuritySystem securitySystem); }
RolesExistValidator extends ConstraintValidatorSupport<RolesExist, Collection<?>> { @Override public boolean isValid(final Collection<?> value, final ConstraintValidatorContext context) { log.trace("Validating roles exist: {}", value); List<Object> missing = new LinkedList<>(); for (Object item : value) { try { authorizationManager.getRole(String.valueOf(item)); } catch (NoSuchRoleException e) { missing.add(getEscapeHelper().stripJavaEl(item.toString())); } } if (missing.isEmpty()) { return true; } context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("Missing roles: " + missing) .addConstraintViolation(); return false; } @Inject  RolesExistValidator(final SecuritySystem securitySystem); @Override boolean isValid(final Collection<?> value, final ConstraintValidatorContext context); }
RolesExistValidator extends ConstraintValidatorSupport<RolesExist, Collection<?>> { @Override public boolean isValid(final Collection<?> value, final ConstraintValidatorContext context) { log.trace("Validating roles exist: {}", value); List<Object> missing = new LinkedList<>(); for (Object item : value) { try { authorizationManager.getRole(String.valueOf(item)); } catch (NoSuchRoleException e) { missing.add(getEscapeHelper().stripJavaEl(item.toString())); } } if (missing.isEmpty()) { return true; } context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("Missing roles: " + missing) .addConstraintViolation(); return false; } @Inject  RolesExistValidator(final SecuritySystem securitySystem); @Override boolean isValid(final Collection<?> value, final ConstraintValidatorContext context);  }