You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Uros Kotnik <ur...@asterius.co.yu> on 2003/02/11 11:43:02 UTC

Accessing DataSourceRealm from servlet

Hi,

I implemented my own class for user authentication based on RealmBase
class, basicaly it's DataSourceRealm class just changed to my needs
(added some methods like getUserRealName() etc.)
So the class is

public class MyDataSourceRealm
    extends RealmBase {.

I put jar with my class  in tc_home/server/lib, defined it in
server.xml. And everything is working OK.

Only problem that I have is that I can't access that class from servlet
and use some of my added methods, like this:

      try{
        Context ctx = new InitialContext();
        MyDataSourceRealm um =
(MyDataSourceRealm)ctx.lookup("java:comp/myDataSourceRealm");
        String sFullName = um.getFullName(req.getRemoteUser());
      }
      catch(NamingException e){
        System.out.println(e.toString());       
      }

I get :

javax.naming.NameNotFoundException: Name myDataSourceRealm is not bound
in this
Context

So, how I can gain access to myDataSourceRealm ?

Thanx


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Re: Accessing DataSourceRealm from servlet

Posted by Glenn Nielsen <gl...@mail.more.net>.
The UserDatabaseRealm can do this, look at it as an example.

Glenn

Uros Kotnik wrote:
> So is there a way to access my own realm implementation from Servlet ?
> 
> 
> 
> -----Original Message-----
> From: Glenn Nielsen [mailto:glenn@mail.more.net] 
> Sent: Tuesday, February 11, 2003 13:26 
> To: Tomcat Developers List
> Subject: Re: Accessing DataSourceRealm from servlet
> 
> The DataSourceRealm uses a JNDI named JDBC DataSource, it is not a
> JNDI named resource itself.
> 
> Glenn
> 
> Uros Kotnik wrote:
> 
>>Hi,
>>
>>I implemented my own class for user authentication based on RealmBase
>>class, basicaly it's DataSourceRealm class just changed to my needs
>>(added some methods like getUserRealName() etc.)
>>So the class is
>>
>>public class MyDataSourceRealm
>>    extends RealmBase {.
>>
>>I put jar with my class  in tc_home/server/lib, defined it in
>>server.xml. And everything is working OK.
>>
>>Only problem that I have is that I can't access that class from
> 
> servlet
> 
>>and use some of my added methods, like this:
>>
>>      try{
>>        Context ctx = new InitialContext();
>>        MyDataSourceRealm um =
>>(MyDataSourceRealm)ctx.lookup("java:comp/myDataSourceRealm");
>>        String sFullName = um.getFullName(req.getRemoteUser());
>>      }
>>      catch(NamingException e){
>>        System.out.println(e.toString());       
>>      }
>>
>>I get :
>>
>>javax.naming.NameNotFoundException: Name myDataSourceRealm is not
> 
> bound
> 
>>in this
>>Context
>>
>>So, how I can gain access to myDataSourceRealm ?
>>
>>Thanx
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


RE: Accessing DataSourceRealm from servlet

Posted by Uros Kotnik <ur...@asterius.co.yu>.
So is there a way to access my own realm implementation from Servlet ?



-----Original Message-----
From: Glenn Nielsen [mailto:glenn@mail.more.net] 
Sent: Tuesday, February 11, 2003 13:26 
To: Tomcat Developers List
Subject: Re: Accessing DataSourceRealm from servlet

The DataSourceRealm uses a JNDI named JDBC DataSource, it is not a
JNDI named resource itself.

Glenn

Uros Kotnik wrote:
> Hi,
> 
> I implemented my own class for user authentication based on RealmBase
> class, basicaly it's DataSourceRealm class just changed to my needs
> (added some methods like getUserRealName() etc.)
> So the class is
> 
> public class MyDataSourceRealm
>     extends RealmBase {.
> 
> I put jar with my class  in tc_home/server/lib, defined it in
> server.xml. And everything is working OK.
> 
> Only problem that I have is that I can't access that class from
servlet
> and use some of my added methods, like this:
> 
>       try{
>         Context ctx = new InitialContext();
>         MyDataSourceRealm um =
> (MyDataSourceRealm)ctx.lookup("java:comp/myDataSourceRealm");
>         String sFullName = um.getFullName(req.getRemoteUser());
>       }
>       catch(NamingException e){
>         System.out.println(e.toString());       
>       }
> 
> I get :
> 
> javax.naming.NameNotFoundException: Name myDataSourceRealm is not
bound
> in this
> Context
> 
> So, how I can gain access to myDataSourceRealm ?
> 
> Thanx
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Re: Accessing DataSourceRealm from servlet

Posted by Glenn Nielsen <gl...@mail.more.net>.
The DataSourceRealm uses a JNDI named JDBC DataSource, it is not a
JNDI named resource itself.

Glenn

Uros Kotnik wrote:
> Hi,
> 
> I implemented my own class for user authentication based on RealmBase
> class, basicaly it's DataSourceRealm class just changed to my needs
> (added some methods like getUserRealName() etc.)
> So the class is
> 
> public class MyDataSourceRealm
>     extends RealmBase {.
> 
> I put jar with my class  in tc_home/server/lib, defined it in
> server.xml. And everything is working OK.
> 
> Only problem that I have is that I can't access that class from servlet
> and use some of my added methods, like this:
> 
>       try{
>         Context ctx = new InitialContext();
>         MyDataSourceRealm um =
> (MyDataSourceRealm)ctx.lookup("java:comp/myDataSourceRealm");
>         String sFullName = um.getFullName(req.getRemoteUser());
>       }
>       catch(NamingException e){
>         System.out.println(e.toString());       
>       }
> 
> I get :
> 
> javax.naming.NameNotFoundException: Name myDataSourceRealm is not bound
> in this
> Context
> 
> So, how I can gain access to myDataSourceRealm ?
> 
> Thanx
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org