Example usage for javax.naming.spi InitialContextFactory getClass

List of usage examples for javax.naming.spi InitialContextFactory getClass

Introduction

In this page you can find the example usage for javax.naming.spi InitialContextFactory getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.rhq.enterprise.server.naming.AccessCheckingInitialContextFactoryBuilder.java

/**
 * @param defaultFactory the default factory to use if none can be deduced from the environment. If null, an attempt
 * is made to obtain the default InitialContextFactory of JBoss AS (which may fail depending on the classloading
 * "situation")./* w  w  w.ja v  a 2s  . co m*/
 * @param pretendNoFactoryBuilder true if the naming contexts should pretend as if there was no initial context
 * factory builder installed. This is to support environments as AS4, where there really was no builder initially
 * and the lookup relied on that fact.
 * 
 * @throws NamingException
 */
public AccessCheckingInitialContextFactoryBuilder(InitialContextFactory defaultFactory,
        final boolean pretendNoFactoryBuilder) throws NamingException {
    if (defaultFactory == null) {
        defaultFactory = getJbossDefaultInitialContextFactory();
    }

    defaultFactoryClassName = defaultFactory.getClass().getName();

    for (FactoryType ft : FactoryType.values()) {
        typeDefaults.put(ft, ft.wrap(defaultFactory));
    }

    this.pretendNoFactoryBuilder = pretendNoFactoryBuilder;

    this.defaultFactory = new InitialContextFactory() {
        public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
            return typeDefaults.get(FactoryType.detect(environment, pretendNoFactoryBuilder))
                    .getInitialContext(environment);
        }
    };
}

From source file:org.rhq.jndi.AccessCheckingInitialContextFactoryBuilder.java

private static InitialContextFactory createSecureWrapper(InitialContextFactory factory,
        Hashtable<?, ?> environment) {
    String providerUrl = (String) environment.get(Context.PROVIDER_URL);

    if (providerUrl == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Wrapping " + factory + " of class " + factory.getClass()
                    + " in an access checking wrapper. No provider URL detected.");
        }// ww  w. ja  v a 2 s.c  o  m
        return getAccessCheckingFactory(factory);
    } else {
        try {
            URI uri = new URI(providerUrl);
            InetAddress providerHost = InetAddress.getByName(uri.getHost());

            //check if we are accessing the RHQ server through some remoting
            //interface.
            if (uri.getPort() == JNP_PORT && SERVER_BIND_IPS.contains(providerHost)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Wrapping " + factory + " of class " + factory.getClass()
                            + " in an access checking wrapper. The provider URL points to this server.");
                }
                return getAccessCheckingFactory(factory);
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Wrapping " + factory + " of class " + factory.getClass()
                            + " in an URL preferring wrapper to enable remote connections.");
                }
                return getURLPreferringFactory(factory);
            }
        } catch (URISyntaxException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("The " + Context.PROVIDER_URL
                        + " is not a valid URI. Falling back to using the access checking wrapper for the factory "
                        + factory + " of class " + factory.getClass() + ".", e);
            }
            return getAccessCheckingFactory(factory);
        } catch (UnknownHostException e) {
            //let the factory deal with the unknown host...
            //this most probably shouldn't be secured because localhost addresses
            //should be resolvable.
            if (LOG.isDebugEnabled()) {
                LOG.debug("The " + Context.PROVIDER_URL
                        + " is not resolvable. Falling back to using the URL preferring wrapper for the factory "
                        + factory + " of class " + factory.getClass() + ".", e);
            }
            return getURLPreferringFactory(factory);
        }
    }
}