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