Example #1
0
  public Object[] getRoles() throws Exception {
    clearIO();
    try {
      Set<Role> roles = securityRepository.getMatch(address.toString());

      Object[] objRoles = new Object[roles.size()];

      int i = 0;
      for (Role role : roles) {
        objRoles[i++] =
            new Object[] {
              role.getName(),
              CheckType.SEND.hasRole(role),
              CheckType.CONSUME.hasRole(role),
              CheckType.CREATE_DURABLE_QUEUE.hasRole(role),
              CheckType.DELETE_DURABLE_QUEUE.hasRole(role),
              CheckType.CREATE_NON_DURABLE_QUEUE.hasRole(role),
              CheckType.DELETE_NON_DURABLE_QUEUE.hasRole(role),
              CheckType.MANAGE.hasRole(role)
            };
      }
      return objRoles;
    } finally {
      blockOnIO();
    }
  }
Example #2
0
  @Test
  public void testGetRoles() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    Role role =
        new Role(
            RandomUtil.randomString(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean());

    session.createQueue(address, queue, true);

    AddressControl addressControl = createManagementControl(address);
    Object[] roles = addressControl.getRoles();
    Assert.assertEquals(0, roles.length);

    Set<Role> newRoles = new HashSet<Role>();
    newRoles.add(role);
    server.getSecurityRepository().addMatch(address.toString(), newRoles);

    roles = addressControl.getRoles();
    Assert.assertEquals(1, roles.length);
    Object[] r = (Object[]) roles[0];
    Assert.assertEquals(role.getName(), r[0]);
    Assert.assertEquals(CheckType.SEND.hasRole(role), r[1]);
    Assert.assertEquals(CheckType.CONSUME.hasRole(role), r[2]);
    Assert.assertEquals(CheckType.CREATE_DURABLE_QUEUE.hasRole(role), r[3]);
    Assert.assertEquals(CheckType.DELETE_DURABLE_QUEUE.hasRole(role), r[4]);
    Assert.assertEquals(CheckType.CREATE_NON_DURABLE_QUEUE.hasRole(role), r[5]);
    Assert.assertEquals(CheckType.DELETE_NON_DURABLE_QUEUE.hasRole(role), r[6]);
    Assert.assertEquals(CheckType.MANAGE.hasRole(role), r[7]);

    session.deleteQueue(queue);
  }