private int getExpectedPrivilegeCount() throws Exception { TestContainer.getInstance().getTestContext().useAdminForRequests(); Set<String> privIds = new HashSet<String>(); List<PrivilegeStatusResource> privs = new PrivilegesMessageUtil(this, XStreamFactory.getXmlXStream(), MediaType.APPLICATION_XML) .getList(); for (PrivilegeStatusResource priv : privs) { if (priv.getType().equals("method")) { for (PrivilegeProperty prop : priv.getProperties()) { if (prop.getKey().equals("permission")) { privIds.add(prop.getValue()); } } } } return privIds.size(); // return getUserPrivs( TestContainer.getInstance().getTestContext().getUsername() ).size(); }
@SuppressWarnings("unchecked") @Test public void createAllMethodTest() throws IOException { PrivilegeResource resource = new PrivilegeResource(); List methods = new ArrayList<String>(); methods.add("create"); methods.add("read"); methods.add("update"); methods.add("delete"); resource.setMethod(methods); resource.setName("createAllMethodTest"); resource.setType(TargetPrivilegeDescriptor.TYPE); resource.setRepositoryTargetId("testTarget"); // get the Resource object List<PrivilegeStatusResource> statusResources = this.messageUtil.createPrivileges(resource); Assert.assertTrue(statusResources.size() == 4); PrivilegeStatusResource createPriv = this.getPrivilegeByMethod("create,read", statusResources); Assert.assertNotNull(createPriv.getId()); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( createPriv, ApplicationPrivilegeMethodPropertyDescriptor.ID), "create,read"); Assert.assertEquals(createPriv.getName(), "createAllMethodTest - (create)"); Assert.assertEquals(createPriv.getType(), TargetPrivilegeDescriptor.TYPE); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( createPriv, TargetPrivilegeRepositoryTargetPropertyDescriptor.ID), "testTarget"); PrivilegeStatusResource readPriv = this.getPrivilegeByMethod("read", statusResources); Assert.assertNotNull(readPriv.getId()); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( readPriv, ApplicationPrivilegeMethodPropertyDescriptor.ID), "read"); Assert.assertEquals(readPriv.getName(), "createAllMethodTest - (read)"); Assert.assertEquals(readPriv.getType(), TargetPrivilegeDescriptor.TYPE); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( readPriv, TargetPrivilegeRepositoryTargetPropertyDescriptor.ID), "testTarget"); PrivilegeStatusResource updatePriv = this.getPrivilegeByMethod("update,read", statusResources); Assert.assertNotNull(updatePriv.getId()); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( updatePriv, ApplicationPrivilegeMethodPropertyDescriptor.ID), "update,read"); Assert.assertEquals(updatePriv.getName(), "createAllMethodTest - (update)"); Assert.assertEquals(updatePriv.getType(), TargetPrivilegeDescriptor.TYPE); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( updatePriv, TargetPrivilegeRepositoryTargetPropertyDescriptor.ID), "testTarget"); PrivilegeStatusResource deletePriv = this.getPrivilegeByMethod("delete,read", statusResources); Assert.assertNotNull(deletePriv.getId()); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( deletePriv, ApplicationPrivilegeMethodPropertyDescriptor.ID), "delete,read"); Assert.assertEquals(deletePriv.getName(), "createAllMethodTest - (delete)"); Assert.assertEquals(deletePriv.getType(), TargetPrivilegeDescriptor.TYPE); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( deletePriv, TargetPrivilegeRepositoryTargetPropertyDescriptor.ID), "testTarget"); SecurityConfigUtil.verifyPrivileges(statusResources); }