use of org.apache.activemq.artemis.api.core.management.AddressControl in project wildfly by wildfly.
the class AddressControlHandler method handleGetRolesAsJson.
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());
}
}
use of org.apache.activemq.artemis.api.core.management.AddressControl in project wildfly by wildfly.
the class ActiveMQServerResource method getCoreAddressNames.
private Set<String> getCoreAddressNames() {
final ManagementService managementService = getManagementService();
if (managementService == null) {
return Collections.emptySet();
} else {
Set<String> result = new HashSet<String>();
for (Object obj : managementService.getResources(AddressControl.class)) {
AddressControl ac = AddressControl.class.cast(obj);
result.add(ac.getAddress());
}
return result;
}
}
use of org.apache.activemq.artemis.api.core.management.AddressControl in project wildfly by wildfly.
the class SecurityRoleReadAttributeHandler method executeRuntimeStep.
@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());
}
}
use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.
the class JMSMessageTypesTest method testAddressControlSendMessage.
@Test(timeout = 60000)
public void testAddressControlSendMessage() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
server.createQueue(address, RoutingType.ANYCAST, address, null, true, false);
AddressControl addressControl = ManagementControlHelper.createAddressControl(address, mBeanServer);
Assert.assertEquals(1, addressControl.getQueueNames().length);
addressControl.sendMessage(null, org.apache.activemq.artemis.api.core.Message.BYTES_TYPE, Base64.encodeBytes("test".getBytes()), false, fullUser, fullPass);
Wait.assertEquals(1, addressControl::getMessageCount);
Connection connection = createConnection("myClientId");
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(address.toString());
MessageConsumer consumer = session.createConsumer(queue);
Message message = consumer.receive(5000);
assertNotNull(message);
byte[] buffer = new byte[(int) ((BytesMessage) message).getBodyLength()];
((BytesMessage) message).readBytes(buffer);
assertEquals("test", new String(buffer));
session.close();
connection.close();
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method getAddressNames.
@Override
public String[] getAddressNames() {
checkStarted();
clearIO();
try {
Object[] addresses = server.getManagementService().getResources(AddressControl.class);
String[] names = new String[addresses.length];
for (int i = 0; i < addresses.length; i++) {
AddressControl address = (AddressControl) addresses[i];
names[i] = address.getAddress();
}
return names;
} finally {
blockOnIO();
}
}
Aggregations