/**
   * Returns a <code>RemoveListenerRequest</code> object constructed from a XML.
   *
   * @param pNode the XML DOM node for the <code>RemoveListenerRequest</code> object.
   * @return constructed <code>RemoveListenerRequest</code> object.
   */
  public static RemoveListenerRequest parseXML(Node pNode) throws PolicyEvaluationException {
    RemoveListenerRequest removeListenerReq = new RemoveListenerRequest();
    String attr = XMLUtils.getNodeAttributeValue(pNode, SERVICE_NAME);

    if (attr == null) {
      debug.error("RemoveListenerRequest: missing attribute " + SERVICE_NAME);
      String objs[] = {SERVICE_NAME};
      throw new PolicyEvaluationException(ResBundleUtils.rbName, "missing_attribute", objs, null);
    }

    removeListenerReq.setServiceName(attr);

    attr = XMLUtils.getNodeAttributeValue(pNode, NOTIFICATION_URL);
    if (attr == null) {
      debug.error("RemoveListenerRequest: missing attribute " + NOTIFICATION_URL);
      String objs[] = {NOTIFICATION_URL};
      throw new PolicyEvaluationException(ResBundleUtils.rbName, "missing_attribute", objs, null);
    }

    removeListenerReq.setNotificationURL(attr);
    return removeListenerReq;
  }
예제 #2
0
  protected static void checkAndEncryptPasswordSyntax(
      Document doc, boolean encrypt, AMEncryption encryptObj) throws SMSException {
    // Get the node list of all AttributeSchema
    NodeList nl = doc.getElementsByTagName(SMSUtils.SCHEMA_ATTRIBUTE);
    for (int i = 0; i < nl.getLength(); i++) {
      Node node = nl.item(i);
      // Check if the "syntax" attribute is "password"
      String syntax = XMLUtils.getNodeAttributeValue(node, SMSUtils.ATTRIBUTE_SYNTAX);
      if (syntax.equals(AttributeSchema.Syntax.PASSWORD.toString())) {
        if (debug.messageEnabled()) {
          debug.message("ServiceManager: encrypting password syntax");
        }
        // Get the DefaultValues and encrypt then
        Node defaultNode;
        if ((defaultNode = XMLUtils.getChildNode(node, SMSUtils.ATTRIBUTE_DEFAULT_ELEMENT))
            != null) {
          // Get NodeList of "Value" nodes and encrypt them
          for (Iterator items =
                  XMLUtils.getChildNodes(defaultNode, SMSUtils.ATTRIBUTE_VALUE).iterator();
              items.hasNext(); ) {
            Node valueNode = (Node) items.next();
            String value = XMLUtils.getValueOfValueNode(valueNode);
            String encValue;

            if (encrypt) {
              if (encryptObj != null) {
                value = (String) AccessController.doPrivileged(new DecodeAction(value, encryptObj));
                if (value.equals("&amp;#160;")) {
                  try {
                    byte[] b = new byte[1];
                    b[0] = -96;
                    value = new String(b, "ISO-8859-1");
                  } catch (UnsupportedEncodingException e) {
                    // ignore
                  }
                }
              }
              encValue = (String) AccessController.doPrivileged(new EncodeAction(value));
            } else {
              encValue = (String) AccessController.doPrivileged(new DecodeAction(value));

              try {
                // this is catch the whitespace for password
                byte[] b = encValue.getBytes("ISO-8859-1");
                if ((b.length == 1) && (b[0] == -96)) {
                  encValue = "&amp;#160;";
                }
              } catch (UnsupportedEncodingException e) {
                // ignore
              }
              if (encryptObj != null) {
                encValue =
                    (String) AccessController.doPrivileged(new EncodeAction(encValue, encryptObj));
              }
            }

            // Construct the encrypted "Value" node
            StringBuffer sb = new StringBuffer(100);
            sb.append(AttributeSchema.VALUE_BEGIN)
                .append(encValue)
                .append(AttributeSchema.VALUE_END);
            Document newDoc = SMSSchema.getXMLDocument(sb.toString(), false);
            Node newValueNode = XMLUtils.getRootNode(newDoc, SMSUtils.ATTRIBUTE_VALUE);
            // Replace the node
            Node nValueNode = doc.importNode(newValueNode, true);
            defaultNode.replaceChild(nValueNode, valueNode);
          }
        }
      }
    }
  }
