Java Code Examples for org.w3c.dom.Element#getAttributeNS()

The following examples show how to use org.w3c.dom.Element#getAttributeNS() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecurityDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static boolean isUnprotectedByPermission(Element element) {
    // Used to check whether an activity, service or broadcast receiver are
    // protected by a permission.
    String permission = element.getAttributeNS(ANDROID_URI, ATTR_PERMISSION);
    if (permission == null || permission.isEmpty()) {
        Node parent = element.getParentNode();
        if (parent.getNodeType() == Node.ELEMENT_NODE
                && parent.getNodeName().equals(TAG_APPLICATION)) {
            Element application = (Element) parent;
            permission = application.getAttributeNS(ANDROID_URI, ATTR_PERMISSION);
            return permission == null || permission.isEmpty();
        }
    }

    return false;
}
 
Example 2
Source File: RequiredElementsBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {

    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    RequiredElements requiredElements = new RequiredElements(consts);
    String attrXPathVersion = element.getAttributeNS(consts.getNamespace(), SPConstants.XPATH_VERSION);

    if (attrXPathVersion != null) {
        requiredElements.setXPathVersion(attrXPathVersion);
    }


    Node nd = element.getFirstChild();
    while (nd != null) {
        if (nd instanceof Element) {
            processElement((Element)nd, requiredElements);                
        }
        nd = nd.getNextSibling();
    }
    return requiredElements;
}
 
Example 3
Source File: RequiredElementsBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {

    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    RequiredElements requiredElements = new RequiredElements(consts);
    String attrXPathVersion = element.getAttributeNS(consts.getNamespace(), SPConstants.XPATH_VERSION);

    if (attrXPathVersion != null) {
        requiredElements.setXPathVersion(attrXPathVersion);
    }


    Node nd = element.getFirstChild();
    while (nd != null) {
        if (nd instanceof Element) {
            processElement((Element)nd, requiredElements);                
        }
        nd = nd.getNextSibling();
    }
    return requiredElements;
}
 
Example 4
Source File: RequiredElementsBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {

    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    RequiredElements requiredElements = new RequiredElements(consts);
    String attrXPathVersion = element.getAttributeNS(consts.getNamespace(), SPConstants.XPATH_VERSION);

    if (attrXPathVersion != null) {
        requiredElements.setXPathVersion(attrXPathVersion);
    }


    Node nd = element.getFirstChild();
    while (nd != null) {
        if (nd instanceof Element) {
            processElement((Element)nd, requiredElements);                
        }
        nd = nd.getNextSibling();
    }
    return requiredElements;
}
 
Example 5
Source File: SignedElementsBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    SignedEncryptedElements signedEncryptedElements = new SignedEncryptedElements(true,
                                                                                  consts);

    String attribute = element.getAttributeNS(consts.getNamespace(), SPConstants.XPATH_VERSION);
    if (attribute != null) {
        signedEncryptedElements.setXPathVersion(attribute);
    }

    Node nd = element.getFirstChild();
    while (nd != null) {
        if (nd instanceof Element) {
            processElement((Element)nd, signedEncryptedElements);                
        }
        nd = nd.getNextSibling();
    }
    return signedEncryptedElements;
}
 
Example 6
Source File: DOMExcC14NMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void unmarshalParams(Element paramsElem) {
    String prefixListAttr = paramsElem.getAttributeNS(null, "PrefixList");
    this.inclusiveNamespaces = prefixListAttr;
    int begin = 0;
    int end = prefixListAttr.indexOf(' ');
    List<String> prefixList = new ArrayList<String>();
    while (end != -1) {
        prefixList.add(prefixListAttr.substring(begin, end));
        begin = end + 1;
        end = prefixListAttr.indexOf(' ', begin);
    }
    if (begin <= prefixListAttr.length()) {
        prefixList.add(prefixListAttr.substring(begin));
    }
    this.params = new ExcC14NParameterSpec(prefixList);
}
 
Example 7
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected String findIDFromSamlToken(Element samlToken) {
    String id = null;
    if (samlToken != null) {
        QName elName = DOMUtils.getElementQName(samlToken);
        if (elName.equals(new QName(WSConstants.SAML_NS, "Assertion"))
            && samlToken.hasAttributeNS(null, "AssertionID")) {
            id = samlToken.getAttributeNS(null, "AssertionID");
        } else if (elName.equals(new QName(WSConstants.SAML2_NS, "Assertion"))
            && samlToken.hasAttributeNS(null, "ID")) {
            id = samlToken.getAttributeNS(null, "ID");
        }
        if (id == null) {
            id = samlToken.getAttributeNS(WSConstants.WSU_NS, "Id");
        }
    }
    return id;
}
 
