Welcome to the jGuard's wiki » jGuard Documentation » Integrate jGuard with Servlets and other

Integrate jGuard with Servlets and other

Last modified by RaffaelloPelagalli on 2007/01/29 22:13

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

Getting the Subject Object

  • in 1.0.x release
HttpAuthenticationUtils auth= (HttpAuthenticationUtils)request.getSession(true).getAttribute(HttpConstants.AUTHN_UTILS);
Subject subject = auth.getSubject();

  • in 0.80 release
AuthenticationUtils authUtils =  (AuthenticationUtils)request.getSession().getAttribute(HttpConstants.AUTH_UTILS);
Subject subject = authUtils.getSubject();
  • in 0.70 release
Subject subj =  (Subject)request.getSession().getAttribute(HttpConstants.SUBJECT_ID);

  • in release prior to 0.70 release:
In 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);

Getting the 'identity' credential

the 'identity' credential is the credential(i.e user attribute) which identify uniquely the user.

  • in 1.0.x release
//get the Subject
AuthenticationUtils authUtils =  (AuthenticationUtils)request.getSession().getAttribute(HttpConstants.AUTH_UTILS);
Subject subject = authUtils.getSubject();
//get the SubjectTemplate
AuthenticationManager am = (AuthenticationManager) request.getSession().getServletContext().getAttribute(SecurityConstants.AUTHENTICATION_MANAGER);
SubjectTemplate defaultTemplate = am.getDefaultSubjectTemplate();
JGuardCredential identityCredential = SubjectUtils.getIdentityCredential(subject,defaultTemplate);
Tags:
Created by diabolo512 on 2006/02/09 14:32

jGuard team copyright 2004-2009
3.1.1