001: /*
002: * argun 1.0
003: * Web 2.0 delivery framework
004: * Copyright (C) 2007 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.biz
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.web.security;
024:
025: import java.sql.ResultSet;
026: import java.sql.SQLException;
027: import java.util.ArrayList;
028: import java.util.Collection;
029: import java.util.Iterator;
030: import java.util.Properties;
031:
032: import org.apache.xpath.CachedXPathAPI;
033: import org.w3c.dom.Element;
034:
035: import biz.hammurapi.config.ConfigurationException;
036: import biz.hammurapi.sql.DataAccessObject;
037: import biz.hammurapi.sql.SQLProcessor;
038: import biz.hammurapi.web.security.sql.SecurityEngine;
039: import biz.hammurapi.web.security.sql.UserRoleImpl;
040: import biz.hammurapi.xml.dom.DOMUtils;
041:
042: /**
043: * @author Pavel Vlasov
044: * @revision $Revision$
045: */
046: public class Role extends UserRoleImpl implements DataAccessObject {
047:
048: /**
049: *
050: */
051: public Role() {
052: // Default constructor
053: }
054:
055: /**
056: * @param force
057: */
058: public Role(boolean force) {
059: super (force);
060: }
061:
062: /**
063: * @param rs
064: * @throws SQLException
065: */
066: public Role(ResultSet rs) throws SQLException {
067: super (rs);
068: }
069:
070: /**
071: * @param holder
072: * @param force
073: * @throws ConfigurationException
074: */
075: public Role(Element holder, boolean force)
076: throws ConfigurationException {
077: super (holder, force);
078: }
079:
080: /**
081: * @param holder
082: * @param pathMap
083: * @param cxpa
084: * @param force
085: * @throws ConfigurationException
086: */
087: public Role(Element holder, Properties pathMap,
088: CachedXPathAPI cxpa, boolean force)
089: throws ConfigurationException {
090: super (holder, pathMap, cxpa, force);
091: }
092:
093: private Collection permissions;
094:
095: /**
096: * Loads permissions associated with the role
097: */
098: public void setSQLProcessor(SQLProcessor processor)
099: throws SQLException {
100: SecurityEngine engine = new SecurityEngine(processor);
101: permissions = engine.getAssignedRolePermission(getName(),
102: new ArrayList(), Permission.class);
103: }
104:
105: public void toDom(Element holder) {
106: super .toDom(holder);
107: DOMUtils.toDom(permissions, "permissions", holder);
108: }
109:
110: /**
111: * @param className
112: * @param actionName
113: * @return True if permission for given class and action is granted by this permission or permissions
114: * implied by this permission.
115: */
116: public Boolean isGranted(String className, String actionName) {
117: Iterator it = permissions.iterator();
118: while (it.hasNext()) {
119: Boolean ret = ((Permission) it.next()).isGranted(className,
120: actionName);
121: if (ret != null) {
122: return ret;
123: }
124: }
125:
126: return null;
127: }
128:
129: }
|