AccessControlAction extends AbstractAuthorizableAction { @Override public void onCreate(@NotNull Group group, @NotNull Root root, @NotNull NamePathMapper namePathMapper) throws RepositoryException { setAC(group, root, namePathMapper); }  @Override void init(SecurityProvider securityProvider, ConfigurationParameters config); @Override void onCreate(@NotNull Group group, @NotNull Root root, @NotNull NamePathMapper namePathMapper); @Override void onCreate(@NotNull User user, @Nullable String password, @NotNull Root root, @NotNull NamePathMapper namePathMapper); static final String USER_PRIVILEGE_NAMES; static final String GROUP_PRIVILEGE_NAMES; }
@Test(expected = IllegalStateException.class) public void testOnCreateUserMissingSecurityProvider() throws Exception { new AccessControlAction().onCreate(mock(User.class), null, root, NamePathMapper.DEFAULT); }
@Test(expected = IllegalStateException.class) public void testOnCreateGroupMissingSecurityProvider() throws Exception { new AccessControlAction().onCreate(mock(Group.class), root, NamePathMapper.DEFAULT); }
@Test public void testOnCreateBuiltinUser() throws Exception { initSecurityProvider("adminId", "anonymousId"); AccessControlAction action = createAction(PrivilegeConstants.JCR_READ); String[] buildinIds = new String[] {"adminId", "anonymousId"}; for (String id : buildinIds) { User user = mockUser(id, null, null); action.onCreate(user, null, root, NamePathMapper.DEFAULT); } }
@Test(expected = RepositoryException.class) public void testOnCreateBuiltinIsGroup() throws Exception { initSecurityProvider("adminIdIsUsedByGroup", "anonymousId"); AccessControlAction action = createAction(PrivilegeConstants.JCR_READ); Group gr = mockGroup("adminIdIsUsedByGroup", null, null); action.onCreate(gr, root, NamePathMapper.DEFAULT); }
@Test public void testOnCreateUserEmptyPrivs() throws Exception { initSecurityProvider(DEFAULT_ADMIN_ID, DEFAULT_ANONYMOUS_ID); AccessControlAction action = createAction(new String[0], new String[] {PrivilegeConstants.JCR_READ}); User user = mockUser("id", null, null); action.onCreate(user, null, root, NamePathMapper.DEFAULT); }
@Test public void testOnCreateGroupEmptyPrivs() throws Exception { initSecurityProvider(DEFAULT_ADMIN_ID, DEFAULT_ANONYMOUS_ID); AccessControlAction action = createAction(new String[] {PrivilegeConstants.JCR_READ}, new String[0]); Group gr = mockGroup("id", null, null); action.onCreate(gr, root, NamePathMapper.DEFAULT); }
@Test public void testOnCreateAdminUser() throws Exception { initSecurityProvider(DEFAULT_ADMIN_ID, DEFAULT_ANONYMOUS_ID, "administrativePrincipal"); AccessControlAction action = createAction(PrivilegeConstants.JCR_READ); User user = mockUser("id", "administrativePrincipal", null); action.onCreate(user, null, root, NamePathMapper.DEFAULT); }
@Test public void testOnCreateAdminGroup() throws Exception { initSecurityProvider(DEFAULT_ADMIN_ID, DEFAULT_ANONYMOUS_ID, "administrativePrincipal"); AccessControlAction action = createAction(PrivilegeConstants.JCR_READ); Group gr = mockGroup("id", "administrativePrincipal", null); action.onCreate(gr, root, NamePathMapper.DEFAULT); }
@Test(expected = RepositoryException.class) public void testOnCreateUserWithoutPath() throws Exception { initSecurityProvider(DEFAULT_ADMIN_ID, DEFAULT_ANONYMOUS_ID); AccessControlAction action = createAction(PrivilegeConstants.JCR_READ); User user = mockUser("id", "principalName", null); action.onCreate(user, null, root, NamePathMapper.DEFAULT); }
@Test(expected = RepositoryException.class) public void testOnCreateGroupWithoutPath() throws Exception { initSecurityProvider(DEFAULT_ADMIN_ID, DEFAULT_ANONYMOUS_ID); AccessControlAction action = createAction(PrivilegeConstants.JCR_READ); Group gr = mockGroup("id", "principal", null); action.onCreate(gr, root, NamePathMapper.DEFAULT); }
@Test public void testOnCreateNoApplicablePolicy() throws Exception { initSecurityProvider(mockAccessControlManager(false), DEFAULT_ADMIN_ID, DEFAULT_ANONYMOUS_ID); AccessControlAction action = createAction(PrivilegeConstants.JCR_READ); action.onCreate(mockUser("userId", "pName", "/none"), "pw", root, NamePathMapper.DEFAULT); }
@Test public void testOnCreateNoApplicableAclPolicy() throws Exception { initSecurityProvider(mockAccessControlManager(false), DEFAULT_ADMIN_ID, DEFAULT_ANONYMOUS_ID); AccessControlAction action = createAction(PrivilegeConstants.JCR_READ); action.onCreate(mockGroup("grId", "pName", "/nonACL"), root, NamePathMapper.DEFAULT); }
@Test public void testOnCreateApplicableAclPolicyForGroup() throws Exception { initSecurityProvider(mockAccessControlManager(false), DEFAULT_ADMIN_ID, DEFAULT_ANONYMOUS_ID); AccessControlAction action = createAction(PrivilegeConstants.JCR_READ); action.onCreate(mockGroup("grId", "pName", "/acl"), root, NamePathMapper.DEFAULT); }
@Test public void testOnCreateApplicableAclPolicyForUser() throws Exception { initSecurityProvider(mockAccessControlManager(true), DEFAULT_ADMIN_ID, DEFAULT_ANONYMOUS_ID); AccessControlAction action = createAction(PrivilegeConstants.JCR_READ); action.onCreate(mockUser("userId", "pName", "/acl"), "pw", root, NamePathMapper.DEFAULT); }