Example usage for org.w3c.dom Element getAttributeNS

List of usage examples for org.w3c.dom Element getAttributeNS

Introduction

In this page you can find the example usage for org.w3c.dom Element getAttributeNS.

Prototype

public String getAttributeNS(String namespaceURI, String localName) throws DOMException;

Source Link

Document

Retrieves an attribute value by local name and namespace URI.

Usage

From source file:fi.okm.mpass.shibboleth.profile.metadata.spring.DataSourceMetadataProviderParser.java

/** {@inheritDoc} */
@Override//from  w  ww.ja v  a2 s.  c  om
protected void doNativeParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    super.doNativeParse(element, parserContext, builder);

    if (element.hasAttributeNS(null, "dataSource")) {
        builder.addConstructorArgReference(
                StringSupport.trimOrNull(element.getAttributeNS(null, "dataSource")));
    } else {
        log.error("{}: dataSource configuration not found",
                parserContext.getReaderContext().getResource().getDescription());
        throw new BeanDefinitionParsingException(new Problem("dataSource configuration not found",
                new Location(parserContext.getReaderContext().getResource())));
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.service.AbstractReloadableServiceBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element configElement, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(configElement, parserContext, builder);

    if (configElement.hasAttributeNS(null, "configurationResourcePollingFrequency")) {
        builder.addPropertyReference("pollingTimer", configElement.getAttributeNS(null, "timerId"));

        long frequency = SpringConfigurationUtils.parseDurationToMillis(
                "'configurationResourcePollingFrequency' on service "
                        + configElement.getAttributeNS(null, "id"),
                configElement.getAttributeNS(null, "configurationResourcePollingFrequency"), 1);
        builder.addPropertyValue("pollingFrequency", frequency);
        log.debug("{} service configuration polling frequency: {}ms", getServiceId(configElement), frequency);

        int retryAttempts = 0;
        if (configElement.hasAttributeNS(null, "configurationResourcePollingRetryAttempts")) {
            retryAttempts = Integer.parseInt(DatatypeHelper.safeTrimOrNullString(
                    configElement.getAttributeNS(null, "configurationResourcePollingRetryAttempts")));
        }/*from  www. j ava 2s  .  c  o m*/
        if (retryAttempts < 1) {
            retryAttempts = 3;
        }
        builder.addPropertyValue("pollingRetryAttempts", retryAttempts);
        log.debug("{} service configuration polling retry attempts: {}", getServiceId(configElement),
                retryAttempts);
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractCredentialBeanDefinitionParser.java

/**
 * Parses the private key from the credential configuration.
 * /*from   w w w  .ja v a 2s .co  m*/
 * @param configChildren children of the credential element
 * @param builder credential build
 */
protected void parsePrivateKey(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) {
    List<Element> keyElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "PrivateKey"));
    if (keyElems == null || keyElems.isEmpty()) {
        return;
    }

    log.debug("Parsing credential private key");
    Element privKeyElem = keyElems.get(0);
    byte[] encodedKey = getEncodedPrivateKey(DatatypeHelper.safeTrimOrNullString(privKeyElem.getTextContent()));
    String keyPassword = DatatypeHelper.safeTrimOrNullString(privKeyElem.getAttributeNS(null, "password"));
    char[] keyPasswordCharArray = null;
    if (keyPassword != null) {
        keyPasswordCharArray = keyPassword.toCharArray();
    }
    try {
        PrivateKey privKey = SecurityHelper.decodePrivateKey(encodedKey, keyPasswordCharArray);
        builder.addPropertyValue("privateKey", privKey);
    } catch (KeyException e) {
        throw new FatalBeanException("Unable to create credential, unable to parse private key", e);
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.metadata.AbstractReloadingMetadataProviderBeanDefinitionParser.java

/**
 * Gets the default task timer reference for the metadata provider.
 * /*from w w  w.  j av a 2  s  . com*/
 * @param config metadata provider configuration element
 * 
 * @return task timer reference
 */
protected String getTaskTimerRef(Element config) {
    String taskTimerRef = null;
    if (config.hasAttributeNS(null, "taskTimerRef")) {
        taskTimerRef = DatatypeHelper.safeTrimOrNullString(config.getAttributeNS(null, "taskTimerRef"));
    }

    if (taskTimerRef == null) {
        taskTimerRef = "shibboleth.TaskTimer";
    }

    return taskTimerRef;
}

From source file:com.duosecurity.shibboleth.idp.twofactor.TwoFactorLoginHandlerBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element config, BeanDefinitionBuilder builder) {
    super.doParse(config, builder);

    if (config.hasAttributeNS(null, "authenticationServletURL")) {
        builder.addPropertyValue("authenticationServletURL",
                DatatypeHelper.safeTrim(config.getAttributeNS(null, "authenticationServletURL")));
    } else {/*from   w ww.j  a  v  a2s  . c  o  m*/
        builder.addPropertyValue("authenticationServletURL", "/Authn/DuoUserPassword");
    }

    String jaasConfigurationURL = DatatypeHelper
            .safeTrim(config.getAttributeNS(null, "jaasConfigurationLocation"));
    log.debug("Setting JAAS configuration file to: {}", jaasConfigurationURL);
    System.setProperty("java.security.auth.login.config", jaasConfigurationURL);

    String skey = DatatypeHelper.safeTrim(config.getAttributeNS(null, "skey"));
    log.debug("Setting Duo skey to: {}", skey);
    builder.addPropertyValue("skey", skey);

    String ikey = DatatypeHelper.safeTrim(config.getAttributeNS(null, "ikey"));
    log.debug("Setting Duo ikey to: {}", ikey);
    builder.addPropertyValue("ikey", ikey);

    String akey = DatatypeHelper.safeTrim(config.getAttributeNS(null, "akey"));
    log.debug("Setting Duo akey to: {}", akey);
    builder.addPropertyValue("akey", akey);

    String host = DatatypeHelper.safeTrim(config.getAttributeNS(null, "host"));
    log.debug("Setting Duo host to: {}", host);
    builder.addPropertyValue("host", host);
}

From source file:edu.washington.shibboleth.attribute.resolver.spring.dc.rws.RwsDataConnectorParser.java

/**
 * Parse attribute requirements//from  w  ww .j a v a  2 s.  c  o  m
 *
 * @param elements DOM elements of type <code>Attribute</code>
 *
 * @return the attributes
 */
protected List<RwsAttribute> parseAttributes(List<Element> elements) {
    if (elements == null || elements.size() == 0) {
        return null;
    }
    List<RwsAttribute> rwsAttributes = new Vector<RwsAttribute>();
    for (Element ele : elements) {
        RwsAttribute rwsAttribute = new RwsAttribute();
        rwsAttribute.name = StringSupport.trimOrNull(ele.getAttributeNS(null, "name"));
        log.debug("parseattribute: " + rwsAttribute.name);
        System.out.println("parseattribute: " + rwsAttribute.name);
        rwsAttribute.xPath = StringSupport.trimOrNull(ele.getAttributeNS(null, "xPath"));
        rwsAttribute.maxResultSize = 1;
        if (ele.hasAttributeNS(null, "maxResultSize")) {
            rwsAttribute.maxResultSize = Integer.parseInt(ele.getAttributeNS(null, "maxResultSize"));
        }
        boolean noResultsIsError = false;
        if (ele.hasAttributeNS(null, "noResultIsError")) {
            rwsAttribute.noResultIsError = AttributeSupport
                    .getAttributeValueAsBoolean(ele.getAttributeNodeNS(null, "noResultIsError"));
        }
        rwsAttributes.add(rwsAttribute);
    }
    return rwsAttributes;
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.encoding.SAML1Base64AttributeEncoderBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(element, parserContext, builder);

    String namespace = "urn:mace:shibboleth:1.0:attributeNamespace:uri";
    if (element.hasAttributeNS(null, "namespace")) {
        namespace = DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null, "namespace"));
    }/*  ww w  . j a  v a  2 s .  c  om*/
    builder.addPropertyValue("namespace", namespace);

    String attributeName = DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null, "name"));
    if (attributeName == null) {
        throw new BeanCreationException("SAML 1 attribute encoders must contain a name");
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractBasicCredentialBeanDefinitionParser.java

/**
 * Parses the secret key from the credential configuration.
 * //from  w ww .j  a  va  2  s. c o m
 * @param configChildren children of the credential element
 * @param builder credential build
 */
protected void parseSecretKey(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) {
    List<Element> keyElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "SecretKey"));
    if (keyElems == null || keyElems.isEmpty()) {
        return;
    }

    log.debug("Parsing credential secret key");
    Element secretKeyElem = keyElems.get(0);
    byte[] encodedKey = getEncodedSecretKey(
            DatatypeHelper.safeTrimOrNullString(secretKeyElem.getTextContent()));
    String keyPassword = DatatypeHelper.safeTrimOrNullString(secretKeyElem.getAttributeNS(null, "password"));
    try {
        SecretKey key = SecurityHelper.decodeSecretKey(encodedKey, keyPassword.toCharArray());
        builder.addPropertyValue("secretKey", key);
    } catch (KeyException e) {
        throw new FatalBeanException("Unable to create credential, unable to parse secret key", e);
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.encoding.SAML1StringNameIdentifierEncoderBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(element, parserContext, builder);

    String namespace = "urn:oasis:names:tc:SAML:1.0:nameid-format:unspecified";
    if (element.hasAttributeNS(null, "nameFormat")) {
        namespace = DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null, "nameFormat"));
    }/*from   www  .j a  v a2 s . c  o  m*/
    builder.addPropertyValue("nameFormat", namespace);

    builder.addPropertyValue("nameQualifier", element.getAttributeNS(null, "nameQualifier"));
}

