You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Veniamin Fichin <3c...@mail.ru> on 2003/01/23 17:01:42 UTC

DataSourceRealm -- solved

Hello list!

    Recently I posted a question about how to make DataSourceRealm work. 
After waiting for an answer here and in tomcat-dev list, I've finally 
gone it. So for those who want to use it, here are my steps.
    Configure server.xml to have <Resource ...> and <ResourceParams ...> 
in <GlobalNamingResource> tag. Have a link to this resource using 
<ResourceLink ...> inside your Context. And configute <Realm ...> 
referencing to corresponding DataSource JNDI name (use absolute 
reference, i.e. starting with java:/comp/env , not relative like 
jdbc/something). Example server.xml and web.xml are in attach. If 
anybody will see any errors in these files, I'd be happy to hear them.
    Though I have one question. What if I don't want to have <Resource 
...> defined in global area? For example, I have several Contexts and 
want to use this resource in one of them only. Will ResourceLink's 
existance in one Context be the guarantee that only this Context will 
have an access to Resource, but not the others?

-- 
Veniamin Fichin  <3c...@mail.ru>
Programmer at    http://www.rbcsoft.ru/

Re: DataSourceRealm -- solved

Posted by Veniamin Fichin <3c...@mail.ru>.
Jacob Kjome wrote:

> You don't have to pur your <Resource> and <ResourceParam> tags in 
> <GlobalNamingResources> .  Just put them inside your <Context> take and 
> things will work fine.

    That's why I began this thread -- this configuration does not work.

...
<Context>
  <Resource />
  <ResourceParams>
...
  </ResourceParams>
  <Realm />
</Context>
...

    doesn't work, but

...
<GlobalNamingResource>
  <Resource />
  <ResourceParams>
...
  </ResourceParams>
</GlobalNamingResource>
...
<Context>
  <ResourceLink />
  <Realm />
</Context>

    works. And from exploring source code it looks like this.
    Method open:

--= [ cut ] =--
StandardServer server = (StandardServer) ServerFactory.getServer();
Context context = server.getGlobalNamingContext();
DataSource dataSource = (DataSource)context.lookup(dataSourceName);
return dataSource.getConnection();
--= [ / cut ] =--

    It's a global naming context that is searched for a JNDI name 
requested. Am I right?

> Jake
> 
> At 07:01 PM 1/23/2003 +0300, you wrote:
> 
>> Hello list!
>>
>>    Recently I posted a question about how to make DataSourceRealm 
>> work. After waiting for an answer here and in tomcat-dev list, I've 
>> finally gone it. So for those who want to use it, here are my steps.
>>    Configure server.xml to have <Resource ...> and <ResourceParams 
>> ...> in <GlobalNamingResource> tag. Have a link to this resource using 
>> <ResourceLink ...> inside your Context. And configute <Realm ...> 
>> referencing to corresponding DataSource JNDI name (use absolute 
>> reference, i.e. starting with java:/comp/env , not relative like 
>> jdbc/something). Example server.xml and web.xml are in attach. If 
>> anybody will see any errors in these files, I'd be happy to hear them.
>>    Though I have one question. What if I don't want to have <Resource 
>> ...> defined in global area? For example, I have several Contexts and 
>> want to use this resource in one of them only. Will ResourceLink's 
>> existance in one Context be the guarantee that only this Context will 
>> have an access to Resource, but not the others?

--= [ cut ] =--

-- 
Veniamin Fichin  <3c...@mail.ru>
Programmer at    http://www.rbcsoft.ru/


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DataSourceRealm -- solved

Posted by Jacob Kjome <ho...@visi.com>.
You don't have to pur your <Resource> and <ResourceParam> tags in 
<GlobalNamingResources> .  Just put them inside your <Context> take and 
things will work fine.

Jake

