Search in sources :

Example 1 with SAMLService

use of org.wildfly.extension.picketlink.federation.service.SAMLService in project wildfly by wildfly.

the class SAMLAddHandler method launchServices.

static void launchServices(OperationContext context, ModelNode operation, ModelNode model, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) throws OperationFailedException {
    PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS));
    String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
    SAMLService service = new SAMLService(toSAMLConfig(context, model));
    ServiceBuilder<SAMLService> serviceBuilder = context.getServiceTarget().addService(SAMLService.createServiceName(federationAlias), service);
    serviceBuilder.addDependency(FederationService.createServiceName(federationAlias), FederationService.class, service.getFederationService());
    if (verificationHandler != null) {
        serviceBuilder.addListener(verificationHandler);
    }
    ServiceController<SAMLService> controller = serviceBuilder.setInitialMode(ServiceController.Mode.PASSIVE).install();
    if (newControllers != null) {
        newControllers.add(controller);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) SAMLService(org.wildfly.extension.picketlink.federation.service.SAMLService)

Example 2 with SAMLService

use of org.wildfly.extension.picketlink.federation.service.SAMLService in project wildfly by wildfly.

the class SAMLResourceDefinition method createAttributeWriterHandler.

@Override
protected OperationStepHandler createAttributeWriterHandler() {
    List<SimpleAttributeDefinition> attributes = getAttributes();
    return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {

        @Override
        protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, false);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, true);
        }

        private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
            String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
            ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
            ServiceController<SAMLService> serviceController = (ServiceController<SAMLService>) serviceRegistry.getService(SAMLService.createServiceName(federationAlias));
            if (serviceController != null) {
                SAMLService service = serviceController.getValue();
                ModelNode samlNode;
                if (!rollback) {
                    samlNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
                } else {
                    Resource rc = context.getOriginalRootResource().navigate(pathAddress);
                    samlNode = rc.getModel();
                }
                service.setStsType(SAMLAddHandler.toSAMLConfig(context, samlNode));
            }
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) SAMLService(org.wildfly.extension.picketlink.federation.service.SAMLService)

Aggregations

PathAddress (org.jboss.as.controller.PathAddress)2 SAMLService (org.wildfly.extension.picketlink.federation.service.SAMLService)2 AbstractWriteAttributeHandler (org.jboss.as.controller.AbstractWriteAttributeHandler)1 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)1 OperationContext (org.jboss.as.controller.OperationContext)1 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)1 Resource (org.jboss.as.controller.registry.Resource)1 ModelNode (org.jboss.dmr.ModelNode)1 ServiceController (org.jboss.msc.service.ServiceController)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1