From source file:edu.internet2.middleware.shibboleth.common.config.metadata.AbstractReloadingMetadataProviderBeanDefinitionParser.java

/**
 * Gets the maximum refresh delay for the metadata provider.
 * //from   w ww.  j a va 2s  .  com
 * @param config provider configuration element
 * 
 * @return the maximum refresh delay, in milliseconds
 */
protected long getMaxRefreshDelay(Element config) {
    long maxRefreshDelay = 14400000L;

    if (config.hasAttributeNS(null, "cacheDuration")) {
        int cacheDuration = Integer.parseInt(config.getAttributeNS(null, "cacheDuration"));
        maxRefreshDelay = cacheDuration * 1000;
        log.warn("Metadata provider cacheDuration attribute is deprecated, use maxRefreshDelay=\"{}\" instead.",
                XMLHelper.getDataTypeFactory().newDuration(maxRefreshDelay).toString());
    }

    if (config.hasAttributeNS(null, "maxCacheDuration")) {
        int cacheDuration = Integer.parseInt(config.getAttributeNS(null, "maxCacheDuration"));
        Duration duration = XMLHelper.getDataTypeFactory().newDuration(cacheDuration * 1000);
        log.warn(
                "Metadata provider maxCacheDuration attribute is deprecated, use maxRefreshDelay=\"{}\" instead.",
                duration.toString());
    }

    if (config.hasAttributeNS(null, "maxRefreshDelay")) {
        String delayString = config.getAttributeNS(null, "maxRefreshDelay");
        try {
            maxRefreshDelay = SpringConfigurationUtils.parseDurationToMillis("maxRefreshDelay", delayString, 1);
        } catch (NumberFormatException e) {
            log.error("Metadata provider had invalid maxRefreshDelay value '{}', using default value",
                    delayString);
        }
    }

    if (maxRefreshDelay <= 0) {
        log.error("Metadata provider had invalid maxRefreshDelay value '{}', using default value",
                maxRefreshDelay);
        maxRefreshDelay = 14400000L;
    }

    return maxRefreshDelay;
}