Welcome to the jGuard's wiki » 全体像 » 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 2006/01/13 05:34

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 Masa Naka on 2006/01/13 05:34

jGuard team copyright 2004-2009
3.1.1