当前位置: 首页>>代码示例>>Java>>正文


Java IgnoreAllErrorHandler类代码示例

本文整理汇总了Java中org.apache.xml.security.utils.IgnoreAllErrorHandler的典型用法代码示例。如果您正苦于以下问题:Java IgnoreAllErrorHandler类的具体用法?Java IgnoreAllErrorHandler怎么用?Java IgnoreAllErrorHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IgnoreAllErrorHandler类属于org.apache.xml.security.utils包,在下文中一共展示了IgnoreAllErrorHandler类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sign

import org.apache.xml.security.utils.IgnoreAllErrorHandler; //导入依赖的package包/类
/**
 * Canonizes and signs a given input with the authentication private key.
 * of the EBICS user.
 * 
 * <p>The given input to be signed is first Canonized using the 
 * http://www.w3.org/TR/2001/REC-xml-c14n-20010315 algorithm.
 * 
 * <p>The element to be canonized is only the SignedInfo element that should be
 * contained in the request to be signed. Otherwise, a {@link TransformationException}
 * is thrown.
 * 
 * <p> The namespace of the SignedInfo element should be named <b>ds</b> as specified in
 * the EBICS specification for common namespaces nomination.
 * 
 * <p> The signature is ensured using the user X002 private key. This step is done in
 * {@link EbicsUser#authenticate(byte[]) authenticate}.
 * 
 * @param toSign the input to sign
 * @return the signed input
 * @throws EbicsException signature fails.
 */
public byte[] sign(byte[] toSign) throws EbicsException {
  try {
    DocumentBuilderFactory 		factory;
    DocumentBuilder			builder;
    Document				document;
    Node 				node;
    Canonicalizer 			canonicalizer;

    factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(true);
    builder = factory.newDocumentBuilder();
    builder.setErrorHandler(new IgnoreAllErrorHandler());
    document = builder.parse(new ByteArrayInputStream(toSign));
    node = XPathAPI.selectSingleNode(document, "//ds:SignedInfo");
    canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
    return user.authenticate(canonicalizer.canonicalizeSubtree(node));
  } catch(Exception e) {
    throw new EbicsException(e.getMessage());
  }
}
 
开发者ID:pinaraf,项目名称:ebics,代码行数:43,代码来源:SignedInfo.java

示例2: sign

import org.apache.xml.security.utils.IgnoreAllErrorHandler; //导入依赖的package包/类
/**
 * Canonizes and signs a given input with the authentication private key.
 * of the EBICS user.
 * 
 * <p>The given input to be signed is first Canonized using the 
 * http://www.w3.org/TR/2001/REC-xml-c14n-20010315 algorithm.
 * 
 * <p>The element to be canonized is only the SignedInfo element that should be
 * contained in the request to be signed. Otherwise, a {@link TransformationException}
 * is thrown.
 * 
 * <p> The namespace of the SignedInfo element should be named <b>ds</b> as specified in
 * the EBICS specification for common namespaces nomination.
 * 
 * <p> The signature is ensured using the user X002 private key. This step is done in
 * {@link EbicsUser#authenticate(byte[]) authenticate}.
 * 
 * @param toSign the input to sign
 * @return the signed input
 * @throws EbicsException signature fails.
 */
public byte[] sign(byte[] toSign) throws AxelorException {
  try {
    DocumentBuilderFactory 		factory;
    DocumentBuilder			builder;
    Document				document;
    Node 				node;
    Canonicalizer 			canonicalizer;

    factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(true);
    builder = factory.newDocumentBuilder();
    builder.setErrorHandler(new IgnoreAllErrorHandler());
    document = builder.parse(new ByteArrayInputStream(toSign));
    node = XPathAPI.selectSingleNode(document, "//ds:SignedInfo");
    canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
    return Beans.get(EbicsUserService.class).authenticate(user, canonicalizer.canonicalizeSubtree(node));
  } catch(Exception e) {
    e.printStackTrace();
    throw new AxelorException(e, IException.CONFIGURATION_ERROR);
  }
}
 
开发者ID:axelor,项目名称:axelor-business-suite,代码行数:44,代码来源:SignedInfo.java

示例3: doTestXMLAttributes

import org.apache.xml.security.utils.IgnoreAllErrorHandler; //导入依赖的package包/类
/**
 * Method doTestXMLAttributes
 *
 * @param input
 * @param definedOutput
 * @param writeResultsToFile
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XPathExpressionException
 */
private boolean doTestXMLAttributes(String input, String definedOutput)
    throws IOException, FileNotFoundException, SAXException,
