001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package de.schlund.pfixxml.config.impl;
020:
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: import org.xml.sax.Attributes;
025:
026: import de.schlund.pfixcore.auth.AuthConstraintImpl;
027:
028: /**
029: * @author mleidig@schlund.de
030: */
031: public class AuthConstraintRule extends CheckedRule {
032:
033: private ContextXMLServletConfigImpl config;
034: private boolean topLevel;
035:
036: public AuthConstraintRule(ContextXMLServletConfigImpl config,
037: boolean topLevel) {
038: this .config = config;
039: this .topLevel = topLevel;
040: }
041:
042: public void begin(String namespace, String name,
043: Attributes attributes) throws Exception {
044: try {
045: check(namespace, name, attributes);
046: AuthConstraintImpl constraint = null;
047: if (topLevel) {
048: String constraintId = attributes.getValue("id");
049: if (constraintId == null)
050: throw new Exception(
051: "Top-level element 'authconstraint' requires attribute 'id'");
052: constraint = new AuthConstraintImpl();
053: getDigester().push(constraint);
054: config.getContextConfig().addAuthConstraint(
055: constraintId, constraint);
056: String defStr = attributes.getValue("default");
057: if (defStr != null) {
058: boolean def = Boolean.valueOf(defStr);
059: if (def)
060: config.getContextConfig()
061: .setDefaultAuthConstraint(constraint);
062: }
063: } else {
064: Object obj = getDigester().peek();
065: String constraintRef = attributes.getValue("ref");
066: if (constraintRef != null) {
067: constraint = (AuthConstraintImpl) config
068: .getContextConfig().getAuthConstraint(
069: constraintRef);
070: if (constraint == null)
071: throw new Exception(
072: "Referenced 'authconstraint' element can't be found: "
073: + constraintRef);
074: } else {
075: constraint = new AuthConstraintImpl();
076: }
077: getDigester().push(constraint);
078: if (obj instanceof PageRequestConfigImpl) {
079: ((PageRequestConfigImpl) obj)
080: .setAuthConstraint(constraint);
081: } else
082: throw new Exception(
083: "Element 'authconstraint' isn't 'pagerequest' child: "
084: + obj.getClass().getName());
085: }
086: String authPage = attributes.getValue("authpage");
087: if (authPage != null)
088: constraint.setAuthPage(authPage);
089: } catch (Exception x) {
090: x.printStackTrace();
091: throw x;
092: }
093: }
094:
095: public void end(String namespace, String name) throws Exception {
096: getDigester().pop();
097: }
098:
099: protected Map<String, Boolean> wantsAttributes() {
100: HashMap<String, Boolean> atts = new HashMap<String, Boolean>();
101: if (topLevel) {
102: atts.put("id", true);
103: atts.put("default", false);
104: } else
105: atts.put("ref", false);
106: atts.put("authpage", false);
107: return atts;
108: }
109:
110: }
|