private void handleGetRolesAsJson(final OperationContext context, final ModelNode operation) { final AddressControl addressControl = getAddressControl(context, operation); try { String json = addressControl.getRolesAsJSON(); reportRolesAsJSON(context, json); } catch (RuntimeException e) { throw e; } catch (Exception e) { context.getFailureDescription().set(e.getLocalizedMessage()); } }
private void handleGetRolesAsJson(final OperationContext context, final ModelNode operation) { final AddressControl addressControl = getAddressControl(context, operation); try { String json = addressControl.getRolesAsJSON(); reportRolesAsJSON(context, json); } catch (RuntimeException e) { throw e; } catch (Exception e) { context.getFailureDescription().set(e.getLocalizedMessage()); } }
private Set<String> getSecurityRoles() { AddressControl addressControl = getAddressControl(); if (addressControl == null) { return Collections.emptySet(); } else { Set<String> names = new HashSet<String>(); try { ModelNode res = ModelNode.fromJSONString(addressControl.getRolesAsJSON()); ModelNode converted = ManagementUtil.convertSecurityRole(res); for (ModelNode role : converted.asList()) { names.add(role.get(NAME).asString()); } return names; } catch (Exception e) { return Collections.emptySet(); } } }
private Set<String> getSecurityRoles() { AddressControl addressControl = getAddressControl(); if (addressControl == null) { return Collections.emptySet(); } else { Set<String> names = new HashSet<String>(); try { ModelNode res = ModelNode.fromJSONString(addressControl.getRolesAsJSON()); ModelNode converted = ManagementUtil.convertSecurityRole(res); for (ModelNode role : converted.asList()) { names.add(role.get(NAME).asString()); } return names; } catch (Exception e) { return Collections.emptySet(); } } }
String json = addressControl.getRolesAsJSON(); reportRoles(context, json); } else if (QUEUE_NAMES.equals(name)) {
String json = addressControl.getRolesAsJSON(); reportRoles(context, json); } else if (QUEUE_NAMES.equals(name)) {
@Override public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString(); PathAddress pathAddress = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); String addressName = pathAddress.getElement(pathAddress.size() - 2).getValue(); String roleName = pathAddress.getLastElement().getValue(); final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR))); ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName); ActiveMQServer server = ActiveMQServer.class.cast(service.getValue()); AddressControl control = AddressControl.class.cast(server.getManagementService().getResource(ResourceNames.ADDRESS + addressName)); if (control == null) { PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address); } try { String rolesAsJSON = control.getRolesAsJSON(); ModelNode res = ModelNode.fromJSONString(rolesAsJSON); ModelNode roles = ManagementUtil.convertSecurityRole(res); ModelNode matchedRole = findRole(roleName, roles); if (matchedRole == null || !matchedRole.hasDefined(attributeName)) { throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName); } boolean value = matchedRole.get(attributeName).asBoolean(); context.getResult().set(value); } catch (Exception e) { context.getFailureDescription().set(e.getLocalizedMessage()); } }
@Override public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString(); PathAddress pathAddress = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); String addressName = pathAddress.getElement(pathAddress.size() - 2).getValue(); String roleName = pathAddress.getLastElement().getValue(); final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR))); ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName); ActiveMQServer server = ActiveMQServer.class.cast(service.getValue()); AddressControl control = AddressControl.class.cast(server.getManagementService().getResource(ResourceNames.ADDRESS + addressName)); if (control == null) { PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address); } try { String rolesAsJSON = control.getRolesAsJSON(); ModelNode res = ModelNode.fromJSONString(rolesAsJSON); ModelNode roles = ManagementUtil.convertSecurityRole(res); ModelNode matchedRole = findRole(roleName, roles); if (matchedRole == null || !matchedRole.hasDefined(attributeName)) { throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName); } boolean value = matchedRole.get(attributeName).asBoolean(); context.getResult().set(value); } catch (Exception e) { context.getFailureDescription().set(e.getLocalizedMessage()); } }
@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(), 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<>(); 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); }