Re: Best Practices for Handling Client Authentication
Greg Trasuk <[email protected]>
| Newsgroups | gmane.comp.java.sun.javaspaces |
|---|---|
| Message-ID | <1144958689.7320.15.camel@gillian> |
Hi Brian:
On Thu, 2006-04-13 at 14:49, Brian Ferris wrote:
> At some point I have to call Subject.doAs to elevate my privileges.
> I have two options:
>
> 1) I can call this method once to wrap all subsequent code
> 2) I can call this method every time I wish to access the privileged
> object (in this case my JavaSpace)
>
> The first option is tricky, because my application is quite complex
> and there is no one nice entry point to do the login.
#1 doesn't work well because the Swing library doesn't maintain your security context, so you end up using subject.doAs() everywhere.
For #2, there is a utility class in the Harvester tools jar in the Harvester distribution called SubjectProxyFactory. Usage is as follows:
/* Begin code snippet */
JavaSpace s= ...//Get it however you get it.
SubjectProxyFactory spf=new SubjectProxyFactory();
spf.setSubject( /* Insert your Subject here */);;
JavaSpace spaceAsSubject = (JavaSpace) spf.getProxy(s);
/* Use spaceAsSubject as though it were a regular space. */
spaceAsSubject.take(....);
spaceAsSubject.write(....);
/* End code snippet */
The SubjectProxyFactory will proxy any interface, not just Space. Also possibly of interest is that you can call spf.setSubject again with a different Subject and all the existing proxies will use the new subject. Harvester-tools can be used whether or not you're using Harvester, although you might need to have Services.jar from the Harvester distribution in your classpath (I don't think so if you just want to use SubjectProxyFactory, but I'm not absolutely sure). Get Harvester from http://harvester.jini.org.
Cheers,
Greg.
--
Greg Trasuk, President
StratusCom Manufacturing Systems Inc. - We use information technology to
solve business problems on your plant floor.
http://stratuscom.com
===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff JAVASPACES-USERS". For general help, send email to
[email protected] and include in the body of the message "help".
To view past JAVASPACES-USERS postings, please see:
http://archives.java.sun.com/archives/javaspaces-users.html