Пример #1
0
  @Test
  public void testGetRolesAsJSON() 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);
    String jsonString = addressControl.getRolesAsJSON();
    Assert.assertNotNull(jsonString);
    RoleInfo[] roles = RoleInfo.from(jsonString);
    Assert.assertEquals(0, roles.length);

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

    jsonString = addressControl.getRolesAsJSON();
    Assert.assertNotNull(jsonString);
    roles = RoleInfo.from(jsonString);
    Assert.assertEquals(1, roles.length);
    RoleInfo r = roles[0];
    Assert.assertEquals(role.getName(), roles[0].getName());
    Assert.assertEquals(role.isSend(), r.isSend());
    Assert.assertEquals(role.isConsume(), r.isConsume());
    Assert.assertEquals(role.isCreateDurableQueue(), r.isCreateDurableQueue());
    Assert.assertEquals(role.isDeleteDurableQueue(), r.isDeleteDurableQueue());
    Assert.assertEquals(role.isCreateNonDurableQueue(), r.isCreateNonDurableQueue());
    Assert.assertEquals(role.isDeleteNonDurableQueue(), r.isDeleteNonDurableQueue());
    Assert.assertEquals(role.isManage(), r.isManage());

    session.deleteQueue(queue);
  }
Пример #2
0
 private void handleGetRolesAsJson(final OperationContext context, final ModelNode operation) {
   final AddressControl addressControl = getAddressControl(context, operation);
   try {
     String json = addressControl.getRolesAsJSON();
     reportRolesAsJSON(context, json);
     context.stepCompleted();
   } catch (RuntimeException e) {
     throw e;
   } catch (Exception e) {
     context.getFailureDescription().set(e.getLocalizedMessage());
   }
 }
Пример #3
0
  private void handleReadAttribute(OperationContext context, ModelNode operation) {

    if (ignoreOperationIfServerNotActive(context, operation)) {
      return;
    }

    final AddressControl addressControl = getAddressControl(context, operation);
    if (addressControl == null) {
      PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
      throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }

    final String name = operation.require(ModelDescriptionConstants.NAME).asString();

    try {
      if (ROLES_ATTR_NAME.equals(name)) {
        String json = addressControl.getRolesAsJSON();
        reportRoles(context, json);
      } else if (QUEUE_NAMES.equals(name)) {
        String[] queues = addressControl.getQueueNames();
        reportListOfStrings(context, queues);
      } else if (NUMBER_OF_BYTES_PER_PAGE.equals(name)) {
        long l = addressControl.getNumberOfBytesPerPage();
        context.getResult().set(l);
      } else if (NUMBER_OF_PAGES.equals(name)) {
        int i = addressControl.getNumberOfPages();
        context.getResult().set(i);
      } else if (BINDING_NAMES.equals(name)) {
        String[] bindings = addressControl.getBindingNames();
        reportListOfStrings(context, bindings);
      } else {
        // Bug
        throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(name);
      }
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      context.getFailureDescription().set(e.getLocalizedMessage());
    }

    context.stepCompleted();
  }