Example 8
Source File: AbstractBindingPolicyValidator.java    From steady with Apache License 2.0 6 votes vote down vote up
/**
 * Return true if the given id was encrypted
 */
private boolean isIdEncrypted(String sigId, List<WSSecurityEngineResult> results) {
    for (WSSecurityEngineResult wser : results) {
        Integer actInt = (Integer)wser.get(WSSecurityEngineResult.TAG_ACTION);
        if (actInt.intValue() == WSConstants.ENCR) {
            List<WSDataRef> el = 
                CastUtils.cast((List<?>)wser.get(WSSecurityEngineResult.TAG_DATA_REF_URIS));
            if (el != null) {
                for (WSDataRef r : el) {
                    Element protectedElement = r.getProtectedElement();
                    if (protectedElement != null) {
                        String id = protectedElement.getAttribute("Id");
                        String wsuId = protectedElement.getAttributeNS(WSConstants.WSU_NS, "Id");
                        if (sigId.equals(id) || sigId.equals(wsuId)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
 
Example 9
Source File: DOMExcC14NMethod.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void unmarshalParams(Element paramsElem) {
    String prefixListAttr = paramsElem.getAttributeNS(null, "PrefixList");
    this.inclusiveNamespaces = prefixListAttr;
    int begin = 0;
    int end = prefixListAttr.indexOf(' ');
    List<String> prefixList = new ArrayList<String>();
    while (end != -1) {
        prefixList.add(prefixListAttr.substring(begin, end));
        begin = end + 1;
        end = prefixListAttr.indexOf(' ', begin);
    }
    if (begin <= prefixListAttr.length()) {
        prefixList.add(prefixListAttr.substring(begin));
    }
    this.params = new ExcC14NParameterSpec(prefixList);
}
 
Example 10
Source File: BodyImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
String getPayloadAttributeValue(QName attNAme) {
    if (staxBridge != null) {
        return staxBridge.getPayloadAttributeValue(attNAme);
    } else {
        //not lazy -Just get first child element and return its attribute
        Element elem = getFirstChildElement();
        if (elem != null) {
            return elem.getAttributeNS(attNAme.getNamespaceURI(), attNAme.getLocalPart());
        }
    }
    return null;
}
 
Example 11
Source File: ManifestModel.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public String getKey(Element xmlElement) {
    String key = mNamespaceUri == null
        ? xmlElement.getAttribute(mAttributeName)
        : xmlElement.getAttributeNS(mNamespaceUri, mAttributeName);
    if (Strings.isNullOrEmpty(key)) return null;
    return key;
}
 
Example 12
Source File: GridLayoutDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private static int getInt(Element element, String attribute, int defaultValue) {
    String valueString = element.getAttributeNS(ANDROID_URI, attribute);
    if (valueString != null && !valueString.isEmpty()) {
        try {
            return Integer.decode(valueString);
        } catch (NumberFormatException nufe) {
            // Ignore - error in user's XML
        }
    }

    return defaultValue;
}
 
Example 13
Source File: DefaultSTSTokenCacher.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static String getIdFromToken(Element token) {
    if (token != null) {
        // For SAML tokens get the ID/AssertionID
        if ("Assertion".equals(token.getLocalName())
            && WSS4JConstants.SAML2_NS.equals(token.getNamespaceURI())) {
            return token.getAttributeNS(null, "ID");
        } else if ("Assertion".equals(token.getLocalName())
            && WSS4JConstants.SAML_NS.equals(token.getNamespaceURI())) {
            return token.getAttributeNS(null, "AssertionID");
        }

        // For UsernameTokens get the username
        if (WSS4JConstants.USERNAME_TOKEN_LN.equals(token.getLocalName())
            && WSS4JConstants.WSSE_NS.equals(token.getNamespaceURI())) {
            Element usernameElement =
                XMLUtils.getDirectChildElement(token, WSS4JConstants.USERNAME_LN, WSS4JConstants.WSSE_NS);
            if (usernameElement != null) {
                return XMLUtils.getElementText(usernameElement);
            }
        }

        // For BinarySecurityTokens take the hash of the value
        if (WSS4JConstants.BINARY_TOKEN_LN.equals(token.getLocalName())
            && WSS4JConstants.WSSE_NS.equals(token.getNamespaceURI())) {
            String text = XMLUtils.getElementText(token);
            if (text != null && !"".equals(text)) {
                try {
                    MessageDigest digest = MessageDigest.getInstance("SHA-256");
                    byte[] bytes = digest.digest(text.getBytes());
                    return org.apache.xml.security.utils.XMLUtils.encodeToString(bytes);
                } catch (NoSuchAlgorithmException e) {
                    // SHA-256 must be supported so not going to happen...
                }
            }
        }
    }
    return "";
}
 
Example 14
Source File: SignedInfo.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Signature method URI
 *
 * @return the Signature method URI
 */
public String getSignatureMethodURI() {
    Element signatureElement = this.getSignatureMethodElement();

    if (signatureElement != null) {
        return signatureElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
    }

    return null;
}
 
Example 15
Source File: SpnegoContextTokenInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
private SpnegoTokenContext handleBinaryExchange(
    Element binaryExchange,
    Message message,
    String namespace
) throws Exception {
    if (binaryExchange == null) {
        throw new Exception("No BinaryExchange element received");
    }
    String encoding = binaryExchange.getAttributeNS(null, "EncodingType");
    if (!BinarySecurity.BASE64_ENCODING.equals(encoding)) {
        throw new Exception("Unknown encoding type: " + encoding);
    }

    String valueType = binaryExchange.getAttributeNS(null, "ValueType");
    if (!(namespace + "/spnego").equals(valueType)) {
        throw new Exception("Unknown value type: " + valueType);
    }

    String content = DOMUtils.getContent(binaryExchange);
    byte[] decodedContent = Base64.decode(content);
    
    String jaasContext = 
        (String)message.getContextualProperty(SecurityConstants.KERBEROS_JAAS_CONTEXT_NAME);
    String kerberosSpn = 
        (String)message.getContextualProperty(SecurityConstants.KERBEROS_SPN);
    CallbackHandler callbackHandler = 
        NegotiationUtils.getCallbackHandler(
            message.getContextualProperty(SecurityConstants.CALLBACK_HANDLER), this.getClass()
        );

    SpnegoTokenContext spnegoToken = new SpnegoTokenContext();
    spnegoToken.validateServiceTicket(
        jaasContext, callbackHandler, kerberosSpn, decodedContent
    );
    return spnegoToken;
}
 
Example 16
Source File: SpnegoContextTokenInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private SpnegoTokenContext handleBinaryExchange(
    Element binaryExchange,
    Message message,
    String namespace
) throws Exception {
    if (binaryExchange == null) {
        throw new Exception("No BinaryExchange element received");
    }
    String encoding = binaryExchange.getAttributeNS(null, "EncodingType");
    if (!WSS4JConstants.BASE64_ENCODING.equals(encoding)) {
        throw new Exception("Unknown encoding type: " + encoding);
    }

    String valueType = binaryExchange.getAttributeNS(null, "ValueType");
    if (!(namespace + "/spnego").equals(valueType)) {
        throw new Exception("Unknown value type: " + valueType);
    }

    String content = DOMUtils.getContent(binaryExchange);
    byte[] decodedContent = XMLUtils.decode(content);

    String jaasContext =
        (String)message.getContextualProperty(SecurityConstants.KERBEROS_JAAS_CONTEXT_NAME);
    String kerberosSpn =
        (String)message.getContextualProperty(SecurityConstants.KERBEROS_SPN);
    CallbackHandler callbackHandler =
        SecurityUtils.getCallbackHandler(
            SecurityUtils.getSecurityPropertyValue(SecurityConstants.CALLBACK_HANDLER, message)
        );

    SpnegoTokenContext spnegoToken = new SpnegoTokenContext();
    spnegoToken.validateServiceTicket(
        jaasContext, callbackHandler, kerberosSpn, decodedContent
    );
    return spnegoToken;
}
 
Example 17
Source File: DOMUtil.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public static String getAttrValueNS(Element elem, String nsUri,
        String localName) {
    return elem.getAttributeNS(nsUri, localName);
}
 
Example 18
Source File: DOMCryptoContext.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Registers the element's attribute specified by the namespace URI and
 * local name to be of type ID. The attribute must have a non-empty value.
 *
 * <p>This implementation uses an internal {@link HashMap} to map the
 * attribute's value to the specified element.
 *
 * @param element the element
 * @param namespaceURI the namespace URI of the attribute (specify
 *    <code>null</code> if not applicable)
 * @param localName the local name of the attribute
 * @throws IllegalArgumentException if <code>localName</code> is not an
 *    attribute of the specified element or it does not contain a specific
 *    value
 * @throws NullPointerException if <code>element</code> or
 *    <code>localName</code> is <code>null</code>
 * @see #getElementById
 */
public void setIdAttributeNS(Element element, String namespaceURI,
    String localName) {
    if (element == null) {
        throw new NullPointerException("element is null");
    }
    if (localName == null) {
        throw new NullPointerException("localName is null");
    }
    String idValue = element.getAttributeNS(namespaceURI, localName);
    if (idValue == null || idValue.length() == 0) {
        throw new IllegalArgumentException(localName + " is not an " +
            "attribute");
    }
    idMap.put(idValue, element);
}
 
Example 19
Source File: KerberosTokenBuilder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory) {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    KerberosToken kerberosToken = new KerberosToken(consts);
    kerberosToken.setOptional(PolicyConstants.isOptional(element));
    kerberosToken.setIgnorable(PolicyConstants.isIgnorable(element));

    String attribute = element.getAttributeNS(element.getNamespaceURI(), SPConstants.ATTR_INCLUDE_TOKEN);
    if (attribute != null) {
        kerberosToken.setInclusion(consts.getInclusionFromAttributeValue(attribute.trim()));
    }
    
    Element child = DOMUtils.getFirstElement(element);
    boolean foundPolicy = false;
    while (child != null) {
        String ln = child.getLocalName();
        if (org.apache.neethi.Constants.ELEM_POLICY.equals(ln)) {
            foundPolicy = true;
            NodeList policyChildren = child.getChildNodes();
            if (policyChildren != null) {
                for (int i = 0; i < policyChildren.getLength(); i++) {
                    Node policyChild = policyChildren.item(i);
                    if (policyChild instanceof Element) {
                        QName qname = 
                            new QName(policyChild.getNamespaceURI(), policyChild.getLocalName());
                        String localpart = qname.getLocalPart();
                        if (SPConstants.KERBEROS_V5_AP_REQ_TOKEN_11.equals(localpart)) {
                            kerberosToken.setV5ApReqToken11(true);
                        } else if (SPConstants.KERBEROS_GSS_V5_AP_REQ_TOKEN_11.equals(localpart)) {
                            kerberosToken.setGssV5ApReqToken11(true);
                        } else if (SPConstants.REQUIRE_DERIVED_KEYS.equals(localpart)) {
                            kerberosToken.setDerivedKeys(true);
                        }
                    }
                }
            }
        }
        child = DOMUtils.getNextElement(child);
    }
    
    if (!foundPolicy && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:KerberosToken/wsp:Policy must have a value"
        );
    }
    return kerberosToken;
}
 
Example 20
Source File: ElementNameAndAttributeQualifier.java    From xmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Determine whether the qualifying attributes are present in both elements
 * and if so whether their values are the same
 * @param control
 * @param test
 * @return true if all qualifying attributes are present with the same
 * values, false otherwise
 * @deprecated this method is no longer used by this class and is
 *             only kept for backwards compatibility, overriding
 *             it won't have any effect anymore
 */
@Deprecated
protected final boolean areAttributesComparable(Element control, Element test) {
    String controlValue, testValue;
    Attr[] qualifyingAttributes;
    NamedNodeMap namedNodeMap = control.getAttributes();
    if (matchesAllAttributes(qualifyingAttrNames)) {
        qualifyingAttributes = new Attr[namedNodeMap.getLength()];
        for (int n=0; n < qualifyingAttributes.length; ++n) {
            qualifyingAttributes[n] = (Attr) namedNodeMap.item(n);
        }
    } else {
        qualifyingAttributes = new Attr[qualifyingAttrNames.length];
        for (int n=0; n < qualifyingAttrNames.length; ++n) {
            qualifyingAttributes[n] = (Attr) namedNodeMap.getNamedItem(qualifyingAttrNames[n]);
        } 
    }

    String nsURI, name;
    for (int i=0; i < qualifyingAttributes.length; ++i) {
        if (qualifyingAttributes[i] != null) {
            nsURI = qualifyingAttributes[i].getNamespaceURI(); 
            controlValue = qualifyingAttributes[i].getNodeValue();
            name = qualifyingAttributes[i].getName();
        } else {
            // cannot be "*" case
            nsURI = controlValue = "";
            name = qualifyingAttrNames[i];
        }
        if (nsURI == null || nsURI.length() == 0) {
            testValue = test.getAttribute(name);
        } else {
            testValue = test.getAttributeNS(nsURI, qualifyingAttributes[i].getLocalName());
        }
        if (controlValue == null) {
            if (testValue != null) {
                return false;
            }
        } else {
            if (!controlValue.equals(testValue)) {
                return false;
            }
        }
    }
    return true;
}