ParserConfigurationException, CanonicalizationException,
InvalidCanonicalizerException, TransformerException, XPathExpressionException {

    DocumentBuilder db = XMLUtils.createDocumentBuilder(true);

    db.setErrorHandler(new IgnoreAllErrorHandler());

    Document doc = db.parse(new ByteArrayInputStream(input.getBytes()));
    Canonicalizer c14nizer =
        Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);

    //XMLUtils.circumventBug2650(doc);

    XPathFactory xpf = XPathFactory.newInstance();
    XPath xPath = xpf.newXPath();
    xPath.setNamespaceContext(new DSNamespaceContext());

    String xpath =
        "(//*[local-name()='included'] | //@*[parent::node()[local-name()='included']])";
    NodeList nodes =
        (NodeList)xPath.evaluate(xpath, doc, XPathConstants.NODESET);

    byte result[] = c14nizer.canonicalizeXPathNodeSet(nodes);
    byte defined[] = definedOutput.getBytes();
    assertEquals(definedOutput, new String(result));
    return java.security.MessageDigest.isEqual(defined, result);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:46,代码来源:Canonicalizer20010315Test.java

示例4: canonize

import org.apache.xml.security.utils.IgnoreAllErrorHandler; //导入依赖的package包/类
/**
 * Canonizes an input with inclusive c14n without comments algorithm.
 * 
 * <p>EBICS Specification 2.4.2 - 5.5.1.1.1 EBICS messages in transaction initialization:
 * 
 * <p>The identification and authentication signature includes all XML elements of the
 * EBICS request whose attribute value for @authenticate is equal to “true”. The
 * definition of the XML schema “ebics_request.xsd“ guarantees that the value of the
 * attribute @authenticate is equal to “true” for precisely those elements that also
 * need to be signed.
 * 
 * <p>Thus, All the Elements with the attribute authenticate = true and their 
 * sub elements are considered for the canonization process. This is performed 
 * via the {@link XPathAPI#selectNodeIterator(Node, String) selectNodeIterator(Node, String)}.
 * 
 * @param input the byte array XML input.
 * @return the canonized form of the given XML
 * @throws EbicsException
 */
public static byte[] canonize(byte[] input) throws EbicsException {
  DocumentBuilderFactory 		factory;
  DocumentBuilder			builder;
  Document				document;
  NodeIterator			iter;
  ByteArrayOutputStream		output;
  Node 				node;

  try {
    factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(true);
    builder = factory.newDocumentBuilder();
    builder.setErrorHandler(new IgnoreAllErrorHandler());
    document = builder.parse(new ByteArrayInputStream(input));
    iter = XPathAPI.selectNodeIterator(document, "//*[@authenticate='true']");
    output = new ByteArrayOutputStream();
    while ((node = iter.nextNode()) != null) {
      Canonicalizer 		canonicalizer;

      canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
      output.write(canonicalizer.canonicalizeSubtree(node));
    }

    return output.toByteArray();
  } catch (Exception e) {
    throw new EbicsException(e.getMessage());
  }
}
 
开发者ID:pinaraf,项目名称:ebics,代码行数:49,代码来源:Utils.java

示例5: canonize

import org.apache.xml.security.utils.IgnoreAllErrorHandler; //导入依赖的package包/类
/**
 * Canonizes an input with inclusive c14n without comments algorithm.
 * 
 * <p>EBICS Specification 2.4.2 - 5.5.1.1.1 EBICS messages in transaction initialization:
 * 
 * <p>The identification and authentication signature includes all XML elements of the
 * EBICS request whose attribute value for @authenticate is equal to “true”. The
 * definition of the XML schema “ebics_request.xsd“ guarantees that the value of the
 * attribute @authenticate is equal to “true” for precisely those elements that also
 * need to be signed.
 * 
 * <p>Thus, All the Elements with the attribute authenticate = true and their 
 * sub elements are considered for the canonization process. This is performed 
 * via the {@link XPathAPI#selectNodeIterator(Node, String) selectNodeIterator(Node, String)}.
 * 
 * @param input the byte array XML input.
 * @return the canonized form of the given XML
 * @throws EbicsException
 */
public static byte[] canonize(byte[] input) throws AxelorException {
  DocumentBuilderFactory 		factory;
  DocumentBuilder			builder;
  Document				document;
  NodeIterator			iter;
  ByteArrayOutputStream		output;
  Node 				node;

  try {
    factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(true);
    builder = factory.newDocumentBuilder();
    builder.setErrorHandler(new IgnoreAllErrorHandler());
    document = builder.parse(new ByteArrayInputStream(input));
    iter = XPathAPI.selectNodeIterator(document, "//*[@authenticate='true']");
    output = new ByteArrayOutputStream();
    while ((node = iter.nextNode()) != null) {
      Canonicalizer 		canonicalizer;

      canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
      output.write(canonicalizer.canonicalizeSubtree(node));
    }

    return output.toByteArray();
  } catch (Exception e) {
    throw new AxelorException(e.getMessage(), IException.CONFIGURATION_ERROR );
  }
}
 
开发者ID:axelor,项目名称:axelor-business-suite,代码行数:49,代码来源:EbicsUtils.java

示例6: c14nAndCompare

