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


Java XMLUtils.protectAgainstWrappingAttack方法代码示例

本文整理汇总了Java中com.sun.org.apache.xml.internal.security.utils.XMLUtils.protectAgainstWrappingAttack方法的典型用法代码示例。如果您正苦于以下问题:Java XMLUtils.protectAgainstWrappingAttack方法的具体用法?Java XMLUtils.protectAgainstWrappingAttack怎么用?Java XMLUtils.protectAgainstWrappingAttack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.org.apache.xml.internal.security.utils.XMLUtils的用法示例。


在下文中一共展示了XMLUtils.protectAgainstWrappingAttack方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dereference

import com.sun.org.apache.xml.internal.security.utils.XMLUtils; //导入方法依赖的package包/类
public Data dereference(URIReference uriRef, XMLCryptoContext context)
    throws URIReferenceException {

    if (uriRef == null) {
        throw new NullPointerException("uriRef cannot be null");
    }
    if (context == null) {
        throw new NullPointerException("context cannot be null");
    }

    DOMURIReference domRef = (DOMURIReference) uriRef;
    Attr uriAttr = (Attr) domRef.getHere();
    String uri = uriRef.getURI();
    DOMCryptoContext dcc = (DOMCryptoContext) context;
    String baseURI = context.getBaseURI();

    boolean secVal = Utils.secureValidation(context);

    // Check if same-document URI and already registered on the context
    if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') {
        String id = uri.substring(1);

        if (id.startsWith("xpointer(id(")) {
            int i1 = id.indexOf('\'');
            int i2 = id.indexOf('\'', i1+1);
            id = id.substring(i1+1, i2);
        }

        Node referencedElem = dcc.getElementById(id);
        if (referencedElem != null) {
            if (secVal) {
                Element start = referencedElem.getOwnerDocument().getDocumentElement();
                if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) {
                    String error = "Multiple Elements with the same ID " + id + " were detected";
                    throw new URIReferenceException(error);
                }
            }

            XMLSignatureInput result = new XMLSignatureInput(referencedElem);
            if (!uri.substring(1).startsWith("xpointer(id(")) {
                result.setExcludeComments(true);
            }

            result.setMIMEType("text/xml");
            if (baseURI != null && baseURI.length() > 0) {
                result.setSourceURI(baseURI.concat(uriAttr.getNodeValue()));
            } else {
                result.setSourceURI(uriAttr.getNodeValue());
            }
            return new ApacheNodeSetData(result);
        }
    }

    try {
        ResourceResolver apacheResolver =
            ResourceResolver.getInstance(uriAttr, baseURI, secVal);
        XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI);
        if (in.isOctetStream()) {
            return new ApacheOctetStreamData(in);
        } else {
            return new ApacheNodeSetData(in);
        }
    } catch (Exception e) {
        throw new URIReferenceException(e);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:67,代码来源:DOMURIDereferencer.java

示例2: dereference

import com.sun.org.apache.xml.internal.security.utils.XMLUtils; //导入方法依赖的package包/类
public Data dereference(URIReference uriRef, XMLCryptoContext context)
    throws URIReferenceException {

    if (uriRef == null) {
        throw new NullPointerException("uriRef cannot be null");
    }
    if (context == null) {
        throw new NullPointerException("context cannot be null");
    }

    DOMURIReference domRef = (DOMURIReference) uriRef;
    Attr uriAttr = (Attr) domRef.getHere();
    String uri = uriRef.getURI();
    DOMCryptoContext dcc = (DOMCryptoContext) context;
    String baseURI = context.getBaseURI();

    boolean secVal = Utils.secureValidation(context);

    if (secVal && Policy.restrictReferenceUriScheme(uri)) {
        throw new URIReferenceException(
            "Uri " + uri + " is forbidden when secure validation is enabled");
    }

    // Check if same-document URI and already registered on the context
    if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') {
        String id = uri.substring(1);

        if (id.startsWith("xpointer(id(")) {
            int i1 = id.indexOf('\'');
            int i2 = id.indexOf('\'', i1+1);
            id = id.substring(i1+1, i2);
        }

        // check if element is registered by Id
        Node referencedElem = uriAttr.getOwnerDocument().getElementById(id);
        if (referencedElem == null) {
           // see if element is registered in DOMCryptoContext
           referencedElem = dcc.getElementById(id);
        }
        if (referencedElem != null) {
            if (secVal && Policy.restrictDuplicateIds()) {
                Element start = referencedElem.getOwnerDocument().getDocumentElement();
                if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) {
                    String error = "Multiple Elements with the same ID "
                        + id + " detected when secure validation"
                        + " is enabled";
                    throw new URIReferenceException(error);
                }
            }

            XMLSignatureInput result = new XMLSignatureInput(referencedElem);
            if (!uri.substring(1).startsWith("xpointer(id(")) {
                result.setExcludeComments(true);
            }

            result.setMIMEType("text/xml");
            if (baseURI != null && baseURI.length() > 0) {
                result.setSourceURI(baseURI.concat(uriAttr.getNodeValue()));
            } else {
                result.setSourceURI(uriAttr.getNodeValue());
            }
            return new ApacheNodeSetData(result);
        }
    }

    try {
        ResourceResolver apacheResolver =
            ResourceResolver.getInstance(uriAttr, baseURI, false);
        XMLSignatureInput in = apacheResolver.resolve(uriAttr,
                                                      baseURI, false);
        if (in.isOctetStream()) {
            return new ApacheOctetStreamData(in);
        } else {
            return new ApacheNodeSetData(in);
        }
    } catch (Exception e) {
        throw new URIReferenceException(e);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:80,代码来源:DOMURIDereferencer.java


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