예제 #3
0
  /**
   * Registers one or more services, defined by the XML input stream that follows the SMS DTD.
   *
   * @param xmlServiceSchema the input stream of service metadata in XML conforming to SMS DTD.
   * @param decryptObj Object to decrypt the password in the XML.
   * @return set of registered service names.
   * @throws SMSException if an error occurred while performing the operation
   * @throws SSOException if the user's single sign on token is invalid or expired.
   */
  public Set registerServices(InputStream xmlServiceSchema, AMEncryption decryptObj)
      throws SMSException, SSOException {
    // Validate SSO Token
    SMSEntry.validateToken(token);
    Set sNames = new HashSet();
    List serviceNodes = new ArrayList();
    // Get the XML document and get the list of service nodes
    Document doc = SMSSchema.getXMLDocument(xmlServiceSchema);

    if (!validSMSDtdDocType(doc)) {
      throw new SMSException(
          IUMSConstants.UMS_BUNDLE_NAME, IUMSConstants.SMS_xml_invalid_doc_type, null);
    }

    // Before validating service schema, we need to check
    // for AttributeSchema having the syntax of "password"
    // and if present, encrypt the DefaultValues if any
    checkAndEncryptPasswordSyntax(doc, true, decryptObj);

    // Create service schema
    NodeList nodes = doc.getElementsByTagName(SMSUtils.SERVICE);
    for (int i = 0; (nodes != null) && (i < nodes.getLength()); i++) {
      Node serviceNode = nodes.item(i);
      String name = XMLUtils.getNodeAttributeValue(serviceNode, SMSUtils.NAME);
      String version = XMLUtils.getNodeAttributeValue(serviceNode, SMSUtils.VERSION);

      // Obtain the SMSSchema for Schema and PluginSchema
      SMSSchema smsSchema = new SMSSchema(name, version, doc);

      // Check if the schema element exists
      if (XMLUtils.getChildNode(serviceNode, SMSUtils.SCHEMA) != null) {
        validateServiceSchema(serviceNode);
        ServiceSchemaManager.createService(token, smsSchema);

        // Update the service name and version cached SMSEntry
        if (serviceNames == null) {
          serviceNames = CachedSubEntries.getInstance(token, serviceDN);
        }
        serviceNames.add(name);
        CachedSubEntries sVersions = (CachedSubEntries) serviceVersions.get(name);
        if (sVersions == null) {
          // Not present, hence create it and add it
          sVersions = CachedSubEntries.getInstance(token, getServiceNameDN(name));
          serviceVersions.put(name, sVersions);
        }
        sVersions.add(version);
        sNames.add(name);
      }

      // Check if PluginSchema nodes exists
      for (Iterator pluginNodes =
              XMLUtils.getChildNodes(serviceNode, SMSUtils.PLUGIN_SCHEMA).iterator();
          pluginNodes.hasNext(); ) {
        Node pluginNode = (Node) pluginNodes.next();
        PluginSchema.createPluginSchema(token, pluginNode, smsSchema);
      }

      if (XMLUtils.getChildNode(serviceNode, SMSUtils.CONFIGURATION) != null) {
        serviceNodes.add(serviceNode);
      }
    }

    if (serviceNodes.size() > 0) {
      clearCache();
    }
    /*
     * Need to do this after all the schema has been loaded
     */
    for (Iterator i = serviceNodes.iterator(); i.hasNext(); ) {
      Node svcNode = (Node) i.next();
      String name = XMLUtils.getNodeAttributeValue(svcNode, SMSUtils.NAME);
      String version = XMLUtils.getNodeAttributeValue(svcNode, SMSUtils.VERSION);
      Node configNode = XMLUtils.getChildNode(svcNode, SMSUtils.CONFIGURATION);
      /*
       * Store the configuration, will throw exception if
       * the service configuration already exists
       */
      CreateServiceConfig.createService(this, name, version, configNode, true, decryptObj);
    }
    return sNames;
  }
