@Override
 protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
     throws OperationFailedException {
   String spAlias =
       PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS))
           .getLastElement()
           .getValue();
   context.removeService(ServiceProviderService.createServiceName(spAlias));
 }
Example #2
0
  static void launchServices(
      final OperationContext context,
      final PathAddress pathAddress,
      final ModelNode model,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    Handler newHandler = new Handler();

    ModelNode classNameNode = HandlerResourceDefinition.CLASS.resolveModelAttribute(context, model);
    ModelNode codeNode = HandlerResourceDefinition.CODE.resolveModelAttribute(context, model);
    String typeName;

    if (classNameNode.isDefined()) {
      typeName = classNameNode.asString();
    } else if (codeNode.isDefined()) {
      typeName = HandlerTypeEnum.forType(codeNode.asString());
    } else {
      throw PicketLinkLogger.ROOT_LOGGER.federationHandlerTypeNotProvided();
    }

    newHandler.setClazz(typeName);

    ModelNode handler = Resource.Tools.readModel(context.readResourceFromRoot(pathAddress));

    if (handler.hasDefined(COMMON_HANDLER_PARAMETER.getName())) {
      for (Property handlerParameter :
          handler.get(COMMON_HANDLER_PARAMETER.getName()).asPropertyList()) {
        String paramName = handlerParameter.getName();
        String paramValue =
            HandlerParameterResourceDefinition.VALUE
                .resolveModelAttribute(context, handlerParameter.getValue())
                .asString();

        KeyValueType kv = new KeyValueType();

        kv.setKey(paramName);
        kv.setValue(paramValue);

        newHandler.add(kv);
      }
    }

    SAMLHandlerService service = new SAMLHandlerService(newHandler);
    PathElement providerAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement();

    ServiceTarget serviceTarget = context.getServiceTarget();
    ServiceBuilder<SAMLHandlerService> serviceBuilder =
        serviceTarget.addService(
            createServiceName(providerAlias.getValue(), newHandler.getClazz()), service);
    ServiceName serviceName;

    if (providerAlias.getKey().equals(IDENTITY_PROVIDER.getName())) {
      serviceName = IdentityProviderService.createServiceName(providerAlias.getValue());
    } else {
      serviceName = ServiceProviderService.createServiceName(providerAlias.getValue());
    }

    serviceBuilder.addDependency(
        serviceName, EntityProviderService.class, service.getEntityProviderService());

    if (verificationHandler != null) {
      serviceBuilder.addListener(verificationHandler);
    }

    ServiceController<SAMLHandlerService> controller =
        serviceBuilder.setInitialMode(ServiceController.Mode.PASSIVE).install();

    if (newControllers != null) {
      newControllers.add(controller);
    }

    if (!context.isBooting()) {
      // a reload is required to get the chain properly updated with the domain model state.
      context.reloadRequired();
    }
  }