01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package de.schlund.pfixxml.config.impl;
20:
21: import java.util.HashMap;
22: import java.util.Map;
23:
24: import org.xml.sax.Attributes;
25:
26: import de.schlund.pfixcore.auth.AuthConstraint;
27: import de.schlund.pfixcore.auth.AuthConstraintImpl;
28: import de.schlund.pfixcore.auth.Condition;
29: import de.schlund.pfixcore.auth.Role;
30: import de.schlund.pfixcore.auth.conditions.And;
31: import de.schlund.pfixcore.auth.conditions.ConditionGroup;
32: import de.schlund.pfixcore.auth.conditions.HasRole;
33: import de.schlund.pfixcore.auth.conditions.Not;
34: import de.schlund.pfixcore.auth.conditions.Or;
35:
36: /**
37: * @author mleidig@schlund.de
38: */
39: public class ConditionRule extends CheckedRule {
40:
41: ContextXMLServletConfigImpl config;
42:
43: public ConditionRule(ContextXMLServletConfigImpl config) {
44: this .config = config;
45: }
46:
47: public void begin(String namespace, String name,
48: Attributes attributes) throws Exception {
49: check(namespace, name, attributes);
50: Condition condition = null;
51: if (name.equals("or")) {
52: condition = new Or();
53: } else if (name.equals("and")) {
54: condition = new And();
55: } else if (name.equals("not")) {
56: condition = new Not();
57: } else if (name.equals("hasrole")) {
58: String roleName = attributes.getValue("name");
59: condition = new HasRole(roleName);
60: Role role = config.getContextConfig().getRole(roleName);
61: if (role == null)
62: throw new Exception(
63: "Condition hasrole references unknown role: "
64: + roleName);
65: } else
66: throw new Exception("Unsupported condition: " + name);
67: Object obj = getDigester().peek();
68: if (obj instanceof AuthConstraint) {
69: ((AuthConstraintImpl) obj).setCondition(condition);
70: } else if (obj instanceof ConditionGroup) {
71: ((ConditionGroup) obj).add(condition);
72: } else if (obj instanceof Not) {
73: ((Not) obj).set(condition);
74: } else
75: throw new Exception("Illegal object: "
76: + obj.getClass().getName());
77: getDigester().push(condition);
78: }
79:
80: public void end(String namespace, String name) throws Exception {
81: getDigester().pop();
82: }
83:
84: protected Map<String, Boolean> wantsAttributes() {
85: HashMap<String, Boolean> atts = new HashMap<String, Boolean>();
86: atts.put("name", false);
87: return atts;
88: }
89:
90: }
|