Example usage for javax.naming InitialContext getEnvironment

List of usage examples for javax.naming InitialContext getEnvironment

Introduction

In this page you can find the example usage for javax.naming InitialContext getEnvironment.

Prototype

public Hashtable<?, ?> getEnvironment() throws NamingException 

Source Link

Usage

From source file:JNDIUtil.java

public static Properties getDefaultProperties() {
    Properties defaultProperties = new Properties();
    try {//  w  ww.  j a v a 2 s  .  c o m
        InitialContext context = new InitialContext();
        defaultProperties.putAll(context.getEnvironment());
    } catch (Exception e) {
        System.out.println("Unexpected exception when trying to retrieve default naming context." + e);
    }
    return defaultProperties;
}

From source file:org.betaconceptframework.astroboa.engine.service.security.AstroboaLogin.java

private void initializeExternalIdentityStore(String identityStoreLocation) throws FailedLoginException {
    try {//from w  ww .j  av  a2s  .  c  o m
        InitialContext context = new InitialContext();

        //First check to see if initial context has been initiated at all
        Hashtable<?, ?> env = context.getEnvironment();
        String initialContextFactoryName = env != null ? (String) env.get(Context.INITIAL_CONTEXT_FACTORY)
                : null;

        if (StringUtils.isNotBlank(initialContextFactoryName)) {

            Object serviceReference = context.lookup(identityStoreLocation);

            if (!(serviceReference instanceof IdentityStore)) {
                if (!identityStoreLocation.endsWith("/local")) {
                    //JNDIName is provided by the user and the object it references is not an instance of IdentityStore.
                    //It is probably an instance of NamingContext which is on top of a local or remote service
                    //Since JNDIName does not end with "/local" , try to locate the local service under the returned NamingContext
                    identityStore = (IdentityStore) context.lookup(identityStoreLocation + "/local");
                } else {
                    throw new Exception("JNDI Name " + identityStoreLocation
                            + " refers to an object whose type is not IdentityStore. Unable to locate. External Identity Store ");
                }
            } else {
                identityStore = (IdentityStore) serviceReference;
            }
            //TODO: It may also be the case another login to the identity store must be done

        } else {
            throw new Exception(
                    "Initial Context Factory Name is blank therefore no initial context is configured, thus any lookup will result in exception."
                            + "External Identity Store " + identityStoreLocation);
        }

    } catch (Exception e) {
        logger.error("", e);
        throw new FailedLoginException("During connection to external Identity Store " + identityStoreLocation);
    }

}

From source file:org.cloudgraph.common.CommonTest.java

/**
 * Get the client's env context for a given name.
 *///from   w w  w .  ja  v  a 2 s.  c  o  m
protected InitialContext getInitialContext(String clientName) throws NamingException {
    InitialContext iniCtx = new InitialContext();
    Hashtable env = iniCtx.getEnvironment();
    env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
    env.put("j2ee.clientName", clientName);
    return new InitialContext(env);
}

From source file:org.dhatim.util.JNDIUtil.java

public static Properties getDefaultProperties() {
    Properties defaultProperties = new Properties();
    try {/*from  w  w  w . j a  v  a  2s .c o  m*/
        InitialContext context = new InitialContext();
        defaultProperties.putAll(context.getEnvironment());
    } catch (Exception e) {
        logger.debug("Unexpected exception when trying to retrieve default naming context.", e);
    }
    return defaultProperties;
}