At 07:01 PM 1/23/2003 +0300, you wrote:
>Hello list!
>
>    Recently I posted a question about how to make DataSourceRealm work. 
> After waiting for an answer here and in tomcat-dev list, I've finally 
> gone it. So for those who want to use it, here are my steps.
>    Configure server.xml to have <Resource ...> and <ResourceParams ...> 
> in <GlobalNamingResource> tag. Have a link to this resource using 
> <ResourceLink ...> inside your Context. And configute <Realm ...> 
> referencing to corresponding DataSource JNDI name (use absolute 
> reference, i.e. starting with java:/comp/env , not relative like 
> jdbc/something). Example server.xml and web.xml are in attach. If anybody 
> will see any errors in these files, I'd be happy to hear them.
>    Though I have one question. What if I don't want to have <Resource 
> ...> defined in global area? For example, I have several Contexts and 
> want to use this resource in one of them only. Will ResourceLink's 
> existance in one Context be the guarantee that only this Context will 
> have an access to Resource, but not the others?
>
>--
>Veniamin Fichin  <3c...@mail.ru>
>Programmer at    http://www.rbcsoft.ru/
>
>
><?xml version="1.0" encoding="UTF-8" ?>
><Server port="8005" shutdown="SHUTDOWN" debug="0">
>  <GlobalNamingResources>
>   <Resource name="jdbc/datasource"
>             type="javax.sql.DataSource"
>             auth="Container"
>             scope="Unshareable"
>             description="Database resource for webapp project" />
>   <ResourceParams name="jdbc/esljsp">
>    <parameter>
>     <name>url</name>
>     <value>jdbc:oracle:thin:@www.dbhost.com:1521:sid</value>
>    </parameter>
>    <parameter>
>     <name>driverClassName</name>
>     <value>oracle.jdbc.driver.OracleDriver</value>
>    </parameter>
>    <parameter>
>     <name>username</name>
>     <value>username</value>
>    </parameter>
>    <parameter>
>     <name>password</name>
>     <value>password</value>
>    </parameter>
>    <parameter>
>     <name>maxActive</name>
>     <value>20</value>
>     <type>java.lang.Integer</type>
>    </parameter>
>    <parameter>
>     <name>maxIdle</name>
>     <value>10</value>
>     <type>java.lang.Integer</type>
>    </parameter>
>    <parameter>
>     <name>maxWait</name>
>     <value>5000</value>
>     <type>java.lang.Long</type>
>    </parameter>
>    <parameter>
>     <name>defaultAutoCommit</name>
>     <value>false</value>
>     <type>java.lang.Boolean</type>
>    </parameter>
>    <parameter>
>     <name>defaultReadOnly</name>
>     <value>false</value>
>     <type>java.lang.Boolean</type>
>    </parameter>
>    <parameter>
>     <name>validationQuery</name>
>     <value>select count(PRIMARYKEY_ID) from TABLE</value>
>    </parameter>
>    <parameter>
>     <name>removeAbandoned</name>
>     <value>true</value>
>    </parameter>
>    <parameter>
>     <name>removeAbandonedTimeout</name>
>     <value>60</value>
>    </parameter>
>    <parameter>
>     <name>logAbandoned</name>
>     <value>true</value>
>    </parameter>
>    <parameter>
>     <name>factory</name>
>     <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>    </parameter>
>   </ResourceParams>
>  </GlobalNamingResources>
>  <Service name="Tomcat-Standalone">
>   <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
>              port="8080"
>              minProcessors="5"
>              maxProcessors="75"
>              enableLookups="true"
>              acceptCount="10"
>              debug="0"
>              connectionTimeout="20000"
>              useURIValidationHack="false" />
>   <Engine name="Standalone"
>           defaultHost="localhost"
>           debug="99">
>    <Logger className="org.apache.catalina.logger.FileLogger"
>            verbosity="4"
>            prefix="catalina_log."
>            timestamp="true"
>            suffix=".txt" />
>    <Host name="localhost"
>          debug="99"
>          appBase="webapps"
>          unpackWARs="true"
>          autoDeploy="true">
>     <Logger className="org.apache.catalina.logger.FileLogger"
>             verbosity="4"
>             directory="logs"
>             prefix="localhost_log."
>             timestamp="true"
>             suffix=".txt" />
>     <Context path="/webapp"
>              docBase="webapp/web"
>              reloadable="true"
>              debug="99"
>              swallowOutput="true">
>      <Logger className="org.apache.catalina.logger.FileLogger"
>              verbosity="4"
>              prefix="localhost_webapp_log."
>              timestamp="true"
>              suffix=".txt" />
>      <ResourceLink name="jdbc/datasource"
>                    global="java:comp/env/jdbc/datasource"
>                    type="javax.sql.DataSource" />
>      <Realm className="org.apache.catalina.realm.DataSourceRealm"
>             dataSourceName="jdbc/datasource"
>             debug="99"
>             userTable="T_USERS"
>             userNameCol="NAME"
>             userCredCol="PASSWORD"
>             userRoleTable="T_USERROLES"
>             roleNameCol="ROLENAME" />
>     </Context>
>    </Host>
>   </Engine>
>  </Service>
></Server><?xml version="1.0" encoding="ISO-8859-1"?>
><!DOCTYPE web-app PUBLIC
>  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>  "http://java.sun.com/dtd/web-app_2_3.dtd"
> >
><web-app>
>  <resource-ref>
>   <description>Oracle database resource for esljsp project</description>
>   <res-ref-name>jdbc/esljsp</res-ref-name>
>   <res-type>javax.sql.DataSource</res-type>
>   <res-auth>Container</res-auth>
>   <res-sharing-scope>Unshareable</res-sharing-scope>
>  </resource-ref>
>  <security-constraint>
>   <web-resource-collection>
>    <web-resource-name>Administrator's interface</web-resource-name>
>    <url-pattern>/admin/*</url-pattern>
>    <http-method>GET</http-method>
>    <http-method>POST</http-method>
>   </web-resource-collection>
>   <auth-constraint>
>    <role-name>Administrator</role-name>
>   </auth-constraint>
>  </security-constraint>
>  <login-config>
>   <auth-method>FORM</auth-method>
>   <realm-name>Administrator's interface</realm-name>
>   <form-login-config>
>    <form-login-page>/login.jsp</form-login-page>
>    <form-error-page>/login_error.jsp</form-error-page>
>   </form-login-config>
>  </login-config>
>  <security-role>
>   <role-name>Administrator</role-name>
>  </security-role>
></web-app>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>