001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wass/common/AuthenticationDocument.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2008 by: 006 EXSE, Department of Geography, University of Bonn 007 http://www.giub.uni-bonn.de/deegree/ 008 lat/lon GmbH 009 http://www.lat-lon.de 010 011 This library is free software; you can redistribute it and/or 012 modify it under the terms of the GNU Lesser General Public 013 License as published by the Free Software Foundation; either 014 version 2.1 of the License, or (at your option) any later version. 015 016 This library is distributed in the hope that it will be useful, 017 but WITHOUT ANY WARRANTY; without even the implied warranty of 018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 Lesser General Public License for more details. 020 021 You should have received a copy of the GNU Lesser General Public 022 License along with this library; if not, write to the Free Software 023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 024 025 Contact: 026 027 Andreas Poth 028 lat/lon GmbH 029 Aennchenstr. 19 030 53115 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Prof. Dr. Klaus Greve 035 Department of Geography 036 University of Bonn 037 Meckenheimer Allee 166 038 53115 Bonn 039 Germany 040 E-Mail: greve@giub.uni-bonn.de 041 042 043 ---------------------------------------------------------------------------*/ 044 045 package org.deegree.ogcwebservices.wass.common; 046 047 import java.net.MalformedURLException; 048 import java.net.URL; 049 import java.util.ArrayList; 050 import java.util.List; 051 052 import org.deegree.framework.xml.XMLFragment; 053 import org.deegree.framework.xml.XMLParsingException; 054 import org.deegree.framework.xml.XMLTools; 055 import org.deegree.ogcbase.CommonNamespaces; 056 import org.w3c.dom.Element; 057 import org.w3c.dom.Node; 058 059 /** 060 * Parser class that can parse all elements within the namespace. 061 * 062 * Namespace: http://www.gdi-nrw.de/authentication 063 * 064 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a> 065 * @author last edited by: $Author: apoth $ 066 * 067 * @version 2.0, $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $ 068 * 069 * @since 2.0 070 */ 071 public class AuthenticationDocument extends XMLFragment { 072 073 private static final long serialVersionUID = -6467874541905139362L; 074 075 private final static String PRE = CommonNamespaces.GDINRW_AUTH_PREFIX + ":"; 076 077 /** 078 * Parses a SupportedAuthenticationMethodList element. 079 * 080 * @param listRoot 081 * the list element 082 * @return an ArrayList with the parsed methods 083 * @throws MalformedURLException 084 * @throws XMLParsingException 085 */ 086 public ArrayList<SupportedAuthenticationMethod> parseSupportedAuthenticationMethodList( 087 Element listRoot ) 088 throws MalformedURLException, XMLParsingException { 089 090 List<Node> methods = XMLTools.getRequiredNodes( listRoot, PRE + "SupportedAuthenticationMethod", 091 nsContext ); 092 ArrayList<SupportedAuthenticationMethod> values = new ArrayList<SupportedAuthenticationMethod>(); 093 for ( Object element : methods ) { 094 values.add( parseSupportedAuthenticationMethod( (Element) element ) ); 095 } 096 097 return values; 098 } 099 100 /** 101 * Parses a SupportedAuthenticationMethod element. 102 * 103 * @param elem 104 * the element 105 * @return the parsed data 106 * @throws XMLParsingException 107 * @throws MalformedURLException 108 */ 109 public SupportedAuthenticationMethod parseSupportedAuthenticationMethod( Node elem ) 110 throws XMLParsingException, MalformedURLException { 111 112 Node method = XMLTools.getNode( elem, PRE + "AuthenticationMethod", nsContext ); 113 URN methodURN = parseAuthenticationMethod( method ); 114 Node metadata = XMLTools.getNode( elem, PRE + "WASAuthenticationMethodMD", nsContext ); 115 if ( metadata != null ) { 116 WASAuthenticationMethodMD wasamd = parseWASAuthenticationMethodMD( metadata ); 117 return new SupportedAuthenticationMethod( methodURN, wasamd ); 118 } 119 metadata = XMLTools.getNode( elem, PRE + "UnknownMethodMetadata", nsContext ); 120 String ummd = null; 121 if ( metadata != null ) 122 ummd = parseUnknownMethodMetadata( metadata ); 123 124 SupportedAuthenticationMethod result = new SupportedAuthenticationMethod( methodURN, ummd ); 125 126 return result; 127 } 128 129 /** 130 * Parses an AuthenticationMethod. 131 * 132 * @param elem 133 * the AuthenticationMethod element 134 * @return an URN with the method 135 * @throws XMLParsingException 136 */ 137 public URN parseAuthenticationMethod( Node elem ) 138 throws XMLParsingException { 139 return new URN( XMLTools.getNodeAsString( elem, "@id", nsContext, null ) ); 140 } 141 142 /** 143 * Parses an UnknownMethodMetadata element. 144 * 145 * @param elem 146 * the element 147 * @return a String with the data 148 * @throws XMLParsingException 149 */ 150 public String parseUnknownMethodMetadata( Node elem ) 151 throws XMLParsingException { 152 return XMLTools.getNodeAsString( elem, ".", nsContext, null ); 153 } 154 155 /** 156 * Parses a WASAuthenticationMethodMD element. 157 * 158 * @param elem 159 * the element 160 * @return an object with the parsed data 161 * @throws XMLParsingException 162 * @throws MalformedURLException 163 */ 164 public WASAuthenticationMethodMD parseWASAuthenticationMethodMD( Node elem ) 165 throws XMLParsingException, MalformedURLException { 166 167 String mdName = XMLTools.getRequiredNodeAsString( elem, PRE + "Name", nsContext ); 168 URL mdURL = XMLTools.getRequiredNodeAsURI( elem, PRE + "URL", nsContext ).toURL(); 169 ArrayList<URN> mdAuthenticationMethods = new ArrayList<URN>(); 170 String[] urns = XMLTools.getNodesAsStrings( elem, PRE + "AuthenticationMethod", nsContext ); 171 for ( int i = 0; i < urns.length; ++i ) 172 mdAuthenticationMethods.add( new URN( urns[i] ) ); 173 174 WASAuthenticationMethodMD result = new WASAuthenticationMethodMD( mdName, mdURL, 175 mdAuthenticationMethods ); 176 177 return result; 178 } 179 180 /** 181 * Parses an AuthenticationData element 182 * 183 * @param elem 184 * the element 185 * @return an object with the parsed data 186 * @throws XMLParsingException 187 */ 188 public AuthenticationData parseAuthenticationData( Node elem ) 189 throws XMLParsingException { 190 191 Node method = XMLTools.getRequiredNode( elem, PRE + "AuthenticationMethod", nsContext ); 192 URN authenticationMethod = parseAuthenticationMethod( method ); 193 Node cred = XMLTools.getRequiredNode( elem, PRE + "Credentials", nsContext ); 194 String credentials = parseCredentials( cred ); 195 196 AuthenticationData result = new AuthenticationData( authenticationMethod, credentials ); 197 198 return result; 199 } 200 201 /** 202 * Parses a Credentials element. 203 * 204 * @param elem 205 * the element 206 * @return a String containing the data 207 * @throws XMLParsingException 208 */ 209 public String parseCredentials( Node elem ) 210 throws XMLParsingException { 211 return XMLTools.getRequiredNodeAsString( elem, ".", nsContext ); 212 } 213 214 }