Package org.sonatype.security.rest.model

Examples of org.sonatype.security.rest.model.RoleResource


  @Test
  public void roleWithSpaceInId()
      throws IOException
  {
    RoleResource resource = new RoleResource();

    resource.setId("role With Space In Id");
    resource.setDescription("roleWithSpaceInId");
    resource.setName("roleWithSpaceInId");
    resource.setSessionTimeout(30);
    resource.addPrivilege("1");

    Response response = this.messageUtil.sendMessage(Method.POST, resource);

    if (!response.getStatus().isSuccess()) {
      Assert.fail("Response: " + response.getEntity().getText() + "Role should have been created: "
          + response.getStatus());
    }

    // make sure the get works too
    Assert.assertEquals(this.messageUtil.getRole(resource.getId()).getId(), "role With Space In Id");
  }
View Full Code Here


  @Test
  public void duplicateIdTest()
      throws IOException
  {

    RoleResource resource = new RoleResource();

    resource.setDescription("duplicateIdTest");
    resource.setName("duplicateIdTest");
    resource.setId("duplicateIdTest");
    resource.setSessionTimeout(30);
    resource.addPrivilege("1");

    // create
    resource = this.messageUtil.createRole(resource);
    Assert.assertEquals(resource.getId(), "duplicateIdTest");

    // update
    Response response = this.messageUtil.sendMessage(Method.POST, resource);

    if (response.getStatus().isSuccess()) {
View Full Code Here

  @Test
  public void createRecursiveContainment()
      throws IOException
  {
    RoleResource resourceA = new RoleResource();
    resourceA.setName("recursive1");
    resourceA.setSessionTimeout(60);
    resourceA.addPrivilege("1");

    Response response = this.messageUtil.sendMessage(Method.POST, resourceA);

    if (!response.getStatus().isSuccess()) {
      Assert.fail("Role should have been created: " + response.getStatus());
    }

    // get the Resource object
    RoleResource responseResourceA = this.messageUtil.getResourceFromResponse(response);

    RoleResource resourceB = new RoleResource();
    resourceB = new RoleResource();
    resourceB.setName("recursive2");
    resourceB.setSessionTimeout(60);
    resourceB.addRole(responseResourceA.getId());

    response = this.messageUtil.sendMessage(Method.POST, resourceB);

    if (!response.getStatus().isSuccess()) {
      Assert.fail("Role should have been created: " + response.getStatus());
    }

    // get the Resource object
    RoleResource responseResourceB = this.messageUtil.getResourceFromResponse(response);

    RoleResource resourceC = new RoleResource();
    resourceC = new RoleResource();
    resourceC.setName("recursive3");
    resourceC.setSessionTimeout(60);
    resourceC.addRole(responseResourceB.getId());

    response = this.messageUtil.sendMessage(Method.POST, resourceC);

    if (!response.getStatus().isSuccess()) {
      Assert.fail("Role should have been created: " + response.getStatus());
    }

    // get the Resource object
    RoleResource responseResourceC = this.messageUtil.getResourceFromResponse(response);

    resourceA.setId(responseResourceA.getId());
    resourceA.getRoles().clear();
    resourceA.addRole(responseResourceC.getId());

    response = this.messageUtil.sendMessage(Method.PUT, resourceA);

    if (response.getStatus().isSuccess()) {
      Assert.fail("Role should not have been updated: " + response.getStatus());
View Full Code Here

    // Then create the roles
    List<String> combined = new ArrayList<String>();
    combined.add(priv1.getId());
    combined.add(priv2.getId());
    RoleResource role1 = createRole("filterRole1", Collections.singletonList(priv1.getId()));
    RoleResource role2 = createRole("filterRole2", Collections.singletonList(priv2.getId()));
    RoleResource role3 = createRole("filterRole3", combined);

    // Now update the test user
    updateUserRole(TEST_USER_NAME, Collections.singletonList(role3.getId()));

    // Now switch to our newly privileged user and do the search
    TestContainer.getInstance().getTestContext().setUsername(TEST_USER_NAME);
    TestContainer.getInstance().getTestContext().setPassword(TEST_USER_PASSWORD);
View Full Code Here

  }

  private RoleResource createRole(String name, List<String> privilegeIds)
      throws Exception
  {
    RoleResource role = new RoleResource();
    role.setName(name);
    role.setDescription("some description");
    role.setSessionTimeout(60);

    for (String privilegeId : privilegeIds) {
      role.addPrivilege(privilegeId);
    }

    role.addPrivilege("1");
    role.addPrivilege("6");
    role.addPrivilege("14");
    role.addPrivilege("17");
    role.addPrivilege("19");
    role.addPrivilege("44");
    role.addPrivilege("54");
    role.addPrivilege("55");
    role.addPrivilege("57");
    role.addPrivilege("58");
    role.addPrivilege("64");

    return this.roleUtil.createRole(role);
  }
View Full Code Here

  @Test
  public void updateValidationTests()
      throws IOException
  {
    RoleResource resource = new RoleResource();

    resource.setDescription("updateValidationTests");
    resource.setName("updateValidationTests");
    resource.setSessionTimeout(99999);
    resource.addPrivilege("5");
    resource.addPrivilege("4");

    Response response = this.messageUtil.sendMessage(Method.POST, resource);

    if (!response.getStatus().isSuccess()) {
      Assert.fail("Could not create role: " + response.getStatus());
    }

    // get the Resource object
    RoleResource responseResource = this.messageUtil.getResourceFromResponse(response);

    // make sure the id != null
    Assert.assertNotNull(responseResource.getId());

    resource.setId(responseResource.getId());

    Assert.assertEquals(responseResource.getDescription(), resource.getDescription());
    Assert.assertEquals(responseResource.getName(), resource.getName());
    Assert.assertEquals(resource.getSessionTimeout(), responseResource.getSessionTimeout());
    Assert.assertEquals(resource.getPrivileges(), responseResource.getPrivileges());
    Assert.assertEquals(resource.getRoles(), responseResource.getRoles());

    getSecurityConfigUtil().verifyRole(resource);

        /*
         * NO Name
View Full Code Here

  @Test
  @Category(SECURITY.class)
  public void deletePriv()
      throws Exception
  {
    RoleResource role = roleUtil.getRole(ROLE_ID);
    Assert.assertNotNull(role);
    MatcherAssert.assertThat(role.getPrivileges(), hasItems(PRIVS));
    privUtil.assertExists(PRIVS);

    // remove read
    Assert.assertTrue(privUtil.delete(READ_PRIV_ID).getStatus().isSuccess());
    role = roleUtil.getRole(ROLE_ID);
    MatcherAssert.assertThat(role.getPrivileges(), not(hasItems(READ_PRIV_ID)));
    MatcherAssert.assertThat(role.getPrivileges(), hasItems(CREATE_PRIV_ID, UPDATE_PRIV_ID, DELETE_PRIV_ID));

    // remove create
    Assert.assertTrue(privUtil.delete(CREATE_PRIV_ID).getStatus().isSuccess());
    role = roleUtil.getRole(ROLE_ID);
    MatcherAssert.assertThat(role.getPrivileges(), not(hasItems(READ_PRIV_ID, CREATE_PRIV_ID)));
    MatcherAssert.assertThat(role.getPrivileges(), hasItems(UPDATE_PRIV_ID, DELETE_PRIV_ID));

    // remove update
    Assert.assertTrue(privUtil.delete(UPDATE_PRIV_ID).getStatus().isSuccess());
    role = roleUtil.getRole(ROLE_ID);
    MatcherAssert.assertThat(role.getPrivileges(), not(hasItems(READ_PRIV_ID, CREATE_PRIV_ID, UPDATE_PRIV_ID)));
    MatcherAssert.assertThat(role.getPrivileges(), hasItems(DELETE_PRIV_ID));

    // remove delete
    Assert.assertTrue(privUtil.delete(DELETE_PRIV_ID).getStatus().isSuccess());
    role = roleUtil.getRole(ROLE_ID);
    MatcherAssert.assertThat(role.getPrivileges(),
        not(hasItems(READ_PRIV_ID, CREATE_PRIV_ID, UPDATE_PRIV_ID, DELETE_PRIV_ID)));
    Assert.assertTrue(role.getPrivileges().isEmpty());

    privUtil.assertNotExists(PRIVS);
  }
View Full Code Here

  @Test
  public void createRoleTest()
      throws IOException
  {

    RoleResource resource = new RoleResource();

    resource.setDescription("Create Test Role");
    resource.setName("CreateRole");
    resource.setSessionTimeout(30);
    resource.addPrivilege("1");
    resource.addPrivilege("2");

    this.messageUtil.createRole(resource);
  }
View Full Code Here

    assertThat(UserCreationUtil.login(), hasStatusCode(403));

    // add login privilege to role
    testContext.useAdminForRequests();

    RoleResource role = roleUtil.getRole(NEXUS504_ROLE);
    role.addPrivilege("2"/* login */);
    assertThat("Unable to add login privilege to role " + NEXUS504_ROLE + "\n"
        + RoleMessageUtil.update(role).getDescription(), RoleMessageUtil.update(role), isSuccess());

    // try to login again
    testContext.setUsername(NEXUS504_USER);
View Full Code Here

  protected static final String ROLE_SOURCE = "default";

  public RoleResource securityToRestModel(Role role, Request request, boolean appendResourceId) {
    // and will convert to the rest object
    RoleResource resource = new RoleResource();

    resource.setDescription(role.getDescription());
    resource.setId(role.getRoleId());
    resource.setName(role.getName());

    String resourceId = "";
    if (appendResourceId) {
      resourceId = resource.getId();
    }
    resource.setResourceURI(this.createChildReference(request, resourceId).toString());

    resource.setUserManaged(!role.isReadOnly());

    for (String roleId : role.getRoles()) {
      resource.addRole(roleId);
    }

    for (String privId : role.getPrivileges()) {
      resource.addPrivilege(privId);
    }

    return resource;
  }
View Full Code Here

TOP

Related Classes of org.sonatype.security.rest.model.RoleResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.