@SuppressWarnings("unchecked") @Test public void createReadMethodTest() throws IOException { PrivilegeResource resource = new PrivilegeResource(); List methods = new ArrayList<String>(); methods.add("read"); resource.setMethod(methods); resource.setName("createReadMethodTest"); resource.setType(TargetPrivilegeDescriptor.TYPE); resource.setRepositoryTargetId("testTarget"); // get the Resource object List<PrivilegeStatusResource> statusResources = this.messageUtil.createPrivileges(resource); Assert.assertTrue(statusResources.size() == 1); // make sure the id != null Assert.assertNotNull(statusResources.get(0).getId()); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( statusResources.get(0), ApplicationPrivilegeMethodPropertyDescriptor.ID), "read"); Assert.assertEquals( statusResources.get(0).getName(), "createReadMethodTest - (read)"); // ' - (read)' is // automatically added Assert.assertEquals(statusResources.get(0).getType(), TargetPrivilegeDescriptor.TYPE); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( statusResources.get(0), TargetPrivilegeRepositoryTargetPropertyDescriptor.ID), "testTarget"); SecurityConfigUtil.verifyPrivileges(statusResources); }
@SuppressWarnings("unchecked") @Test public void listTest() throws IOException { if (printKnownErrorButDoNotFail(Nexus233PrivilegesCrudXMLIT.class, "listTest")) { return; } PrivilegeResource resource = new PrivilegeResource(); List methods = new ArrayList<String>(); methods.add("read"); resource.setMethod(methods); resource.setName("listTest"); resource.setType(TargetPrivilegeDescriptor.TYPE); resource.setRepositoryTargetId("testTarget"); // get the Resource object List<PrivilegeStatusResource> statusResources = this.messageUtil.createPrivileges(resource); Assert.assertTrue(statusResources.size() == 1); // make sure the id != null Assert.assertNotNull(statusResources.get(0).getId()); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( statusResources.get(0), ApplicationPrivilegeMethodPropertyDescriptor.ID), "read"); Assert.assertEquals(statusResources.get(0).getName(), "listTest - (read)"); // ' - (read)' is // automatically added Assert.assertEquals(statusResources.get(0).getType(), TargetPrivilegeDescriptor.TYPE); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( statusResources.get(0), TargetPrivilegeRepositoryTargetPropertyDescriptor.ID), "testTarget"); SecurityConfigUtil.verifyPrivileges(statusResources); // now we have something in the repo. now lets get it all... Response response = this.messageUtil.sendMessage(Method.GET, resource); // get the Resource object statusResources = this.messageUtil.getResourceListFromResponse(response); SecurityConfigUtil.verifyPrivileges(statusResources); }
@SuppressWarnings("unchecked") @Test public void deleteTest() throws IOException { PrivilegeResource resource = new PrivilegeResource(); List methods = new ArrayList<String>(); methods.add("read"); resource.setMethod(methods); resource.setName("deleteTest"); resource.setType(TargetPrivilegeDescriptor.TYPE); resource.setRepositoryTargetId("testTarget"); // get the Resource object List<PrivilegeStatusResource> statusResources = this.messageUtil.createPrivileges(resource); Assert.assertTrue(statusResources.size() == 1); // make sure the id != null Assert.assertNotNull(statusResources.get(0).getId()); String readPrivId = statusResources.get(0).getId(); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( statusResources.get(0), ApplicationPrivilegeMethodPropertyDescriptor.ID), "read"); Assert.assertEquals(statusResources.get(0).getName(), "deleteTest - (read)"); // ' - (read)' is // automatically // added Assert.assertEquals(statusResources.get(0).getType(), TargetPrivilegeDescriptor.TYPE); Assert.assertEquals( SecurityConfigUtil.getPrivilegeProperty( statusResources.get(0), TargetPrivilegeRepositoryTargetPropertyDescriptor.ID), "testTarget"); Response response = this.messageUtil.sendMessage(Method.DELETE, resource, readPrivId); if (!response.getStatus().isSuccess()) // Method Not Allowed { Assert.fail("Delete failed: " + response.getStatus()); } Assert.assertNull(SecurityConfigUtil.getCPrivilege(readPrivId)); }
private PrivilegeStatusResource getPrivilegeByMethod( String method, List<PrivilegeStatusResource> statusResources) { for (Iterator<PrivilegeStatusResource> iter = statusResources.iterator(); iter.hasNext(); ) { PrivilegeStatusResource privilegeBaseStatusResource = iter.next(); if (SecurityConfigUtil.getPrivilegeProperty( privilegeBaseStatusResource, ApplicationPrivilegeMethodPropertyDescriptor.ID) .equals(method)) { return privilegeBaseStatusResource; } } return null; }
@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); }