@Override void checkValidTree(@NotNull Tree tree) throws RepositoryException { super.checkValidTree(tree); if (!UserUtil.isSystemUser(tree)) { throw new IllegalArgumentException("Invalid user node: node type rep:SystemUser expected."); } }
@Override void checkValidTree(@NotNull Tree tree) throws RepositoryException { super.checkValidTree(tree); if (!UserUtil.isSystemUser(tree)) { throw new IllegalArgumentException("Invalid user node: node type rep:SystemUser expected."); } }
@Override void checkValidTree(@Nonnull Tree tree) throws RepositoryException { super.checkValidTree(tree); if (!UserUtil.isSystemUser(tree)) { throw new IllegalArgumentException("Invalid user node: node type rep:SystemUser expected."); } }
@Nullable private Principal createUserPrincipal(@NotNull String id, @NotNull Tree userTree) { String principalName = getPrincipalName(userTree); if (principalName == null) { return null; } if (UserUtil.isSystemUser(userTree)) { return new SystemUserPrincipalImpl(principalName, userTree, namePathMapper); } else if (UserUtil.isAdmin(config.getParameters(), id)) { return new AdminPrincipalImpl(principalName, userTree, namePathMapper); } else { return new TreeBasedPrincipal(principalName, userTree, namePathMapper); } }
@Nullable private Principal createUserPrincipal(@NotNull String id, @NotNull Tree userTree) { String principalName = getPrincipalName(userTree); if (principalName == null) { return null; } if (UserUtil.isSystemUser(userTree)) { return new SystemUserPrincipalImpl(principalName, userTree, namePathMapper); } else if (UserUtil.isAdmin(config.getParameters(), id)) { return new AdminPrincipalImpl(principalName, userTree, namePathMapper); } else { return new TreeBasedPrincipal(principalName, userTree, namePathMapper); } }
@CheckForNull private Principal createUserPrincipal(@Nonnull String id, @Nonnull Tree userTree) { String principalName = getPrincipalName(userTree); if (principalName == null) { return null; } if (UserUtil.isSystemUser(userTree)) { return new SystemUserPrincipalImpl(principalName, userTree, namePathMapper); } else if (UserUtil.isAdmin(config.getParameters(), id)) { return new AdminPrincipalImpl(principalName, userTree, namePathMapper); } else { return new TreeBasedPrincipal(principalName, userTree, namePathMapper); } }
@Nullable private Authorizable getAuthorizable(@Nullable String id, @Nullable Tree tree) throws RepositoryException { if (id == null || tree == null) { return null; } if (UserUtil.isType(tree, AuthorizableType.USER)) { if (UserUtil.isSystemUser(tree)) { return new SystemUserImpl(id, tree, this); } else { return new UserImpl(id, tree, this); } } else if (UserUtil.isType(tree, AuthorizableType.GROUP)) { return new GroupImpl(id, tree, this); } else { throw new RepositoryException("Not a user or group tree " + tree.getPath() + '.'); } }
@Nullable private Authorizable getAuthorizable(@Nullable String id, @Nullable Tree tree) throws RepositoryException { if (id == null || tree == null) { return null; } if (UserUtil.isType(tree, AuthorizableType.USER)) { if (UserUtil.isSystemUser(tree)) { return new SystemUserImpl(id, tree, this); } else { return new UserImpl(id, tree, this); } } else if (UserUtil.isType(tree, AuthorizableType.GROUP)) { return new GroupImpl(id, tree, this); } else { throw new RepositoryException("Not a user or group tree " + tree.getPath() + '.'); } }
@CheckForNull private Authorizable getAuthorizable(@CheckForNull String id, @CheckForNull Tree tree) throws RepositoryException { if (id == null || tree == null) { return null; } if (UserUtil.isType(tree, AuthorizableType.USER)) { if (UserUtil.isSystemUser(tree)) { return new SystemUserImpl(id, tree, this); } else { return new UserImpl(id, tree, this); } } else if (UserUtil.isType(tree, AuthorizableType.GROUP)) { return new GroupImpl(id, tree, this); } else { throw new RepositoryException("Not a user or group tree " + tree.getPath() + '.'); } }
@Test public void testIsSystemUser() { Map<String, Boolean> test = ImmutableMap.of( UserConstants.NT_REP_GROUP, false, UserConstants.NT_REP_USER, false, UserConstants.NT_REP_SYSTEM_USER, true, UserConstants.NT_REP_AUTHORIZABLE, false, JcrConstants.NT_FILE, false ); for (String ntName : test.keySet()) { boolean expected = test.get(ntName); assertEquals(ntName, expected, UserUtil.isSystemUser(createTree(ntName))); } }
@Test public void testIsSystemUserNullTree() { assertFalse(UserUtil.isSystemUser(null)); }
private void validateAuthorizable(@Nonnull Tree tree, @Nullable AuthorizableType type) throws CommitFailedException { boolean isSystemUser = (type == AuthorizableType.USER) && UserUtil.isSystemUser(tree); String authRoot = UserUtil.getAuthorizableRootPath(provider.getConfig(), type); if (isSystemUser) { String sysRelPath = provider.getConfig().getConfigValue(PARAM_SYSTEM_RELATIVE_PATH, DEFAULT_SYSTEM_RELATIVE_PATH); authRoot = authRoot + '/' + sysRelPath; } if (authRoot != null) { assertHierarchy(tree, authRoot); // assert rep:principalName is present (that should actually by covered // by node type validator) if (TreeUtil.getString(tree, REP_PRINCIPAL_NAME) == null) { throw constraintViolation(26, "Mandatory property rep:principalName missing."); } if (isSystemUser) { if (TreeUtil.getString(tree, REP_PASSWORD) != null) { throw constraintViolation(32, "Attempt to set password with system user."); } if (tree.hasChild(REP_PWD)) { throw constraintViolation(33, "Attempt to add rep:pwd node to a system user."); } } } }
private void validateAuthorizable(@NotNull Tree tree, @Nullable AuthorizableType type) throws CommitFailedException { boolean isSystemUser = (type == AuthorizableType.USER) && UserUtil.isSystemUser(tree); String authRoot = UserUtil.getAuthorizableRootPath(provider.getConfig(), type); if (isSystemUser) { String sysRelPath = provider.getConfig().getConfigValue(PARAM_SYSTEM_RELATIVE_PATH, DEFAULT_SYSTEM_RELATIVE_PATH); authRoot = authRoot + '/' + sysRelPath; } if (authRoot != null) { assertHierarchy(tree, authRoot); // assert rep:principalName is present (that should actually by covered // by node type validator) if (TreeUtil.getString(tree, REP_PRINCIPAL_NAME) == null) { throw constraintViolation(26, "Mandatory property rep:principalName missing."); } if (isSystemUser) { if (TreeUtil.getString(tree, REP_PASSWORD) != null) { throw constraintViolation(32, "Attempt to set password with system user."); } if (tree.hasChild(REP_PWD)) { throw constraintViolation(33, "Attempt to add rep:pwd node to a system user."); } } } }
private void validateAuthorizable(@NotNull Tree tree, @Nullable AuthorizableType type) throws CommitFailedException { boolean isSystemUser = (type == AuthorizableType.USER) && UserUtil.isSystemUser(tree); String authRoot = UserUtil.getAuthorizableRootPath(provider.getConfig(), type); if (isSystemUser) { String sysRelPath = provider.getConfig().getConfigValue(PARAM_SYSTEM_RELATIVE_PATH, DEFAULT_SYSTEM_RELATIVE_PATH); authRoot = authRoot + '/' + sysRelPath; } if (authRoot != null) { assertHierarchy(tree, authRoot); // assert rep:principalName is present (that should actually by covered // by node type validator) if (TreeUtil.getString(tree, REP_PRINCIPAL_NAME) == null) { throw constraintViolation(26, "Mandatory property rep:principalName missing."); } if (isSystemUser) { if (TreeUtil.getString(tree, REP_PASSWORD) != null) { throw constraintViolation(32, "Attempt to set password with system user."); } if (tree.hasChild(REP_PWD)) { throw constraintViolation(33, "Attempt to add rep:pwd node to a system user."); } } } }