@Test public void changePrimaryTypeValid() throws Exception { Tree userTree = root.getTree(userPath); UserValidator validator = createUserValidator(userTree, userTree); validator.propertyChanged(PropertyStates.createProperty(JCR_PRIMARYTYPE, NT_REP_GROUP), userTree.getProperty(JCR_PRIMARYTYPE)); }
@Override public void propertyChanged(PropertyState before, PropertyState after) throws CommitFailedException { if (authorizableType == null) { return; } String name = before.getName(); if (REP_PRINCIPAL_NAME.equals(name) || REP_AUTHORIZABLE_ID.equals(name)) { String msg = "Authorizable property " + name + " may not be altered after user/group creation."; throw constraintViolation(22, msg); } else if (JcrConstants.JCR_UUID.equals(name)) { checkNotNull(parentAfter); if (!isValidUUID(parentAfter, after.getValue(Type.STRING))) { String msg = "Invalid jcr:uuid for authorizable " + parentAfter.getName(); throw constraintViolation(23, msg); } } else if (JcrConstants.JCR_PRIMARYTYPE.equals(name)) { validateAuthorizable(parentAfter, UserUtil.getType(after.getValue(Type.STRING))); } boolean isUser = authorizableType == AuthorizableType.USER; if (isUser && REP_PASSWORD.equals(name) && PasswordUtil.isPlainTextPassword(after.getValue(Type.STRING))) { String msg = "Password may not be plain text."; throw constraintViolation(24, msg); } }
UserValidator extends DefaultValidator implements UserConstants { @Override public void propertyChanged(PropertyState before, PropertyState after) throws CommitFailedException { if (authorizableType == null) { return; } String name = before.getName(); if (REP_PRINCIPAL_NAME.equals(name) || REP_AUTHORIZABLE_ID.equals(name)) { String msg = "Authorizable property " + name + " may not be altered after user/group creation."; throw constraintViolation(22, msg); } else if (JcrConstants.JCR_UUID.equals(name)) { checkNotNull(parentAfter); if (!isValidUUID(parentAfter, after.getValue(Type.STRING))) { String msg = "Invalid jcr:uuid for authorizable " + parentAfter.getName(); throw constraintViolation(23, msg); } } else if (JcrConstants.JCR_PRIMARYTYPE.equals(name)) { validateAuthorizable(parentAfter, UserUtil.getType(after.getValue(Type.STRING))); } boolean isUser = authorizableType == AuthorizableType.USER; if (isUser && REP_PASSWORD.equals(name) && PasswordUtil.isPlainTextPassword(after.getValue(Type.STRING))) { String msg = "Password may not be plain text."; throw constraintViolation(24, msg); } } }
UserValidator extends DefaultValidator implements UserConstants { @Override public void propertyChanged(PropertyState before, PropertyState after) throws CommitFailedException { if (authorizableType == null) { return; } String name = before.getName(); if (REP_PRINCIPAL_NAME.equals(name) || REP_AUTHORIZABLE_ID.equals(name)) { String msg = "Authorizable property " + name + " may not be altered after user/group creation."; throw constraintViolation(22, msg); } else if (JcrConstants.JCR_UUID.equals(name)) { checkNotNull(parentAfter); if (!isValidUUID(parentAfter, after.getValue(Type.STRING))) { String msg = "Invalid jcr:uuid for authorizable " + parentAfter.getName(); throw constraintViolation(23, msg); } } else if (JcrConstants.JCR_PRIMARYTYPE.equals(name)) { validateAuthorizable(parentAfter, UserUtil.getType(after.getValue(Type.STRING))); } boolean isUser = authorizableType == AuthorizableType.USER; if (isUser && REP_PASSWORD.equals(name) && PasswordUtil.isPlainTextPassword(after.getValue(Type.STRING))) { String msg = "Password may not be plain text."; throw constraintViolation(24, msg); } } UserValidator(Tree parentBefore, Tree parentAfter, UserValidatorProvider provider); }
UserValidator extends DefaultValidator implements UserConstants { @Override public void propertyChanged(PropertyState before, PropertyState after) throws CommitFailedException { if (authorizableType == null) { return; } String name = before.getName(); if (REP_PRINCIPAL_NAME.equals(name) || REP_AUTHORIZABLE_ID.equals(name)) { String msg = "Authorizable property " + name + " may not be altered after user/group creation."; throw constraintViolation(22, msg); } else if (JcrConstants.JCR_UUID.equals(name)) { checkNotNull(parentAfter); if (!isValidUUID(parentAfter, after.getValue(Type.STRING))) { String msg = "Invalid jcr:uuid for authorizable " + parentAfter.getName(); throw constraintViolation(23, msg); } } else if (JcrConstants.JCR_PRIMARYTYPE.equals(name)) { validateAuthorizable(parentAfter, UserUtil.getType(after.getValue(Type.STRING))); } boolean isUser = authorizableType == AuthorizableType.USER; if (isUser && REP_PASSWORD.equals(name) && PasswordUtil.isPlainTextPassword(after.getValue(Type.STRING))) { String msg = "Password may not be plain text."; throw constraintViolation(24, msg); } } UserValidator(Tree parentBefore, Tree parentAfter, UserValidatorProvider provider); @Override void propertyAdded(PropertyState after); @Override void propertyChanged(PropertyState before, PropertyState after); @Override void propertyDeleted(PropertyState before); @Override Validator childNodeAdded(String name, NodeState after); @Override Validator childNodeChanged(String name, NodeState before, NodeState after); @Override Validator childNodeDeleted(String name, NodeState before); }
UserValidator extends DefaultValidator implements UserConstants { @Override public void propertyChanged(PropertyState before, PropertyState after) throws CommitFailedException { if (authorizableType == null) { return; } String name = before.getName(); if (REP_PRINCIPAL_NAME.equals(name) || REP_AUTHORIZABLE_ID.equals(name)) { String msg = "Authorizable property " + name + " may not be altered after user/group creation."; throw constraintViolation(22, msg); } else if (JcrConstants.JCR_UUID.equals(name)) { checkNotNull(parentAfter); if (!isValidUUID(parentAfter, after.getValue(Type.STRING))) { String msg = "Invalid jcr:uuid for authorizable " + parentAfter.getName(); throw constraintViolation(23, msg); } } else if (JcrConstants.JCR_PRIMARYTYPE.equals(name)) { validateAuthorizable(parentAfter, UserUtil.getType(after.getValue(Type.STRING))); } boolean isUser = authorizableType == AuthorizableType.USER; if (isUser && REP_PASSWORD.equals(name) && PasswordUtil.isPlainTextPassword(after.getValue(Type.STRING))) { String msg = "Password may not be plain text."; throw constraintViolation(24, msg); } } UserValidator(Tree parentBefore, Tree parentAfter, UserValidatorProvider provider); @Override void propertyAdded(PropertyState after); @Override void propertyChanged(PropertyState before, PropertyState after); @Override void propertyDeleted(PropertyState before); @Override Validator childNodeAdded(String name, NodeState after); @Override Validator childNodeChanged(String name, NodeState before, NodeState after); @Override Validator childNodeDeleted(String name, NodeState before);  }