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 Group extends UserRoleImpl implements DataAccessObject {
047:
048: /**
049: *
050: */
051: public Group() {
052: // Default constructor
053: }
054:
055: /**
056: * @param force
057: */
058: public Group(boolean force) {
059: super (force);
060: }
061:
062: /**
063: * @param rs
064: * @throws SQLException
065: */
066: public Group(ResultSet rs) throws SQLException {
067: super (rs);
068: }
069:
070: /**
071: * @param holder
072: * @param force
073: * @throws ConfigurationException
074: */
075: public Group(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 Group(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: private Collection roles;
095:
096: /**
097: * Loads permissions associated with the role
098: */
099: public void setSQLProcessor(SQLProcessor processor)
100: throws SQLException {
101: SecurityEngine engine = new SecurityEngine(processor);
102: permissions = engine.getAssignedGroupPermission(getName(),
103: new ArrayList(), Permission.class);
104: roles = engine.getGroupRoles(getName(), new ArrayList(),
105: Role.class);
106: }
107:
108: public void toDom(Element holder) {
109: super .toDom(holder);
110: DOMUtils.toDom(permissions, "permissions", holder);
111: DOMUtils.toDom(roles, "roles", holder);
112: }
113:
114: /**
115: * @param className
116: * @param actionName
117: * @return True if permission for given class and action is granted by this permission or permissions
118: * implied by this permission.
119: */
120: public Boolean isGranted(String className, String actionName) {
121: Iterator it = permissions.iterator();
122: while (it.hasNext()) {
123: Boolean ret = ((Permission) it.next()).isGranted(className,
124: actionName);
125: if (ret != null) {
126: return ret;
127: }
128: }
129:
130: it = roles.iterator();
131: while (it.hasNext()) {
132: Boolean ret = ((Role) it.next()).isGranted(className,
133: actionName);
134: if (ret != null) {
135: return ret;
136: }
137: }
138:
139: return null;
140: }
141:
142: }
|