Integrate jGuard with Servlets and other "web" classes (Struts Actions, etc.)
Getting the Subject Object
HttpAuthenticationUtils auth= (HttpAuthenticationUtils)request.getSession(true).getAttribute(HttpConstants.AUTHN_UTILS);
Subject subject = auth.getSubject();
AuthenticationUtils authUtils = (AuthenticationUtils)request.getSession().getAttribute(HttpConstants.AUTH_UTILS);
Subject subject = authUtils.getSubject();
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.
//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);