void launchServices(
      final OperationContext context,
      final PathAddress pathAddress,
      final ModelNode model,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    Handler newHandler = new Handler();

    newHandler.setClazz(
        HandlerResourceDefinition.CLASS.resolveModelAttribute(context, model).asString());

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

    if (handler.hasDefined(COMMON_HANDLER_PARAMETER.getName())) {
      for (ModelNode handlerParameter : handler.get(COMMON_HANDLER_PARAMETER.getName()).asList()) {
        Property property = handlerParameter.asProperty();
        String paramName = property.getName();
        String paramValue =
            HandlerParameterResourceDefinition.VALUE
                .resolveModelAttribute(context, property.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());

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

    if (newControllers != null) {
      newControllers.add(controller);
    }
  }
Exemplo n.º 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();
    }
  }
Exemplo n.º 3
0
  /**
   * Parses the {@code ClaimsProcessors} section of the STS configuration file.
   *
   * @param xmlEventReader the reader used to parse the XML configuration file.
   * @return a {@code ClaimsProcessorsType} instance that contains the parsed data.
   * @throws ParsingException if an error occurs while parsing the XML file.
   */
  private ClaimsProcessorsType parseClaimsProcessors(XMLEventReader xmlEventReader)
      throws ParsingException {
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, CLAIMS_PROCESSORS_ELEMENT);

    ClaimsProcessorsType claimsProcessors = new ClaimsProcessorsType();

    // parse all claims processors one by one.
    while (xmlEventReader.hasNext()) {
      XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
      if (xmlEvent == null) break;
      if (xmlEvent instanceof EndElement) {
        EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader);
        String endElementName = StaxParserUtil.getEndElementName(endElement);
        if (endElementName.equals(CLAIMS_PROCESSORS_ELEMENT)) break;
        else throw logger.parserUnknownEndElement(endElementName);
      }

      StartElement subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
      if (subEvent == null) break;
      String elementName = StaxParserUtil.getStartElementName(subEvent);

      if (CLAIMS_PROCESSOR_ELEMENT.equalsIgnoreCase(elementName)) {
        subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
        StaxParserUtil.validate(subEvent, CLAIMS_PROCESSOR_ELEMENT);
        ClaimsProcessorType claimsProcessor = new ClaimsProcessorType();

        // parse the processor attributes (class and dialect).
        QName attributeQName = new QName("", PROCESSOR_CLASS_ATTRIB);
        Attribute attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null)
          claimsProcessor.setProcessorClass(StaxParserUtil.getAttributeValue(attribute));
        attributeQName = new QName("", DIALECT_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null)
          claimsProcessor.setDialect(StaxParserUtil.getAttributeValue(attribute));

        // parse the processor properties.
        while (xmlEventReader.hasNext()) {
          xmlEvent = StaxParserUtil.peek(xmlEventReader);
          if (xmlEvent == null) break;
          if (xmlEvent instanceof EndElement) {
            EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader);
            String endElementName = StaxParserUtil.getEndElementName(endElement);
            if (endElementName.equals(CLAIMS_PROCESSOR_ELEMENT)) break;
            else throw logger.parserUnknownEndElement(endElementName);
          }

          subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
          if (subEvent == null) break;
          elementName = StaxParserUtil.getStartElementName(subEvent);
          if (PROPERTY_ELEMENT.equalsIgnoreCase(elementName)) {
            // parse the property key and value.
            subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
            KeyValueType keyValue = new KeyValueType();
            // parse the key and value attributes.
            attributeQName = new QName("", KEY_ATTRIB);
            attribute = subEvent.getAttributeByName(attributeQName);
            if (attribute != null) keyValue.setKey(StaxParserUtil.getAttributeValue(attribute));
            attributeQName = new QName("", VALUE_ATTRIB);
            attribute = subEvent.getAttributeByName(attributeQName);
            if (attribute != null) keyValue.setValue(StaxParserUtil.getAttributeValue(attribute));

            EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
            StaxParserUtil.validate(endElement, PROPERTY_ELEMENT);
            claimsProcessor.add(keyValue);
          } else throw logger.parserUnknownTag(elementName, subEvent.getLocation());
        }
        claimsProcessors.add(claimsProcessor);
      } else throw logger.parserUnknownTag(elementName, subEvent.getLocation());
    }
    return claimsProcessors;
  }
