Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C4D3E17D0C for ; Mon, 13 Oct 2014 11:35:56 +0000 (UTC) Received: (qmail 60094 invoked by uid 500); 13 Oct 2014 11:35:50 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 60029 invoked by uid 500); 13 Oct 2014 11:35:50 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 60017 invoked by uid 99); 13 Oct 2014 11:35:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Oct 2014 11:35:50 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of dmikusa@pivotal.io designates 74.125.82.41 as permitted sender) Received: from [74.125.82.41] (HELO mail-wg0-f41.google.com) (74.125.82.41) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Oct 2014 11:35:45 +0000 Received: by mail-wg0-f41.google.com with SMTP id b13so8461391wgh.12 for ; Mon, 13 Oct 2014 04:35:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=Ga+WEnMuhKjO4AdoovjxoxqD1iGbVYfrDB6rrb0pDnQ=; b=HgPE3cNtVSNwRafbS0a+Ft+PYCl9MCsSNNSxc7fRPqhYaYVj6dcUMe8zQj9lk0gTO+ l7SD61INIpgOmVd0y/UTE4g81KNVVkURFTeqLD4DVEY1aAiXXSwxWuAE42eucs/mGmlU +CSr8RFNdq3ErGis8sFD1hklLNQ4wa0cHLki/hhjAt7w7awXF0ZOf2N9eyCCwl7bxfHZ yCGHzhUygz98mxIvmP2kNslhPoT1EIRG6XCIMYfFtSpghPrPJ5wlH0YXah6IH3hXfP7f vH4IDnWzKylcKwvftxUgHsOZqfQQSUYCgun+K4H9SSSo1lnkQMjMc06wdww3Orbo18QJ OvGA== X-Gm-Message-State: ALoCoQn65aOzpFbijbJ4eyEddLhluTUIb0MimP9e8M+bSQ8At6O6wRZIV5BacH7y44i6rrS37bqo MIME-Version: 1.0 X-Received: by 10.180.78.106 with SMTP id a10mr235644wix.23.1413200124557; Mon, 13 Oct 2014 04:35:24 -0700 (PDT) Received: by 10.217.12.205 with HTTP; Mon, 13 Oct 2014 04:35:24 -0700 (PDT) In-Reply-To: <0194A51B-FE2B-45E8-9BF5-5A72D2D7F069@servicesymphony.com> References: <0194A51B-FE2B-45E8-9BF5-5A72D2D7F069@servicesymphony.com> Date: Mon, 13 Oct 2014 07:35:24 -0400 Message-ID: Subject: Re: Custom Realm From: Daniel Mikusa To: Tomcat Users List Content-Type: multipart/alternative; boundary=f46d043be1586bfa7905054c4b78 X-Virus-Checked: Checked by ClamAV on apache.org --f46d043be1586bfa7905054c4b78 Content-Type: text/plain; charset=UTF-8 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 > > > > > 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 > > > > > > > > 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 --f46d043be1586bfa7905054c4b78--