tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Mikusa <dmik...@pivotal.io>
Subject Re: Custom Realm
Date Mon, 13 Oct 2014 11:35:24 GMT
On Sun, Oct 12, 2014 at 8:26 AM, Service Symphony <
meeraj@servicesymphony.com> wrote:

> I have got it working, since the server is not started yet, none of the
> underlying infrastructure is available in the realm class constructor.
>
> Sent from my iPhone
>
> > On 11 Oct 2014, at 22:37, Meeraj Kunnumpurath <
> meeraj@servicesymphony.com> wrote:
> >
> > Hi,
> >
> > I have some specific requirements for security and I have been trying to
> right a custom realm, that reads information from the database.
> >
> > 1. I have added a datasource in the global naming resources section in
> the server.xml
> > 2. I have packaged the realm class in a JAR file and copied it the
> server lib
> > 3. I have included a context.xml in the WAR META-INF, that declares the
> realm from (2)
> >
> > In the constructor of the realm class, I try to look up the datasource,
> >
> > 1. If I use new InitialContext().lookup, I get a name not found
> exception.
> > 2. If I try to get the global naming context, by calling getServer from
> RealBase, getServer returns a null reference.
> >
> > This is the entry in server.xml
> >
> >        <Resource name="MyDS"
> >               auth="Container"
> >               type="javax.sql.DataSource"
> >               driverClassName="oracle.jdbc.OracleDriver"
> >               factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
> >               url="jdbc:oracle:thin:@10.211.55.7:1521:xe"
> >               username="meeraj"
> >               password="password"
> >               maxTotal="20"
> >               maxIdle="10"
> >               maxWaitMillis="-1"
> >               accessToUnderlyingConnectionAllowed="true"/>
> >
> > This is the entry in the context.xml
> >
> > <Realm className="com.ss.security.provider.DatabaseRealm" digest="SHA1"/>
> >
> > This is the constructor of the Realm class
> >
> >     public DatabaseRealm() throws NamingException {
> >         Context context = null;
> >         try {
> >             context = new InitialContext();
> >             template = new SimpleJdbcTemplate((DataSource)
> context.lookup("MyDS"));
> >         } finally {
> >             if (context != null) context.close();
> >         }
> >     }
> >
> > Any pointers will be highly appreciated.
> >
> > Many thanks
> >
> > --
> > Meeraj Kunnumpurath
> > Director and Executive Principal
> > Service Symphony Ltd
> > 00 44 7702 693597
> > meeraj@servicesymphony.com
>

For what it's worth, DataSourceRealm sounds very similar to this.  Might
serve as a good example.


http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/realm/DataSourceRealm.java?view=markup

Dan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message