001: //$HeadURL$
002: /*---------------- FILE HEADER ------------------------------------------
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: Contact:
022:
023: Andreas Poth
024: lat/lon GmbH
025: Aennchenstr. 19
026: 53177 Bonn
027: Germany
028: E-Mail: poth@lat-lon.de
029:
030: Prof. Dr. Klaus Greve
031: Department of Geography
032: University of Bonn
033: Meckenheimer Allee 166
034: 53115 Bonn
035: Germany
036: E-Mail: greve@giub.uni-bonn.de
037: ---------------------------------------------------------------------------*/
038:
039: package org.deegree.security;
040:
041: import java.io.File;
042: import java.io.IOException;
043: import java.io.Reader;
044: import java.lang.reflect.Constructor;
045: import java.net.MalformedURLException;
046: import java.net.URL;
047: import java.util.ArrayList;
048: import java.util.HashMap;
049: import java.util.List;
050: import java.util.Map;
051:
052: import org.deegree.datatypes.QualifiedName;
053: import org.deegree.datatypes.parameter.InvalidParameterValueException;
054: import org.deegree.framework.xml.NamespaceContext;
055: import org.deegree.framework.xml.XMLFragment;
056: import org.deegree.framework.xml.XMLParsingException;
057: import org.deegree.framework.xml.XMLTools;
058: import org.deegree.ogcbase.CommonNamespaces;
059: import org.w3c.dom.Document;
060: import org.w3c.dom.Element;
061: import org.w3c.dom.Node;
062: import org.xml.sax.SAXException;
063:
064: /**
065: *
066: *
067: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
068: * @author last edited by: $Author: poth $
069: *
070: * @version $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
071: */
072: public class AuthenticationDocument extends XMLFragment {
073:
074: private static final long serialVersionUID = 9122355584178027980L;
075:
076: private static NamespaceContext nsc = CommonNamespaces
077: .getNamespaceContext();
078:
079: /**
080: *
081: *
082: */
083: public AuthenticationDocument() {
084: super ();
085: }
086:
087: /**
088: *
089: * @param doc
090: * @param systemId
091: * @throws MalformedURLException
092: */
093: public AuthenticationDocument(Document doc, String systemId)
094: throws MalformedURLException {
095: super (doc, systemId);
096: }
097:
098: /**
099: *
100: * @param element
101: */
102: public AuthenticationDocument(Element element) {
103: super (element);
104: }
105:
106: /**
107: *
108: * @param file
109: * @throws MalformedURLException
110: * @throws IOException
111: * @throws SAXException
112: */
113: public AuthenticationDocument(File file)
114: throws MalformedURLException, IOException, SAXException {
115: super (file);
116: }
117:
118: /**
119: *
120: * @param elementName
121: */
122: public AuthenticationDocument(QualifiedName elementName) {
123: super (elementName);
124: }
125:
126: /**
127: *
128: * @param reader
129: * @param systemId
130: * @throws SAXException
131: * @throws IOException
132: */
133: public AuthenticationDocument(Reader reader, String systemId)
134: throws SAXException, IOException {
135: super (reader, systemId);
136: }
137:
138: /**
139: *
140: * @param url
141: * @throws IOException
142: * @throws SAXException
143: */
144: public AuthenticationDocument(URL url) throws IOException,
145: SAXException {
146: super (url);
147: }
148:
149: /**
150: * parses the authentications document and returns the content as an
151: * instance of {@link Authentications}
152: * @return new Authentications object
153: * @throws XMLParsingException
154: */
155: public Authentications createAuthentications()
156: throws XMLParsingException {
157:
158: List<Node> methodNodes = XMLTools.getNodes(getRootElement(),
159: "//Method", nsc);
160: List<AbstractAuthentication> authentications = new ArrayList<AbstractAuthentication>();
161: for (Node node : methodNodes) {
162: String name = XMLTools.getRequiredNodeAsString(node,
163: "./@name", nsc);
164: String className = XMLTools.getRequiredNodeAsString(node,
165: "./class/text()", nsc);
166:
167: // parameter type for map of init-params and authentication name
168: Class[] cl = new Class[2];
169: cl[0] = String.class;
170: cl[1] = Map.class;
171:
172: // set parameter to submitt to the constructor
173: Object[] o = new Object[2];
174: o[0] = name;
175: o[1] = createInitParams(node);
176:
177: try {
178: Class clzz = Class.forName(className);
179: Constructor con = clzz.getConstructor(cl);
180: authentications.add((AbstractAuthentication) con
181: .newInstance(o));
182: } catch (Exception e) {
183: throw new InvalidParameterValueException(
184: e.getMessage(), "class", className);
185: }
186: }
187: return new Authentications(authentications);
188: }
189:
190: /**
191: *
192: * @param methodNode
193: * @return
194: * @throws XMLParsingException
195: */
196: private Map<String, String> createInitParams(Node methodNode)
197: throws XMLParsingException {
198: List<Node> nodes = XMLTools.getNodes(methodNode,
199: "./init-param", nsc);
200: Map<String, String> map = new HashMap<String, String>();
201: for (Node node : nodes) {
202: String name = XMLTools.getRequiredNodeAsString(node,
203: "./name/text()", nsc);
204: String value = XMLTools.getRequiredNodeAsString(node,
205: "./value/text()", nsc);
206: map.put(name, value);
207: }
208: return map;
209: }
210:
211: }
|