KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossnet > security > SecurityUnitTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 // $Id: SecurityUnitTestCase.java,v 1.1.1.1.6.6 2005/03/04 21:59:39 tdiesler Exp $
9

10 package org.jboss.test.jbossnet.security;
11
12 import junit.framework.Test;
13 import org.jboss.test.jbossnet.JBossNetTestBase;
14
15 import javax.xml.namespace.QName JavaDoc;
16 import javax.xml.rpc.Stub JavaDoc;
17 import java.net.URL JavaDoc;
18
19 /**
20  * Tests security issues of web services
21  * @since 5. Oktober 2001, 12:11
22  * @author <a HREF="mailto:Christoph.Jung@infor.de">Christoph G. Jung</a>
23  * @author Thomas.Diesler@jboss.org
24  * @version $Revision: 1.1.1.1.6.6 $
25  */

26 public class SecurityUnitTestCase extends JBossNetTestBase
27 {
28    private QName JavaDoc AUTHENTICATION_SERVICE = new QName JavaDoc("http://" + getServerHost() + ":8080/jboss-net/services/Authentication", "AuthenticationService");
29    private QName JavaDoc AUTHORIZATION_SERVICE = new QName JavaDoc("http://" + getServerHost() + ":8080/jboss-net/services/Authorization", "AuthorizationService");
30
31    // Constructors --------------------------------------------------
32
public SecurityUnitTestCase(String JavaDoc name)
33    {
34       super(name);
35    }
36
37    /** the session bean with which we interact */
38    Authentication jduke_authentication;
39    Authentication jdukeman_authentication;
40    Authorization jduke_authorization;
41    Authorization jdukeman_authorization;
42    Authorization not_authorized;
43    Authentication not_authenticated;
44
45    /** setup the bean */
46    public void setUp() throws Exception JavaDoc
47    {
48       super.setUp();
49       URL JavaDoc wsdlAuthentication = new URL JavaDoc(SERVICES_LOCATION + "/Authentication?wsdl");
50       URL JavaDoc wsdlAuthorization = new URL JavaDoc(SERVICES_LOCATION + "/Authorization?wsdl");
51
52       jduke_authentication = (Authentication)createService(wsdlAuthentication, AUTHENTICATION_SERVICE).getPort(Authentication.class);
53       ((Stub JavaDoc)jduke_authentication)._setProperty(Stub.USERNAME_PROPERTY, "jduke");
54       ((Stub JavaDoc)jduke_authentication)._setProperty(Stub.PASSWORD_PROPERTY, "theduke");
55
56       jduke_authorization = (Authorization)createService(wsdlAuthorization, AUTHORIZATION_SERVICE).getPort(Authorization.class);
57       ((Stub JavaDoc)jduke_authorization)._setProperty(Stub.USERNAME_PROPERTY, "jduke");
58       ((Stub JavaDoc)jduke_authorization)._setProperty(Stub.PASSWORD_PROPERTY, "theduke");
59
60       jdukeman_authentication = (Authentication)createService(wsdlAuthentication, AUTHENTICATION_SERVICE).getPort(Authentication.class);
61       ((Stub JavaDoc)jdukeman_authentication)._setProperty(Stub.USERNAME_PROPERTY, "jdukeman");
62       ((Stub JavaDoc)jdukeman_authentication)._setProperty(Stub.PASSWORD_PROPERTY, "anotherduke");
63
64       jdukeman_authorization = (Authorization)createService(wsdlAuthorization, AUTHORIZATION_SERVICE).getPort(Authorization.class);
65       ((Stub JavaDoc)jdukeman_authorization)._setProperty(Stub.USERNAME_PROPERTY, "jdukeman");
66       ((Stub JavaDoc)jdukeman_authorization)._setProperty(Stub.PASSWORD_PROPERTY, "anotherduke");
67
68       not_authenticated = (Authentication)(Authentication)createService(wsdlAuthentication, AUTHENTICATION_SERVICE).getPort(Authentication.class);
69       not_authorized = (Authorization)createService(wsdlAuthorization, AUTHORIZATION_SERVICE).getPort(Authorization.class);
70    }
71
72    /** test authentication effects */
73    public void testAuthentication() throws Exception JavaDoc
74    {
75       assertTrue("Correctly authenticated as role1, role2", jduke_authentication.workedOut());
76       assertTrue("Correctly authenticated as role3, role2", !jdukeman_authentication.workedOut());
77       try
78       {
79          not_authenticated.workedOut();
80          fail("Not authenticated user came through.");
81       }
82       catch (Exception JavaDoc e)
83       {
84       }
85    }
86
87    /** test authorization effects */
88    public void testAuthorization() throws Exception JavaDoc
89    {
90       assertTrue("Correctly authorized.", jduke_authorization.workedOut());
91       try
92       {
93          jdukeman_authorization.workedOut();
94          fail("Wrong authorization came through");
95       }
96       catch (Exception JavaDoc e)
97       {
98       }
99    }
100
101    public static Test suite() throws Exception JavaDoc
102    {
103       return getDeploySetup(SecurityUnitTestCase.class, "jbossnet-security.ear");
104    }
105
106    public static void main(String JavaDoc[] args)
107    {
108       junit.textui.TestRunner.run(SecurityUnitTestCase.class);
109    }
110
111 }
Popular Tags