KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jguard > jee > taglib > Principals


1 /*
2 jGuard is a security framework based on top of jaas (java authentication and authorization security).
3 it is written for web applications, to resolve simply, access control problems.
4 version $Name$
5 http://sourceforge.net/projects/jguard/
6
7 Copyright (C) 2004 Charles GAY
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23
24 jGuard project home page:
25 http://sourceforge.net/projects/jguard/
26
27 */

28 package net.sf.jguard.jee.taglib;
29
30 import java.util.Iterator JavaDoc;
31 import java.util.Set JavaDoc;
32
33 import javax.security.auth.Subject JavaDoc;
34 import javax.servlet.jsp.JspTagException JavaDoc;
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 JavaDoc var ="principals";
47     private final static Class JavaDoc defaultClassName = RolePrincipal.class;
48     private Class JavaDoc clazz = defaultClassName;
49     private Iterator JavaDoc principalsIt;
50
51     public final void setClassName(String JavaDoc className) {
52         try {
53             this.clazz = Class.forName(className);
54         } catch (ClassNotFoundException JavaDoc e) {
55             logger.info(" 'className' attribute does not map to an existing or reachable class ");
56         }
57     }
58
59     protected boolean hasNext() throws JspTagException JavaDoc {
60         return principalsIt.hasNext();
61     }
62
63     protected Object JavaDoc next() throws JspTagException JavaDoc {
64         return principalsIt.next();
65     }
66
67     protected void prepare() throws JspTagException JavaDoc {
68         Subject JavaDoc subject = TagUtils.getSubject(this.pageContext);
69         Set JavaDoc principals = subject.getPrincipals(clazz);
70         if(principals==null){
71             throw new JspTagException JavaDoc("principal's set is null ");
72         }
73         principalsIt = principals.iterator();
74     }
75 }
76
Popular Tags