import org.apache.xml.security.utils.IgnoreAllErrorHandler; //导入依赖的package包/类
private boolean c14nAndCompare(
    String fileIn,
    String fileRef,
    String fileOut,
    String c14nURI,
    boolean validating,
    String xpath,
    Map<String, String> namespaces
) throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException, XPathExpressionException {

    DocumentBuilder documentBuilder = XMLUtils.createDocumentBuilder(validating, false);

    // throw away all warnings and errors
    documentBuilder.setErrorHandler(new IgnoreAllErrorHandler());

    // org.xml.sax.EntityResolver resolver = new TestVectorResolver();
    // documentBuilder.setEntityResolver(resolver);
    // Document doc = documentBuilder.parse(resolver.resolveEntity(null, fileIn));

    Document doc = documentBuilder.parse(fileIn);


    Canonicalizer c14n = Canonicalizer.getInstance(c14nURI);
    byte c14nBytes[] = null;

    if (xpath == null) {
        c14nBytes = c14n.canonicalizeSubtree(doc);
    } else {
        NodeList nl = null;

        XPathFactory xpf = XPathFactory.newInstance();
        XPath xPath = xpf.newXPath();
        DSNamespaceContext namespaceContext =
            new DSNamespaceContext(namespaces);
        xPath.setNamespaceContext(namespaceContext);

        nl = (NodeList)xPath.evaluate(xpath, doc, XPathConstants.NODESET);

        c14nBytes = c14n.canonicalizeXPathNodeSet(nl);
    }

    // org.xml.sax.InputSource refIs = resolver.resolveEntity(null, fileRef);
    // byte refBytes[] = JavaUtils.getBytesFromStream(refIs.getByteStream());
    byte refBytes[] = JavaUtils.getBytesFromFile(fileRef);

    // if everything is OK, result is true; we do a binary compare, byte by byte
    boolean result = java.security.MessageDigest.isEqual(refBytes, c14nBytes);

    if (!result) {    	
        File f = new File(fileOut);
        if (!f.exists()) {
            File parent = new File(f.getParent());
            parent.mkdirs();
            f.createNewFile();
        }
        FileOutputStream fos = new FileOutputStream(f);

        fos.write(c14nBytes);
        log.debug("Wrote erroneous result to file " + f.toURI().toURL().toString());
        assertEquals(new String(refBytes),new String(c14nBytes));
        fos.close();
    }

    return result;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:68,代码来源:Canonicalizer20010315Test.java

示例7: c14nAndCompare

import org.apache.xml.security.utils.IgnoreAllErrorHandler; //导入依赖的package包/类
private boolean c14nAndCompare(
    String fileIn,
    String fileRef,
    String fileOut,
    String c14nURI,
    boolean validating,
    String xpath,
    Map<String, String> namespaces
) throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException, XPathExpressionException {

    DocumentBuilder documentBuilder = XMLUtils.createDocumentBuilder(validating, false);

    // throw away all warnings and errors
    documentBuilder.setErrorHandler(new IgnoreAllErrorHandler());

    // org.xml.sax.EntityResolver resolver = new TestVectorResolver();
    // documentBuilder.setEntityResolver(resolver);
    // Document doc = documentBuilder.parse(resolver.resolveEntity(null, fileIn));

    Document doc = documentBuilder.parse(fileIn);


    Canonicalizer c14n = Canonicalizer.getInstance(c14nURI);
    byte c14nBytes[] = null;

    if (xpath == null) {
        c14nBytes = c14n.canonicalizeSubtree(doc);
    } else {
        NodeList nl = null;

        XPathFactory xpf = XPathFactory.newInstance();
        XPath xPath = xpf.newXPath();
        DSNamespaceContext namespaceContext =
            new DSNamespaceContext(namespaces);
        xPath.setNamespaceContext(namespaceContext);

        nl = (NodeList)xPath.evaluate(xpath, doc, XPathConstants.NODESET);

        c14nBytes = c14n.canonicalizeXPathNodeSet(nl);
    }

    // org.xml.sax.InputSource refIs = resolver.resolveEntity(null, fileRef);
    // byte refBytes[] = JavaUtils.getBytesFromStream(refIs.getByteStream());
    byte refBytes[] = JavaUtils.getBytesFromFile(fileRef);

    // if everything is OK, result is true; we do a binary compare, byte by byte
    boolean result = java.security.MessageDigest.isEqual(refBytes, c14nBytes);

    if (!result) {    	
        File f = new File(fileOut);
        if (!f.exists()) {
            File parent = new File(f.getParent());
            parent.mkdirs();
            f.createNewFile();
        }
        FileOutputStream fos = new FileOutputStream(f);

        fos.write(c14nBytes);
        log.debug("Wrote erroneous result to file " + f.toURI().toURL().toString());
        assertEquals(new String(refBytes), new String(c14nBytes));
        fos.close();
    }

    return result;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:68,代码来源:Canonicalizer11Test.java


注:本文中的org.apache.xml.security.utils.IgnoreAllErrorHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。