Hello,

your Login Module in the server env and you must access the GlobalNamingContext
from server direct.


import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.sql.DataSource;

import org.apache.naming.ContextBindings;
import org.apache.catalina.ServerFactory;
import org.apache.catalina.core.StandardServer;

public class xxx {
....
public Connection open(String dataSouceName) {
try {
Context context = null;
StandardServer server =
(StandardServer) ServerFactory.getServer();
context = server.getGlobalNamingContext();
DataSource dataSource = (DataSource)context.lookup(dataSourceName);
return dataSource.getConnection();
} catch (Exception e) {
// ???
} return null;
}
}


Only at your web application you have a comp/env JNDI Tree ( Look at resource-link server.xml configuration)

regards
peter
http://tomcat.objektpark.org

Beloglazov Maksim schrieb:

Hello,

I'm stuck with the problem trying to get a way out for several hours:
I have a database resource declared in server.xml in GlobalNamingResources part
Also I have a JAAS login module which is intended to use this JNDI database resource.
And I can't get access to this resource my JAAS login module. The error is


...
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:815)
at org.apache.naming.NamingContext.lookup(NamingContext.java:198)
at ru.mb.security.jaas.RDBMSJAASLoginModule.rdbmsValidate(Unknown Source)
at ru.mb.security.jaas.RDBMSJAASLoginModule.login(Unknown Source)
...


server.xml:
<GlobalNamingResources>
       <Resource name="jdbc/MerxDB" auth="Container"
                 type="javax.sql.DataSource" scope="Sharable"/>

<ResourceParams name="jdbc/MerxDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>SYSDBA</value>
</parameter>
<parameter>
<name>password</name>
<value>masterkey</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.firebirdsql.jdbc.FBDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:firebirdsql:localhost/3050:/var/db/firebird/merx.gdb</value>
</parameter>
</ResourceParams>
...
</GlobalNamingResources>


code from login module:
...
Context ctx = new InitialContext();
if (null==ctx) throw new Exception("No context");
Context envCtx = (Context)ctx.lookup("java:comp/env");
if (null==envCtx) throw new Exception("No context");
DataSource ds = (DataSource)envCtx.lookup("jdbc/MerxDB");
...

Is there any way out? Any help is greatly appreciated.

Maksim Beloglazov



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to