1 28 package net.sf.jguard.jee.taglib; 29 30 import java.util.Iterator ; 31 import java.util.Set ; 32 33 import javax.security.auth.Subject ; 34 import javax.servlet.jsp.JspTagException ; 35 import javax.servlet.jsp.jstl.core.LoopTagSupport; 36 37 import net.sf.jguard.core.principals.RolePrincipal; 38 39 import org.apache.commons.logging.Log; 40 import org.apache.commons.logging.LogFactory; 41 42 public class Principals extends LoopTagSupport { 43 44 private static final Log logger = LogFactory.getLog(Principals.class); 45 private static final long serialVersionUID = 5869136846797237440L; 46 private String var ="principals"; 47 private final static Class defaultClassName = RolePrincipal.class; 48 private Class clazz = defaultClassName; 49 private Iterator principalsIt; 50 51 public final void setClassName(String className) { 52 try { 53 this.clazz = Class.forName(className); 54 } catch (ClassNotFoundException e) { 55 logger.info(" 'className' attribute does not map to an existing or reachable class "); 56 } 57 } 58 59 protected boolean hasNext() throws JspTagException { 60 return principalsIt.hasNext(); 61 } 62 63 protected Object next() throws JspTagException { 64 return principalsIt.next(); 65 } 66 67 protected void prepare() throws JspTagException { 68 Subject subject = TagUtils.getSubject(this.pageContext); 69 Set principals = subject.getPrincipals(clazz); 70 if(principals==null){ 71 throw new JspTagException ("principal's set is null "); 72 } 73 principalsIt = principals.iterator(); 74 } 75 } 76 | Popular Tags |