예제 #4
0
  /**
   * Returns a <code>PolicyRequest</code> object constructed from a XML.
   *
   * @param pNode the XML DOM node for the <code>PolicyRequest</code> object.
   * @return constructed <code>PolicyRequest</code> object
   */
  public static PolicyRequest parseXML(Node pNode) throws PolicyEvaluationException {
    PolicyRequest preq = new PolicyRequest();

    String attr = XMLUtils.getNodeAttributeValue(pNode, APP_SSOTOKEN);
    if (attr == null) {
      debug.error("PolicyRequestparseXML(Node): missing attribute " + APP_SSOTOKEN);
      String objs[] = {APP_SSOTOKEN};
      throw new PolicyEvaluationException(ResBundleUtils.rbName, "missing_attribute", objs, null);
    }
    preq.setAppSSOToken(attr);
    attr = XMLUtils.getNodeAttributeValue(pNode, REQUEST_ID);

    if (attr == null) {
      debug.error("PolicyRequest.parseXML(Node): missing attribute " + REQUEST_ID);
      String objs[] = {REQUEST_ID};
      throw new PolicyEvaluationException(ResBundleUtils.rbName, "missing_attribute", objs, null);
    }
    preq.setRequestId(attr);

    Node node = XMLUtils.getChildNode(pNode, GET_RESOURCE_RESULTS);
    if (node != null) {
      ResourceResultRequest resourceResultReq = null;
      try {
        resourceResultReq = ResourceResultRequest.parseXML(node);
      } catch (PolicyEvaluationException pe) {
        throw new PolicyEvaluationException(pe, preq.getRequestId());
      }
      preq.setResourceResultRequest(resourceResultReq);
      preq.setMethodID(POLICY_REQUEST_GET_RESOURCE_RESULTS);
      return preq;
    }

    node = XMLUtils.getChildNode(pNode, ADD_POLICY_LISTENER);
    if (node != null) {
      PolicyListenerRequest plr = null;
      try {
        plr = PolicyListenerRequest.parseXML(node);
      } catch (PolicyEvaluationException pe) {
        throw new PolicyEvaluationException(pe, preq.getRequestId());
      }
      preq.setPolicyListenerRequest(plr);
      preq.setMethodID(POLICY_REQUEST_ADD_POLICY_LISTENER);
      return preq;
    }

    node = XMLUtils.getChildNode(pNode, REMOVE_POLICY_LISTENER);
    if (node != null) {
      RemoveListenerRequest rmListenerReq = null;
      try {
        rmListenerReq = RemoveListenerRequest.parseXML(node);
      } catch (PolicyEvaluationException pe) {
        throw new PolicyEvaluationException(pe, preq.getRequestId());
      }
      preq.setRemoveListenerRequest(rmListenerReq);
      preq.setMethodID(POLICY_REQUEST_REMOVE_POLICY_LISTENER);
      return preq;
    }

    node = XMLUtils.getChildNode(pNode, ADVICES_HANDLEABLE_BY_AM_REQUEST);
    if (node != null) {
      preq.setAdvicesHandleableByAMRequest(new AdvicesHandleableByAMRequest());
      preq.setMethodID(POLICY_REQUEST_ADVICES_HANDLEABLE_BY_AM_REQUEST);
      return preq;
    }

    /*
     * We reach here, there is no valid method name specified in
     * the xml docuemnt. Throw exception.
     */
    debug.error("PolicyRequest: invalid method specified");
    throw new PolicyEvaluationException(
        ResBundleUtils.rbName, "invalid_policy_request_method", null, null);
  }