Welcome to the jGuard's wiki » Welcome on your Wiki » General section » Integrate jGuard with Servlets and other "web" classes (Struts Actions, etc.)

Integrate jGuard with Servlets and other "web" classes (Struts Actions, etc.)

Last modified by RaffaelloPelagalli on 2005/12/05 10:51

Integrate jGuard with Servlets and other "web" classes (Struts Actions, etc.)

Get the Subject object

When authentication is done by AccessFilter, it stores the newly-created Subject object in the HttpSession, using "subjectID" as the key. This way, you can obtain the Subject object with the code below (the HttpServletRequest servlet reference is the request object, and we also use the interface net.sf.jguard.filters.Constants):

Subject subj =  (Subject)request.getSession().getAttribute(HttpConstants.SUBJECT_ID);

note: on releases prior to jGuard 0.70, you can obtain the Subject with the following code (Constants is used instead of HttpConstants):

Subject subj =  (Subject)request.getSession().getAttribute(Constants.SUBJECT_ID);

Refreshing of authentication and authorization data in jGuard

Changes on authorization and authentication data can be made on the fly, reflecting the updates immediatly, without the need of restarting any server. To do this, you could use the following code::

Policy policy = (Policy)Policy.getPolicy();
JGuardPolicy jg = (JGuardPolicy)policy;
jg.refresh(Thread.currentThread().getContextClassLoader());
Tags:
Created by diabolo512 on 2005/09/28 18:46

jGuard team copyright 2004-2009
3.1.1