Search in sources :

Example 6 with ActiveMQServer

use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.

the class JMSQueueRemove method performRuntime.

protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String name = address.getLastElement().getValue();
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    JMSServerControl control = JMSServerControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_SERVER));
    if (control != null) {
        try {
            control.destroyQueue(name, true);
        } catch (Exception e) {
            throw new OperationFailedException(e);
        }
    }
    context.removeService(JMSServices.getJmsQueueBaseServiceName(serviceName).append(name));
    for (String entry : CommonAttributes.DESTINATION_ENTRIES.unwrap(context, model)) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(entry);
        ServiceName binderServiceName = bindInfo.getBinderServiceName();
        context.removeService(binderServiceName);
    }
    for (String legacyEntry : CommonAttributes.LEGACY_ENTRIES.unwrap(context, model)) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(legacyEntry);
        ServiceName binderServiceName = bindInfo.getBinderServiceName();
        context.removeService(binderServiceName);
    }
}
Also used : JMSServerControl(org.apache.activemq.artemis.api.jms.management.JMSServerControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 7 with ActiveMQServer

use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.

the class SecurityRoleAdd method rollbackRuntime.

@Override
protected void rollbackRuntime(OperationContext context, ModelNode operation, Resource resource) {
    final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    final ActiveMQServer server = getServer(context, operation);
    final String match = address.getElement(address.size() - 2).getValue();
    final String roleName = address.getLastElement().getValue();
    SecurityRoleRemove.removeRole(server, match, roleName);
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PathAddress(org.jboss.as.controller.PathAddress)

Example 8 with ActiveMQServer

use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.

the class SecurityRoleAttributeHandler method revertUpdateToRuntime.

@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Set<Role> handback) throws OperationFailedException {
    if (handback != null) {
        final ActiveMQServer server = getActiveMQServer(context, operation);
        if (server != null) {
            final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
            final String match = address.getElement(address.size() - 2).getValue();
            server.getSecurityRepository().addMatch(match, handback);
        }
    }
}
Also used : ActiveMQActivationService.getActiveMQServer(org.wildfly.extension.messaging.activemq.ActiveMQActivationService.getActiveMQServer) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PathAddress(org.jboss.as.controller.PathAddress)

Example 9 with ActiveMQServer

use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.

the class SecurityRoleAttributeHandler method applyUpdateToRuntime.

@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode newValue, ModelNode currentValue, HandbackHolder<Set<Role>> handbackHolder) throws OperationFailedException {
    final ActiveMQServer server = getActiveMQServer(context, operation);
    if (server != null) {
        final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
        final String match = address.getElement(address.size() - 2).getValue();
        final String roleName = address.getLastElement().getValue();
        final Set<Role> newRoles = new HashSet<Role>();
        final Set<Role> roles = server.getSecurityRepository().getMatch(match);
        handbackHolder.setHandback(roles);
        for (final Role role : roles) {
            if (!roleName.equals(role.getName())) {
                newRoles.add(role);
            }
        }
        final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
        final ModelNode subModel = resource.getModel();
        final Role updatedRole = SecurityRoleDefinition.transform(context, roleName, subModel);
        newRoles.add(updatedRole);
        server.getSecurityRepository().addMatch(match, newRoles);
    }
    return false;
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQActivationService.getActiveMQServer(org.wildfly.extension.messaging.activemq.ActiveMQActivationService.getActiveMQServer) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet)

Example 10 with ActiveMQServer

use of org.apache.activemq.artemis.core.server.ActiveMQServer 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.CORE_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());
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)37 ServiceName (org.jboss.msc.service.ServiceName)20 PathAddress (org.jboss.as.controller.PathAddress)19 OperationFailedException (org.jboss.as.controller.OperationFailedException)12 ModelNode (org.jboss.dmr.ModelNode)9 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5 ActiveMQActivationService.getActiveMQServer (org.wildfly.extension.messaging.activemq.ActiveMQActivationService.getActiveMQServer)4 Role (org.apache.activemq.artemis.core.security.Role)3 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)3 HttpServerExchange (io.undertow.server.HttpServerExchange)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ConnectionFactoryControl (org.apache.activemq.artemis.api.jms.management.ConnectionFactoryControl)2 JMSServerControl (org.apache.activemq.artemis.api.jms.management.JMSServerControl)2 TopicControl (org.apache.activemq.artemis.api.jms.management.TopicControl)2 RemotingService (org.apache.activemq.artemis.core.remoting.server.RemotingService)2 OperationContext (org.jboss.as.controller.OperationContext)2 Resource (org.jboss.as.controller.registry.Resource)2 ContextNames (org.jboss.as.naming.deployment.ContextNames)2 StartException (org.jboss.msc.service.StartException)2 SocketChannel (io.netty.channel.socket.SocketChannel)1