65cbfba05fdcf2bec1f09c63fee38566192d8fe2
[java-idp.git] / tests / edu / internet2 / middleware / shibboleth / hs / provider / NameMapperTests.java
1 /*
2  * The Shibboleth License, Version 1. Copyright (c) 2002 University Corporation for Advanced Internet Development, Inc.
3  * All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted
4  * provided that the following conditions are met: Redistributions of source code must retain the above copyright
5  * notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above
6  * copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials
7  * provided with the distribution, if any, must include the following acknowledgment: "This product includes software
8  * developed by the University Corporation for Advanced Internet Development <http://www.ucaid.edu> Internet2 Project.
9  * Alternately, this acknowledegement may appear in the software itself, if and wherever such third-party
10  * acknowledgments normally appear. Neither the name of Shibboleth nor the names of its contributors, nor Internet2, nor
11  * the University Corporation for Advanced Internet Development, Inc., nor UCAID may be used to endorse or promote
12  * products derived from this software without specific prior written permission. For written permission, please contact
13  * shibboleth@shibboleth.org Products derived from this software may not be called Shibboleth, Internet2, UCAID, or the
14  * University Corporation for Advanced Internet Development, nor may Shibboleth appear in their name, without prior
15  * written permission of the University Corporation for Advanced Internet Development. THIS SOFTWARE IS PROVIDED BY THE
16  * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE
18  * DISCLAIMED AND THE ENTIRE RISK OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE. IN NO
19  * EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC.
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 package edu.internet2.middleware.shibboleth.hs.provider;
27
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.FileNotFoundException;
31 import java.io.InputStream;
32 import java.io.StringReader;
33 import java.net.MalformedURLException;
34
35 import junit.framework.TestCase;
36
37 import org.apache.log4j.BasicConfigurator;
38 import org.apache.log4j.Level;
39 import org.apache.log4j.Logger;
40 import org.opensaml.SAMLNameIdentifier;
41 import org.xml.sax.EntityResolver;
42 import org.xml.sax.ErrorHandler;
43 import org.xml.sax.InputSource;
44 import org.xml.sax.SAXException;
45 import org.xml.sax.SAXParseException;
46
47 import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
48 import edu.internet2.middleware.shibboleth.common.Credential;
49 import edu.internet2.middleware.shibboleth.common.IdentityProvider;
50 import edu.internet2.middleware.shibboleth.common.NameIdentifierMapping;
51 import edu.internet2.middleware.shibboleth.common.NameIdentifierMappingException;
52 import edu.internet2.middleware.shibboleth.common.NameMapper;
53 import edu.internet2.middleware.shibboleth.common.ServiceProvider;
54 import edu.internet2.middleware.shibboleth.xml.Parser;
55
56
57
58 /**
59  * Validation suite for the <code>NameMapper</code>.
60  * 
61  * @author Walter Hoehn(wassa@columbia.edu)
62  */
63
64 public class NameMapperTests extends TestCase {
65
66         private Parser.DOMParser parser = new Parser.DOMParser(true);
67
68         public NameMapperTests(String name) {
69
70                 super(name);
71                 BasicConfigurator.resetConfiguration();
72                 BasicConfigurator.configure();
73                 Logger.getRootLogger().setLevel(Level.DEBUG);
74         }
75
76         public static void main(String[] args) {
77
78                 junit.textui.TestRunner.run(NameMapperTests.class);
79                 BasicConfigurator.configure();
80                 Logger.getRootLogger().setLevel(Level.DEBUG);
81         }
82
83         protected void setUp() throws Exception {
84
85                 super.setUp();
86
87         }
88
89         public void testCryptoMapping() {
90
91                 try {
92
93                         NameMapper nameMapper = new NameMapper();
94
95                         File file = new File("data/handle.jks");
96
97                         String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
98                                         + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
99                                         + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
100                                         + "             xsi:schemaLocation=\"urn:mace:shibboleth:namemapper:1.0 namemapper.xsd\" "
101                                         + "                     id=\"cryptotest\" format=\"urn:mace:shibboleth:1.0:nameIdentifier\" "
102                                         + "                     type=\"CryptoHandleGenerator\" handleTTL=\"1800\">" 
103                                         + "             <KeyStorePath>" + file.toURL().toString() + "</KeyStorePath>" 
104                                         + "             <KeyStorePassword>shibhs</KeyStorePassword>"
105                                         + "             <KeyStoreKeyAlias>handlekey</KeyStoreKeyAlias>"
106                                         + "             <KeyStoreKeyPassword>shibhs</KeyStoreKeyPassword>" 
107                                         + "     </NameMapping>";
108
109                         parser.parse(new InputSource(new StringReader(rawConfig)));
110                         nameMapper.addNameMapping(parser.getDocument().getDocumentElement());
111
112                         SAMLNameIdentifier nameId = nameMapper.getNameIdentifierName("cryptotest", new AuthNPrincipal(
113                                         "testprincipal"), new BasicServiceProvider(), new BasicIdentityProvider("urn-x:testid"));
114
115                         AuthNPrincipal principal = nameMapper.getPrincipal(nameId, new BasicServiceProvider(),
116                                         new BasicIdentityProvider("urn-x:testid"));
117                         assertEquals("Round-trip handle validation failed.", principal.getName(), "testprincipal");
118
119                 } catch (MalformedURLException e) {
120                         fail("Error in test specification: " + e.getMessage());
121                 } catch (NameIdentifierMappingException e) {
122                         fail("Error exercising NameMaper: " + e.getMessage());
123                 } catch (Exception e) {
124                         fail("Error exercising NameMaper: " + e.getMessage());
125                 }
126
127         }
128
129         public void testCryptoMappingWithOverriddenAlgorithms() {
130
131                 try {
132
133                         NameMapper nameMapper = new NameMapper();
134
135                         File file = new File("data/handle.jks");
136
137                         String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
138                                         + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
139                                         + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
140                                         + "             xsi:schemaLocation=\"urn:mace:shibboleth:namemapper:1.0 namemapper.xsd\" "
141                                         + "                     id=\"cryptotest\" format=\"urn:mace:shibboleth:1.0:nameIdentifier\" "
142                                         + "                     type=\"CryptoHandleGenerator\" handleTTL=\"1800\">" 
143                                         + "             <KeyStorePath>"+ file.toURL().toString() + "</KeyStorePath>" 
144                                         + "             <KeyStorePassword>shibhs</KeyStorePassword>"
145                                         + "             <KeyStoreKeyAlias>handlekey</KeyStoreKeyAlias>"
146                                         + "             <KeyStoreKeyPassword>shibhs</KeyStoreKeyPassword>"
147                                         + "             <Cipher>DESede/CBC/PKCS5Padding</Cipher>" 
148                                         + "             <MAC>HmacSHA1</MAC>"
149                                         + "             <KeyStoreType>JCEKS</KeyStoreType>" 
150                                         + "     </NameMapping>";
151
152                         parser.parse(new InputSource(new StringReader(rawConfig)));
153                         nameMapper.addNameMapping(parser.getDocument().getDocumentElement());
154
155                         SAMLNameIdentifier nameId = nameMapper.getNameIdentifierName("cryptotest", new AuthNPrincipal(
156                                         "testprincipal"), new BasicServiceProvider(), new BasicIdentityProvider("urn-x:testid"));
157
158                         AuthNPrincipal principal = nameMapper.getPrincipal(nameId, new BasicServiceProvider(),
159                                         new BasicIdentityProvider("urn-x:testid"));
160                         assertEquals("Round-trip handle validation failed.", principal.getName(), "testprincipal");
161
162                 } catch (MalformedURLException e) {
163                         fail("Error in test specification: " + e.getMessage());
164                 } catch (NameIdentifierMappingException e) {
165                         fail("Error exercising NameMaper: " + e.getMessage());
166                 } catch (Exception e) {
167                         fail("Error exercising NameMaper: " + e.getMessage());
168                 }
169
170         }
171         
172         public void testCryptoMappingBadQualifier() {
173
174                 try {
175
176                         NameMapper nameMapper = new NameMapper();
177
178                         File file = new File("data/handle.jks");
179
180                         String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
181                                         + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
182                                         + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
183                                         + "             xsi:schemaLocation=\"urn:mace:shibboleth:namemapper:1.0 namemapper.xsd\" "
184                                         + "                     id=\"cryptotest\" format=\"urn:mace:shibboleth:1.0:nameIdentifier\" "
185                                         + "                     type=\"CryptoHandleGenerator\" handleTTL=\"1800\">" 
186                                         + "             <KeyStorePath>" + file.toURL().toString() + "</KeyStorePath>" 
187                                         + "             <KeyStorePassword>shibhs</KeyStorePassword>"
188                                         + "             <KeyStoreKeyAlias>handlekey</KeyStoreKeyAlias>"
189                                         + "             <KeyStoreKeyPassword>shibhs</KeyStoreKeyPassword>" 
190                                         + "     </NameMapping>";
191
192                         parser.parse(new InputSource(new StringReader(rawConfig)));
193                         nameMapper.addNameMapping(parser.getDocument().getDocumentElement());
194
195                         SAMLNameIdentifier nameId = nameMapper.getNameIdentifierName("cryptotest", new AuthNPrincipal(
196                                         "testprincipal"), new BasicServiceProvider(), new BasicIdentityProvider("urn-x:good"));
197
198                         AuthNPrincipal principal = nameMapper.getPrincipal(nameId, new BasicServiceProvider(),
199                                         new BasicIdentityProvider("urn-x:bad"));
200                 
201                         fail("Expected failure for bad name qualifier.");
202                         
203                 } catch (NameIdentifierMappingException e) {
204                         //This exception should be generated by this test
205                         
206                 } catch (MalformedURLException e) {
207                         fail("Error in test specification: " + e.getMessage());
208                 
209                 } catch (Exception e) {
210                         fail("Error exercising NameMaper: " + e.getMessage());
211                 }
212
213         }
214
215         public void testDefaultConfig() {
216
217                 try {
218
219                         NameMapper nameMapper = new NameMapper();
220
221                         SAMLNameIdentifier nameId = nameMapper.getNameIdentifierName(null, new AuthNPrincipal("testprincipal"),
222                                         new BasicServiceProvider(), new BasicIdentityProvider("urn-x:testid"));
223
224                         AuthNPrincipal principal = nameMapper.getPrincipal(nameId, new BasicServiceProvider(),
225                                         new BasicIdentityProvider("urn-x:testid"));
226
227                         assertEquals("Round-trip handle validation failed.", principal.getName(), "testprincipal");
228
229                 } catch (NameIdentifierMappingException e) {
230                         fail("Error exercising NameMaper: " + e.getMessage());
231                 } catch (Exception e) {
232                         fail("Error exercising NameMaper: " + e.getMessage());
233                 }
234         }
235
236         public void testDefaultingId() {
237
238                 try {
239
240                         NameMapper nameMapper = new NameMapper();
241
242                         File file = new File("data/handle.jks");
243
244                         String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
245                                         + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
246                                         + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
247                                         + "             xsi:schemaLocation=\"urn:mace:shibboleth:namemapper:1.0 namemapper.xsd\" "
248                                         + "                     format=\"urn:mace:shibboleth:1.0:nameIdentifier\""
249                                         + "             type=\"CryptoHandleGenerator\" handleTTL=\"1800\">" 
250                                         + "             <KeyStorePath>" + file.toURL().toString() + "</KeyStorePath>" 
251                                         + "             <KeyStorePassword>shibhs</KeyStorePassword>"
252                                         + "             <KeyStoreKeyAlias>handlekey</KeyStoreKeyAlias>"
253                                         + "             <KeyStoreKeyPassword>shibhs</KeyStoreKeyPassword>" 
254                                         + "     </NameMapping>";
255
256                         parser.parse(new InputSource(new StringReader(rawConfig)));
257                         nameMapper.addNameMapping(parser.getDocument().getDocumentElement());
258
259                         SAMLNameIdentifier nameId = nameMapper.getNameIdentifierName(null, new AuthNPrincipal("testprincipal"),
260                                         new BasicServiceProvider(), new BasicIdentityProvider("urn-x:testid"));
261
262                         AuthNPrincipal principal = nameMapper.getPrincipal(nameId, new BasicServiceProvider(),
263                                         new BasicIdentityProvider("urn-x:testid"));
264
265                         assertEquals("Round-trip handle validation failed.", principal.getName(), "testprincipal");
266
267                         NameIdentifierMapping nameMapping = nameMapper.getNameIdentifierMappingById(null);
268                         if (!(nameMapping instanceof CryptoShibHandle)) {
269                                 fail("HSNameMapper defaulted to incorrect name mapping.");
270                         }
271
272                 } catch (NameIdentifierMappingException e) {
273                         fail("Error exercising NameMaper: " + e.getMessage());
274                 } catch (Exception e) {
275                         fail("Error exercising NameMaper: " + e.getMessage());
276                 }
277         }
278
279         public void testDefaultingAmbiguousId() {
280
281                 try {
282
283                         NameMapper nameMapper = new NameMapper();
284
285                         File file = new File("data/handle.jks");
286
287                         String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
288                                         + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
289                                         + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
290                                         + "             xsi:schemaLocation=\"urn:mace:shibboleth:namemapper:1.0 namemapper.xsd\" "
291                                         + "                     format=\"urn:mace:shibboleth:1.0:nameIdentifier\""
292                                         + "             type=\"CryptoHandleGenerator\" handleTTL=\"1800\">" 
293                                         + "             <KeyStorePath>" + file.toURL().toString() + "</KeyStorePath>" 
294                                         + "             <KeyStorePassword>shibhs</KeyStorePassword>"
295                                         + "             <KeyStoreKeyAlias>handlekey</KeyStoreKeyAlias>"
296                                         + "             <KeyStoreKeyPassword>shibhs</KeyStoreKeyPassword>" 
297                                         + "     </NameMapping>";
298
299                         parser.parse(new InputSource(new StringReader(rawConfig)));
300                         nameMapper.addNameMapping(parser.getDocument().getDocumentElement());
301
302                         String rawConfig2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
303                                         + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
304                                         + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
305                                         + "             xsi:schemaLocation=\"urn:mace:shibboleth:namemapper:1.0 namemapper.xsd\" "
306                                         + "                     format=\"urn-x:testNameIdentifier\"" 
307                                         + "             type=\"CryptoHandleGenerator\" handleTTL=\"1800\">"
308                                         + "             <KeyStorePath>" + file.toURL().toString() + "</KeyStorePath>"
309                                         + "             <KeyStorePassword>shibhs</KeyStorePassword>"
310                                         + "             <KeyStoreKeyAlias>handlekey</KeyStoreKeyAlias>"
311                                         + "             <KeyStoreKeyPassword>shibhs</KeyStoreKeyPassword>" 
312                                         + "     </NameMapping>";
313
314                         parser.parse(new InputSource(new StringReader(rawConfig2)));
315
316                         nameMapper.addNameMapping(parser.getDocument().getDocumentElement());
317
318                         nameMapper.getNameIdentifierName(null, new AuthNPrincipal("testprincipal"), new BasicServiceProvider(),
319                                         new BasicIdentityProvider("urn-x:testid"));
320
321                         fail("HSNameMapper defaulted to incorrect name mapping.");
322
323                         //This is only a failure if we don't get this exception
324                 } catch (NameIdentifierMappingException e) {
325
326                 } catch (Exception e) {
327
328                         fail("Error exercising NameMaper: " + e.getMessage());
329                 }
330         }
331
332         public void testMemoryMapping() {
333
334                 try {
335
336                         NameMapper nameMapper = new NameMapper();
337
338                         String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
339                                         + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
340                                         + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
341                                         + "             xsi:schemaLocation=\"urn:mace:shibboleth:namemapper:1.0 namemapper.xsd\" "
342                                         + "                     id=\"memorytest\" " 
343                                         + "             format=\"urn:mace:shibboleth:1.0:nameIdentifier\""
344                                         + "             type=\"SharedMemoryShibHandle\" handleTTL=\"1800\"/>";
345
346                         parser.parse(new InputSource(new StringReader(rawConfig)));
347                         nameMapper.addNameMapping(parser.getDocument().getDocumentElement());
348
349                         SAMLNameIdentifier nameId = nameMapper.getNameIdentifierName("memorytest", new AuthNPrincipal(
350                                         "testprincipal"), new BasicServiceProvider(), new BasicIdentityProvider("urn-x:testid"));
351
352                         AuthNPrincipal principal = nameMapper.getPrincipal(nameId, new BasicServiceProvider(),
353                                         new BasicIdentityProvider("urn-x:testid"));
354
355                         assertEquals("Round-trip handle validation failed.", principal.getName(), "testprincipal");
356
357                 } catch (MalformedURLException e) {
358                         fail("Error in test specification: " + e.getMessage());
359                 } catch (NameIdentifierMappingException e) {
360                         fail("Error exercising NameMaper: " + e.getMessage());
361                 } catch (Exception e) {
362                         fail("Error exercising NameMaper: " + e.getMessage());
363                 }
364         }
365         
366         public void testMemoryMappingBadQualifier() {
367
368                 try {
369
370                         NameMapper nameMapper = new NameMapper();
371
372                         String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
373                                         + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
374                                         + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
375                                         + "             xsi:schemaLocation=\"urn:mace:shibboleth:namemapper:1.0 namemapper.xsd\" "
376                                         + "                     id=\"memorytest\" " 
377                                         + "             format=\"urn:mace:shibboleth:1.0:nameIdentifier\""
378                                         + "             type=\"SharedMemoryShibHandle\" handleTTL=\"1800\"/>";
379
380                         parser.parse(new InputSource(new StringReader(rawConfig)));
381                         nameMapper.addNameMapping(parser.getDocument().getDocumentElement());
382
383                         SAMLNameIdentifier nameId = nameMapper.getNameIdentifierName("memory", new AuthNPrincipal(
384                                         "testprincipal"), new BasicServiceProvider(), new BasicIdentityProvider("urn-x:good"));
385
386                         AuthNPrincipal principal = nameMapper.getPrincipal(nameId, new BasicServiceProvider(),
387                                         new BasicIdentityProvider("urn-x:bad"));
388                 
389                         fail("Expected failure for bad name qualifier.");
390                         
391                 } catch (NameIdentifierMappingException e) {
392                         //This exception should be generated by this test
393                         
394                 } catch (MalformedURLException e) {
395                         fail("Error in test specification: " + e.getMessage());
396                 
397                 } catch (Exception e) {
398                         fail("Error exercising NameMaper: " + e.getMessage());
399                 }
400         }
401
402         public void testPrincipalMapping() {
403
404                 try {
405
406                         NameMapper nameMapper = new NameMapper();
407
408                         String format = "urn-x:test:NameIdFormat1";
409                         String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
410                                         + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
411                                         + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
412                                         + "             xsi:schemaLocation=\"urn:mace:shibboleth:namemapper:1.0 namemapper.xsd\" " 
413                                         + "                     format=\"" + format + "\"" + "          type=\"Principal\"/>";
414
415                         parser.parse(new InputSource(new StringReader(rawConfig)));
416                         nameMapper.addNameMapping(parser.getDocument().getDocumentElement());
417
418                         SAMLNameIdentifier nameId = new SAMLNameIdentifier("testprincipal", "urn-x:testid", format);
419                         AuthNPrincipal principal = nameMapper.getPrincipal(nameId, new BasicServiceProvider(),
420                                         new BasicIdentityProvider("urn-x:testid"));
421
422                         assertEquals("Round-trip handle validation failed.", principal.getName(), "testprincipal");
423
424                 } catch (MalformedURLException e) {
425                         fail("Error in test specification: " + e.getMessage());
426                 } catch (NameIdentifierMappingException e) {
427                         fail("Error exercising NameMaper: " + e.getMessage());
428                 } catch (Exception e) {
429                         fail("Error exercising NameMaper: " + e.getMessage());
430                 }
431
432         }
433         
434         public void testPrincipalMappingBadQualifier() {
435
436                 try {
437
438                         NameMapper nameMapper = new NameMapper();
439
440                         String format = "urn-x:test:NameIdFormat1";
441                         String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
442                                         + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
443                                         + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
444                                         + "             xsi:schemaLocation=\"urn:mace:shibboleth:namemapper:1.0 namemapper.xsd\" " 
445                                         + "                     format=\"" + format + "\"" + "          type=\"Principal\"/>";
446                         parser.parse(new InputSource(new StringReader(rawConfig)));
447                         nameMapper.addNameMapping(parser.getDocument().getDocumentElement());
448
449                         SAMLNameIdentifier nameId = new SAMLNameIdentifier("testprincipal", "urn-x:good", format);
450
451                         AuthNPrincipal principal = nameMapper.getPrincipal(nameId, new BasicServiceProvider(),
452                                         new BasicIdentityProvider("urn-x:bad"));
453                 
454                         fail("Expected failure for bad name qualifier.");
455                         
456                 } catch (NameIdentifierMappingException e) {
457                         //This exception should be generated by this test
458                         
459                 } catch (MalformedURLException e) {
460                         fail("Error in test specification: " + e.getMessage());
461                 
462                 } catch (Exception e) {
463                         fail("Error exercising NameMaper: " + e.getMessage());
464                 }
465
466         }
467 }
468
469 class BasicIdentityProvider implements IdentityProvider {
470
471         String id;
472
473         public BasicIdentityProvider(String id) {
474
475                 this.id = id;
476         }
477
478         public String getProviderId() {
479
480                 return id;
481         }
482
483         public Credential getResponseSigningCredential() {
484
485                 return null;
486         }
487
488         public Credential getAssertionSigningCredential() {
489
490                 return null;
491         }
492
493 }
494
495 class BasicServiceProvider implements ServiceProvider {
496
497         public String getProviderId() {
498
499                 return null;
500         }
501
502 }