You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Daniel Santos <ds...@att.com> on 2006/11/20 22:44:24 UTC

Help with custom Realm

Hello, I'm implementing a new realm for a custom single sign-on dealie that
my company is using (so I can use container managed security with their new
system).  Everything is going smoothly, except that I can't figure out how
to get an object I declared as a <Resource> under the context, from outside
of the web-application space.  Basically, my Realm object works great, but
it needs pluggable support objects and I'm having problems getting those to
the Realm (perhaps I'm even putting them in a bad place?)  Anyway, I figured
I would declare them at the same level as the Realm.  I'm declaring this
Realm at the Context level now, and I need to get it done for a deadline,
and then make sure it works at the Server, Host, etc. level later.

sample snipped from <context> section:

<Resource
	name="a.unique.name.for.something.i.Need"
	auth="Container"
	type="com.att.my.package.tomcat.SupportObject"
	factory="org.apache.naming.factory.BeanFactory"
	dataSourceName="jdbc/myApp"
	userTableName="users"
	userFieldName="id"
	lastActiveFieldName="last_active"
/>

<Realm
	className="com.att.my.package.tomcat.SuperRealm"
	validationEnv="PROD"
	loginURL="https://www.yadayada.att.com/login"
	logoutURL="https://www.yadayada.att.com/logout"
	myThingieName="a.unique.name.for.something.i.Need"
/>

Of course, I have a pretty mbean for the realm (I'm implementing RealmBase
to save me some time although I don't use 80% of RealmBase) and my custom
realm comes up fine.  What I haven't figured out how to do is to get a
context that contains this crap!!  I can do it from my web app fairly simply
with this:

	import com.att.my.package.tomcat.SupportObject;
	import javax.naming.Context;

	Context initialContext = new InitialContext();
	Context envContext = (Context)initialContext.lookup("java:comp/env");
	Object o = envContext.lookup("a.unique.name.for.something.i.Need");
	SupportObject mySupportObject = (SupportObject)o;

and hurray!  It works.  I get a new instance of my support object class,
fully initialized.  Of course, I need this in my realm, not the web app. 
This will be used by many different Tomcat-based web applications and I want
it to be as clean and transparent as possible.

My realm's container happens to be a StandardContext (or wrapper to it, I
forgot) and via the fields namingContextListener.envCtx will give me the
Context I need to create my support objects, but it's hacky and
"StandardContext.namingContextListener" is private.

So here are my questions:

A.	Is using a <Resrouce> or <GlobalResource> a healthy way to provide
support objects to a custom Realm?
B.	Would it be better to hack something else so that I can embed these into
the <Realm> tag as children?  (I'm not super-duper strong on the commons
digester, although it's really cool)
C.	If what I'm tyring to do looks sane, can you please show me how to get
the javax.naming.Context or org.apache.naming.NamingContext object that can
create my support objects for me?

Thanks,
Daniel



-- 
View this message in context: http://www.nabble.com/Help-with-custom-Realm-tf2672022.html#a7451310
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org