Package org.sonatype.security.authorization

Examples of org.sonatype.security.authorization.Role


  }

  public Set<Role> listRoles() {
    Set<Role> roles = new HashSet<Role>();

    Role role1 = new Role();
    role1.setSource(this.getSource());
    role1.setName("Role 1");
    role1.setRoleId("test-role1");
    role1.addPrivilege("from-role1:read");
    role1.addPrivilege("from-role1:delete");

    Role role2 = new Role();
    role2.setSource(this.getSource());
    role2.setName("Role 2");
    role2.setRoleId("test-role2");
    role2.addPrivilege("from-role2:read");
    role2.addPrivilege("from-role2:delete");

    roles.add(role1);
    roles.add(role2);

    return roles;
View Full Code Here


public class RoleTest
    extends InjectedTestCase
{

  public void testCompareDifferentId() {
    Role roleA = new Role();
    roleA.setName("ID1");
    roleA.setRoleId("ID1");
    roleA.setSource("source");

    Role roleB = new Role();
    roleB.setName("ID2");
    roleB.setRoleId("ID2");
    roleB.setSource("source");

    Assert.assertEquals(-1, roleA.compareTo(roleB));
    Assert.assertEquals(1, roleB.compareTo(roleA));

  }
View Full Code Here

    Assert.assertEquals(1, roleB.compareTo(roleA));

  }

  public void testCompareDifferentSource() {
    Role roleA = new Role();
    roleA.setName("ID1");
    roleA.setRoleId("ID1");
    roleA.setSource("source1");

    Role roleB = new Role();
    roleB.setName("ID1");
    roleB.setRoleId("ID1");
    roleB.setSource("source2");

    Assert.assertEquals(-1, roleA.compareTo(roleB));
    Assert.assertEquals(1, roleB.compareTo(roleA));

  }
View Full Code Here

  public String getSource() {
    return SOURCE;
  }

  protected Role toRole(CRole secRole) {
    Role role = new Role();

    role.setRoleId(secRole.getId());
    role.setName(secRole.getName());
    role.setSource(SOURCE);
    role.setDescription(secRole.getDescription());
    role.setReadOnly(secRole.isReadOnly());
    role.setPrivileges(new HashSet<String>(secRole.getPrivileges()));
    role.setRoles(new HashSet<String>(secRole.getRoles()));

    return role;
  }
View Full Code Here

  }

  public Set<Role> listRoles() {
    Set<Role> roles = new HashSet<Role>();

    roles.add(new Role("mockrole1", "MockRole1", "Mock Role1", "Mock", true, null, null));
    roles.add(new Role("mockrole2", "MockRole2", "Mock Role2", "Mock", true, null, null));
    roles.add(new Role("mockrole3", "MockRole3", "Mock Role3", "Mock", true, null, null));

    return roles;
  }
View Full Code Here

        "randomId",
        "permissionOne",
        "permissionOne",
        ApplicationPrivilegeDescriptor.TYPE,
        properties, false));
    securitySystem.getAuthorizationManager("default").addRole(new Role("mockrole1", "mockrole1", "mockrole1",
        "default", false, null,
        Collections.singleton("randomId")));

    // add MockRealm to config
    List<String> realms = new ArrayList<String>();
View Full Code Here

  {
    SecuritySystem securitySystem = this.lookup(SecuritySystem.class);
    AuthorizationManager authManager = securitySystem.getAuthorizationManager("default");

    // create an empty role
    Role emptyRole = this.buildEmptyRole();

    // this should work fine
    authManager.addRole(emptyRole);

    // now create a user and add it to the user
    DefaultUser user = this.buildTestUser();
    user.setRoles(Collections.singleton(new RoleIdentifier(emptyRole.getSource(), emptyRole.getRoleId())));

    // create the user, this user only has an empty role
    securitySystem.addUser(user);

    Set<RoleIdentifier> emptyRoleSet = Collections.emptySet();
    user.setRoles(emptyRoleSet);
    securitySystem.updateUser(user);

    // delete the empty role
    authManager.deleteRole(emptyRole.getRoleId());
  }
View Full Code Here

      throws Exception
  {
    SecuritySystem securitySystem = this.lookup(SecuritySystem.class);
    AuthorizationManager authManager = securitySystem.getAuthorizationManager("default");

    Role emptyRole = this.buildEmptyRole();

    // this should work fine
    authManager.addRole(emptyRole);

    // make sure the role is still there
    Assert.assertNotNull(authManager.getRole(emptyRole.getRoleId()));
  }
View Full Code Here

    SecuritySystem securitySystem = this.lookup(SecuritySystem.class);
    securitySystem.setRealms(Arrays.asList(XmlAuthenticatingRealm.ROLE, XmlAuthorizingRealm.ROLE));
    AuthorizationManager authManager = securitySystem.getAuthorizationManager("default");

    // create an empty role
    Role emptyRole = this.buildEmptyRole();

    // this should work fine
    authManager.addRole(emptyRole);

    Role normalRole =
        new Role("normalRole-" + Math.random(), "NormalRole", "Normal Role", "default", false,
            new HashSet<String>(), new HashSet<String>());
    normalRole.addPrivilege(this.createTestPriv());
    authManager.addRole(normalRole);

    // now create a user and add it to the user
    DefaultUser user = this.buildTestUser();
    user.addRole(new RoleIdentifier(emptyRole.getSource(), emptyRole.getRoleId()));
    user.addRole(new RoleIdentifier(normalRole.getSource(), normalRole.getRoleId()));

    // create the user, this user only has an empty role
    securitySystem.addUser(user, "password");

    // now authorize the user
View Full Code Here

  {
    SecuritySystem securitySystem = this.lookup(SecuritySystem.class);
    AuthorizationManager authManager = securitySystem.getAuthorizationManager("default");

    // create an empty role
    Role emptyRole = this.buildEmptyRole();

    // this should work fine
    authManager.addRole(emptyRole);

    // now create a user and add it to the user
    DefaultUser user = this.buildTestUser();
    user.setRoles(Collections.singleton(new RoleIdentifier(emptyRole.getSource(), emptyRole.getRoleId())));

    // create the user, this user only has an empty role
    securitySystem.addUser(user);

    Set<User> userSearchResult =
        securitySystem.searchUsers(new UserSearchCriteria(null, Collections.singleton(emptyRole.getRoleId()),
            null));
    // this should contain a single result
    Assert.assertEquals(1, userSearchResult.size());
    Assert.assertEquals(user.getUserId(), userSearchResult.iterator().next().getUserId());
View Full Code Here

TOP

Related Classes of org.sonatype.security.authorization.Role

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.