Example usage for javax.naming Context LANGUAGE

List of usage examples for javax.naming Context LANGUAGE

Introduction

In this page you can find the example usage for javax.naming Context LANGUAGE.

Prototype

String LANGUAGE

To view the source code for javax.naming Context LANGUAGE.

Click Source Link

Document

Constant that holds the name of the environment property for specifying the preferred language to use with the service.

Usage

From source file:org.apache.openaz.xacml.std.pip.engines.ldap.LDAPEngine.java

@Override
public void configure(String id, Properties properties) throws PIPException {
    /*//from   ww w .j a  v  a2 s.  c  om
     * Handle the standard properties
     */
    super.configure(id, properties);
    String propertyPrefix = id + ".";

    /*
     * Configure the LDAP environment: I think the only required property is the provider_url
     */
    if (!this.configureStringProperty(propertyPrefix, Context.PROVIDER_URL, properties, null)) {
        throw new PIPException("Invalid configuration for " + this.getClass().getName() + ": No "
                + propertyPrefix + Context.PROVIDER_URL);
    }
    this.configureStringProperty(propertyPrefix, Context.AUTHORITATIVE, properties, null);
    this.configureIntegerProperty(propertyPrefix, Context.BATCHSIZE, properties, null);
    this.configureStringProperty(propertyPrefix, Context.DNS_URL, properties, null);
    this.configureStringProperty(propertyPrefix, Context.INITIAL_CONTEXT_FACTORY, properties,
            DEFAULT_CONTEXT_FACTORY);
    this.configureStringProperty(propertyPrefix, Context.LANGUAGE, properties, null);
    this.configureStringProperty(propertyPrefix, Context.OBJECT_FACTORIES, properties, null);
    this.configureStringProperty(propertyPrefix, Context.REFERRAL, properties, null);
    this.configureStringProperty(propertyPrefix, Context.SECURITY_AUTHENTICATION, properties, null);
    this.configureStringProperty(propertyPrefix, Context.SECURITY_CREDENTIALS, properties, null);
    this.configureStringProperty(propertyPrefix, Context.SECURITY_PRINCIPAL, properties, null);
    this.configureStringProperty(propertyPrefix, Context.SECURITY_PROTOCOL, properties, null);
    this.configureStringProperty(propertyPrefix, Context.STATE_FACTORIES, properties, null);
    this.configureStringProperty(propertyPrefix, Context.URL_PKG_PREFIXES, properties, null);

    String ldapScopeValue = properties.getProperty(propertyPrefix + PROP_LDAP_SCOPE, DEFAULT_SCOPE);
    if (LDAP_SCOPE_SUBTREE.equals(ldapScopeValue)) {
        this.ldapScope = SearchControls.SUBTREE_SCOPE;
    } else if (LDAP_SCOPE_OBJECT.equals(ldapScopeValue)) {
        this.ldapScope = SearchControls.OBJECT_SCOPE;
    } else if (LDAP_SCOPE_ONELEVEL.equals(ldapScopeValue)) {
        this.ldapScope = SearchControls.ONELEVEL_SCOPE;
    } else {
        this.logger.warn("Invalid LDAP Scope value '" + ldapScopeValue + "'; using " + DEFAULT_SCOPE);
        this.ldapScope = SearchControls.SUBTREE_SCOPE;
    }

    /*
     * Get list of resolvers defined for this LDAP Engine
     */
    String resolversList = properties.getProperty(propertyPrefix + PROP_RESOLVERS);
    if (resolversList == null || resolversList.isEmpty()) {
        throw new PIPException("Invalid configuration for " + this.getClass().getName() + ": No "
                + propertyPrefix + PROP_RESOLVERS);
    }

    /*
     * Iterate the resolvers
     */
    for (String resolver : Splitter.on(',').trimResults().omitEmptyStrings().split(resolversList)) {
        /*
         * Get the LDAPResolver for this LDAPEngine
         */
        String resolverClassName = properties
                .getProperty(propertyPrefix + PROP_RESOLVER + "." + resolver + ".classname");
        if (resolverClassName == null) {
            throw new PIPException("Invalid configuration for " + this.getClass().getName() + ": No "
                    + propertyPrefix + PROP_RESOLVER + "." + resolver + ".classname");
        }

        LDAPResolver ldapResolverNew = null;
        try {
            Class<?> classResolver = Class.forName(resolverClassName);
            if (!LDAPResolver.class.isAssignableFrom(classResolver)) {
                this.logger.error("LDAPResolver class " + resolverClassName + " does not implement "
                        + LDAPResolver.class.getCanonicalName());
                throw new PIPException("LDAPResolver class " + resolverClassName + " does not implement "
                        + LDAPResolver.class.getCanonicalName());
            }
            ldapResolverNew = LDAPResolver.class.cast(classResolver.newInstance());
        } catch (Exception ex) {
            this.logger.error("Exception instantiating LDAPResolver for class '" + resolverClassName + "': "
                    + ex.getMessage(), ex);
            throw new PIPException("Exception instantiating LDAPResolver for class '" + resolverClassName + "'",
                    ex);
        }
        assert ldapResolverNew != null;
        ldapResolverNew.configure(propertyPrefix + PROP_RESOLVER + "." + resolver, properties,
                this.getIssuer());

        this.ldapResolvers.add(ldapResolverNew);
    }

}