Exemplo n.º 1
0
 public final String modelToXmlString() {
   TiersInformationsType object = (TiersInformationsType) this.modelToXml();
   XmlOptions opts = new XmlOptions();
   opts.setSavePrettyPrint();
   opts.setSavePrettyPrintIndent(4);
   opts.setUseDefaultNamespace();
   opts.setCharacterEncoding("UTF-8");
   return object.xmlText(opts);
 }
 @Override
 public final String modelToXmlString() {
   TechnicalInterventionRequestDocument object = this.modelToXml();
   XmlOptions opts = new XmlOptions();
   opts.setSavePrettyPrint();
   opts.setSavePrettyPrintIndent(4);
   opts.setUseDefaultNamespace();
   opts.setCharacterEncoding("UTF-8");
   return object.xmlText(opts);
 }
Exemplo n.º 3
0
  private void createConfigFile(
      String issuer,
      String nameQualifier,
      String ksType,
      String ksFile,
      String ksPassword,
      String privKeyAlias,
      String privKeyPassword,
      String certAlias)
      throws IOException {

    String SSO_CONFIG_FILE = "/WEB-INF/guanxi_idp/config/idp.xml";
    String KEYSTORE_KEY_TYPE = "dsa";

    IdpDocument idpDoc = null;
    try {
      idpDoc = IdpDocument.Factory.parse(new File(servletContext.getRealPath(SSO_CONFIG_FILE)));
    } catch (XmlException xe) {
      logger.error("Can't create config file", xe);
      return;
    }

    IdpDocument.Idp idp = idpDoc.getIdp();

    idp.getServiceProviderArray(0).setIdentity("exampleIdentity");
    idp.getServiceProviderArray(0).setCreds("exampleCreds");
    idp.getServiceProviderArray(0).setName("REPLACE_WITH_PROVIDER_ID_OF_SERVICE_PROVIDER");

    idp.getIdentityArray(0).setName("exampleIdentity");
    idp.getIdentityArray(0).setNameQualifier(nameQualifier);
    idp.getIdentityArray(0).setIssuer(issuer);

    idp.getCredsArray(0).setName("exampleCreds");
    idp.getCredsArray(0).setKeystoreType("jks");
    idp.getCredsArray(0).setKeyType(ksType);
    idp.getCredsArray(0).setKeystoreFile(ksFile);
    idp.getCredsArray(0).setKeystorePassword(ksPassword);
    idp.getCredsArray(0).setPrivateKeyAlias(privKeyAlias);
    idp.getCredsArray(0).setPrivateKeyPassword(privKeyPassword);
    idp.getCredsArray(0).setCertificateAlias(certAlias);
    idp.getCredsArray(0).setKeyType(KEYSTORE_KEY_TYPE);

    XmlOptions xmlOptions = new XmlOptions();
    xmlOptions.setSavePrettyPrint();
    xmlOptions.setSavePrettyPrintIndent(2);
    xmlOptions.setUseDefaultNamespace();

    idpDoc.save(new File(servletContext.getRealPath(SSO_CONFIG_FILE)), xmlOptions);

    servletContext.setAttribute(Guanxi.CONTEXT_ATTR_IDP_CONFIG_DOC, idpDoc);
    servletContext.setAttribute(Guanxi.CONTEXT_ATTR_IDP_CONFIG, idpDoc.getIdp());
  }
Exemplo n.º 4
0
 public void saveConfiguration() {
   File file = getDefaultConfigurationFile();
   log.info("Storing current configuration in file: " + file.getAbsolutePath());
   try {
     XmlOptions opts = new XmlOptions();
     opts.setSavePrettyPrint();
     opts.setSavePrettyPrintIndent(4);
     configuration.save(file, opts);
   } catch (IOException e) {
     log.error("Unable to save the updated configuration in file: " + file.getAbsolutePath());
     throw new RuntimeException("Unable to save the updated configuration: " + e.getMessage());
   }
 }
Exemplo n.º 5
0
  /**
   * Dumps an XML document to disk.
   *
   * @param doc The document to dump to disk
   * @param filePath The full path and name of the file
   */
  public static void dumpXML(XmlObject doc, String filePath) {
    HashMap<String, String> namespaces = new HashMap<String, String>();
    namespaces.put("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
    namespaces.put("http://www.nsdl.org/ontologies/relationships#", "myns");
    XmlOptions xmlOptions = new XmlOptions();
    xmlOptions.setSavePrettyPrint();
    xmlOptions.setSavePrettyPrintIndent(2);
    // xmlOptions.setUseDefaultNamespace();
    // xmlOptions.setSaveAggressiveNamespaces();
    xmlOptions.setSaveSuggestedPrefixes(namespaces);
    // xmlOptions.setSaveNamespacesFirst();

    try {
      doc.save(new File(filePath), xmlOptions);
    } catch (Exception e) {
    }
  }