KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > identity > sso > SAMLGenerationTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.security.identity.sso;
23
24 import org.jboss.security.identity.sso.AuthResponse;
25 import org.jboss.security.identity.sso.JBossSingleSignOnProcessor;
26 import org.jboss.security.identity.sso.SSOUser;
27 import org.jboss.security.identity.sso.SingleSignOnProcessor;
28 import org.jboss.test.JBossTestCase;
29
30 //$Id: SAMLGenerationTestCase.java 43631 2006-04-11 17:02:48Z asaldhana $
31

32 /**
33  * Tests generation of saml by the thin library in the security module
34  * based on opensaml
35  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
36  * @author <a HREF="mailto:Sohil.Shah@jboss.org">Sohil Shah</a>
37  * @since Apr 10, 2006
38  * @version $Revision: 43631 $
39  */

40 public class SAMLGenerationTestCase extends JBossTestCase
41 {
42    /**
43     * Better to be injected rather than a static class
44     */

45    private SingleSignOnProcessor processor = null;
46    
47    private static final String JavaDoc USERNAME = "saml_user";
48    private static final String JavaDoc PASSWORD = "saml_pwd";
49    private static final String JavaDoc ASSERTING_PARTY = "jboss";
50    
51    public SAMLGenerationTestCase(String JavaDoc name)
52    {
53       super(name);
54    }
55    
56    protected void setUp()
57    {
58       processor = new JBossSingleSignOnProcessor();
59    }
60    
61    protected void tearDown()
62    {
63       processor = null;
64    }
65    
66    public void testRequestGeneration() throws Exception JavaDoc
67    {
68       assertNotNull("processor != null");
69       String JavaDoc request = processor.generateAuthRequest(USERNAME, PASSWORD);
70       assertNotNull("request != null", request);
71       SSOUser user = processor.parseAuthRequest(request);
72       assertNotNull("user != null", user);
73       assertTrue("user ==" + USERNAME, user.getUserName().equals(USERNAME));
74       assertTrue("pwd ==" + PASSWORD, user.getPassword().equals(PASSWORD));
75    }
76    
77    public void testResponseGeneration() throws Exception JavaDoc
78    {
79       assertNotNull("processor != null");
80       String JavaDoc response = processor.generateAuthResponse(ASSERTING_PARTY,USERNAME, true);
81       assertNotNull("response != null", response);
82       AuthResponse authResponse = processor.parseAuthResponse(response);
83       assertNotNull("authResponse != null", authResponse);
84       assertTrue("AP ==" + ASSERTING_PARTY,
85             authResponse.getAssertingParty().equals(ASSERTING_PARTY));
86       assertTrue(" USERNAME==" + USERNAME,
87             authResponse.getUser().getUserName().equals(USERNAME));
88       assertNotNull("Asserting token != null", authResponse.getAssertToken());
89       assertTrue("authenticated?", authResponse.isAuthenticated());
90    }
91 }
92
Popular Tags