1 28 package net.sf.jguard.jee.taglib; 29 30 import java.io.IOException ; 31 32 import javax.security.auth.Subject ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import javax.servlet.http.HttpSession ; 36 import javax.servlet.jsp.JspTagException ; 37 import javax.servlet.jsp.PageContext ; 38 39 import net.sf.jguard.ext.SecurityConstants; 40 import net.sf.jguard.jee.authentication.http.HttpAuthenticationUtils; 41 import net.sf.jguard.jee.authentication.http.HttpConstants; 42 43 public class TagUtils { 44 45 46 53 protected static Subject getSubject(PageContext pageContext) throws JspTagException { 54 HttpSession session = pageContext.getSession(); 55 HttpAuthenticationUtils httpUtils = (HttpAuthenticationUtils)session.getAttribute(HttpConstants.AUTHN_UTILS); 56 Subject subject = null; 57 if(httpUtils!=null){ 58 subject = httpUtils.getSubject(); 59 } 60 61 boolean local = true; 62 String authenticationScope = (String )pageContext.getServletContext().getAttribute(SecurityConstants.AUTHENTICATION_SCOPE); 63 if(SecurityConstants.JVM_SCOPE.equalsIgnoreCase(authenticationScope)){ 64 local = false; 65 } 66 if(subject==null ||session.getAttribute(HttpConstants.AUTHN_UTILS)==null){ 67 try { 68 HttpAuthenticationUtils.authenticate((HttpServletRequest )pageContext.getRequest(),(HttpServletResponse )pageContext.getResponse(),false,local); 69 subject = ((HttpAuthenticationUtils)session.getAttribute(HttpConstants.AUTHN_UTILS)).getSubject(); 71 } catch (IOException e) { 72 throw new JspTagException (e); 73 } 74 } 75 return subject; 76 } 77 78 } 79 | Popular Tags |