Exemplo n.º 4
0
  /**
   * Parses the {@code TokenProviders} section of the STS configuration file.
   *
   * @param xmlEventReader the reader used to parse the XML configuration file.
   * @return a {@code TokenProvidersType} instance that contains the parsed data.
   * @throws ParsingException if an error occurs while parsing the XML file.
   */
  private TokenProvidersType parseTokenProviders(XMLEventReader xmlEventReader)
      throws ParsingException {
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, TOKEN_PROVIDERS_ELEMENT);

    TokenProvidersType tokenProviders = new TokenProvidersType();

    // parse all token providers one by one.
    while (xmlEventReader.hasNext()) {
      XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
      if (xmlEvent == null) break;
      if (xmlEvent instanceof EndElement) {
        EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader);
        String endElementName = StaxParserUtil.getEndElementName(endElement);
        if (endElementName.equals(TOKEN_PROVIDERS_ELEMENT)) break;
        else throw logger.parserUnknownEndElement(endElementName);
      }

      StartElement subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
      if (subEvent == null) break;
      String elementName = StaxParserUtil.getStartElementName(subEvent);

      if (TOKEN_PROVIDER_ELEMENT.equalsIgnoreCase(elementName)) {
        subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
        StaxParserUtil.validate(subEvent, TOKEN_PROVIDER_ELEMENT);
        TokenProviderType tokenProvider = new TokenProviderType();

        // parse the provider attributes (provider class, token type, token element, token
        // namespace).
        QName attributeQName = new QName("", PROVIDER_CLASS_ATTRIB);
        Attribute attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null)
          tokenProvider.setProviderClass(StaxParserUtil.getAttributeValue(attribute));
        attributeQName = new QName("", TOKEN_TYPE_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null)
          tokenProvider.setTokenType(StaxParserUtil.getAttributeValue(attribute));
        attributeQName = new QName("", TOKEN_ELEMENT_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null)
          tokenProvider.setTokenElement(StaxParserUtil.getAttributeValue(attribute));
        attributeQName = new QName("", TOKEN_ELEMENT_NS_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null)
          tokenProvider.setTokenElementNS(StaxParserUtil.getAttributeValue(attribute));

        // parse the provider properties.
        while (xmlEventReader.hasNext()) {
          xmlEvent = StaxParserUtil.peek(xmlEventReader);
          if (xmlEvent == null) break;
          if (xmlEvent instanceof EndElement) {
            EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader);
            String endElementName = StaxParserUtil.getEndElementName(endElement);
            if (endElementName.equals(TOKEN_PROVIDER_ELEMENT)) break;
            else throw logger.parserUnknownEndElement(endElementName);
          }

          subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
          if (subEvent == null) break;
          elementName = StaxParserUtil.getStartElementName(subEvent);
          if (PROPERTY_ELEMENT.equalsIgnoreCase(elementName)) {
            // parse the property key and value.
            subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
            KeyValueType keyValue = new KeyValueType();
            // parse the key and value attributes.
            attributeQName = new QName("", KEY_ATTRIB);
            attribute = subEvent.getAttributeByName(attributeQName);
            if (attribute != null) keyValue.setKey(StaxParserUtil.getAttributeValue(attribute));
            attributeQName = new QName("", VALUE_ATTRIB);
            attribute = subEvent.getAttributeByName(attributeQName);
            if (attribute != null) keyValue.setValue(StaxParserUtil.getAttributeValue(attribute));

            EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
            StaxParserUtil.validate(endElement, PROPERTY_ELEMENT);
            tokenProvider.add(keyValue);
          } else throw logger.parserUnknownTag(elementName, subEvent.getLocation());
        }
        tokenProviders.add(tokenProvider);
      } else throw logger.parserUnknownTag(elementName, subEvent.getLocation());
    }
    return tokenProviders;
  }
Exemplo n.º 5
0
  /**
   * Parses the {@code KeyProvider} section of the STS configuration file. This section is used to
   * setup the keystore \ that will be used to sign and encrypt security tokens.
   *
   * @param xmlEventReader the reader used to parse the XML configuration file.
   * @return a {@code KeyProviderType} instance that contains the parsed data.
   * @throws ParsingException if an error occurs while parsing the XML file.
   */
  private KeyProviderType parseKeyProvider(XMLEventReader xmlEventReader) throws ParsingException {
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, KEY_PROVIDER_ELEMENT);

    KeyProviderType keyProvider = new KeyProviderType();
    // get the key provider class name attribute.
    QName attributeQName = new QName("", CLASS_NAME_ATTRIB);
    Attribute attribute = startElement.getAttributeByName(attributeQName);
    if (attribute == null) throw logger.parserRequiredAttribute("ClassName");
    keyProvider.setClassName(StaxParserUtil.getAttributeValue(attribute));

    // parse the inner elements.
    while (xmlEventReader.hasNext()) {
      XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
      if (xmlEvent == null) break;
      if (xmlEvent instanceof EndElement) {
        EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader);
        String endElementName = StaxParserUtil.getEndElementName(endElement);
        if (endElementName.equals(KEY_PROVIDER_ELEMENT)) break;
        else throw logger.parserUnknownEndElement(endElementName);
      }

      StartElement subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
      if (subEvent == null) break;
      String elementName = StaxParserUtil.getStartElementName(subEvent);

      if (SIGNING_ALIAS_ELEMENT.equalsIgnoreCase(elementName)) {
        subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
        if (!StaxParserUtil.hasTextAhead(xmlEventReader))
          throw logger.parserExpectedTextValue("SigningAlias");
        keyProvider.setSigningAlias(StaxParserUtil.getElementText(xmlEventReader));
      } else if (VALIDATING_ALIAS_ELEMENT.equalsIgnoreCase(elementName)) {
        subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
        KeyValueType keyValue = new KeyValueType();
        // parse the key and value attributes.
        attributeQName = new QName("", KEY_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null) keyValue.setKey(StaxParserUtil.getAttributeValue(attribute));
        attributeQName = new QName("", VALUE_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null) keyValue.setValue(StaxParserUtil.getAttributeValue(attribute));

        EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
        StaxParserUtil.validate(endElement, VALIDATING_ALIAS_ELEMENT);
        keyProvider.add(keyValue);
      } else if (AUTH_ELEMENT.equalsIgnoreCase(elementName)) {
        subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
        AuthPropertyType authProperty = new AuthPropertyType();
        // parse the key and value attributes.
        attributeQName = new QName("", KEY_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null) authProperty.setKey(StaxParserUtil.getAttributeValue(attribute));
        attributeQName = new QName("", VALUE_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null) authProperty.setValue(StaxParserUtil.getAttributeValue(attribute));

        EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
        StaxParserUtil.validate(endElement, AUTH_ELEMENT);
        keyProvider.add(authProperty);
      } else throw logger.parserUnknownTag(elementName, subEvent.getLocation());
    }
    return keyProvider;
  }