1 7 8 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 ; 16 import javax.xml.rpc.Stub ; 17 import java.net.URL ; 18 19 26 public class SecurityUnitTestCase extends JBossNetTestBase 27 { 28 private QName AUTHENTICATION_SERVICE = new QName ("http://" + getServerHost() + ":8080/jboss-net/services/Authentication", "AuthenticationService"); 29 private QName AUTHORIZATION_SERVICE = new QName ("http://" + getServerHost() + ":8080/jboss-net/services/Authorization", "AuthorizationService"); 30 31 public SecurityUnitTestCase(String name) 33 { 34 super(name); 35 } 36 37 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 46 public void setUp() throws Exception 47 { 48 super.setUp(); 49 URL wsdlAuthentication = new URL (SERVICES_LOCATION + "/Authentication?wsdl"); 50 URL wsdlAuthorization = new URL (SERVICES_LOCATION + "/Authorization?wsdl"); 51 52 jduke_authentication = (Authentication)createService(wsdlAuthentication, AUTHENTICATION_SERVICE).getPort(Authentication.class); 53 ((Stub )jduke_authentication)._setProperty(Stub.USERNAME_PROPERTY, "jduke"); 54 ((Stub )jduke_authentication)._setProperty(Stub.PASSWORD_PROPERTY, "theduke"); 55 56 jduke_authorization = (Authorization)createService(wsdlAuthorization, AUTHORIZATION_SERVICE).getPort(Authorization.class); 57 ((Stub )jduke_authorization)._setProperty(Stub.USERNAME_PROPERTY, "jduke"); 58 ((Stub )jduke_authorization)._setProperty(Stub.PASSWORD_PROPERTY, "theduke"); 59 60 jdukeman_authentication = (Authentication)createService(wsdlAuthentication, AUTHENTICATION_SERVICE).getPort(Authentication.class); 61 ((Stub )jdukeman_authentication)._setProperty(Stub.USERNAME_PROPERTY, "jdukeman"); 62 ((Stub )jdukeman_authentication)._setProperty(Stub.PASSWORD_PROPERTY, "anotherduke"); 63 64 jdukeman_authorization = (Authorization)createService(wsdlAuthorization, AUTHORIZATION_SERVICE).getPort(Authorization.class); 65 ((Stub )jdukeman_authorization)._setProperty(Stub.USERNAME_PROPERTY, "jdukeman"); 66 ((Stub )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 73 public void testAuthentication() throws Exception 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 e) 83 { 84 } 85 } 86 87 88 public void testAuthorization() throws Exception 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 e) 97 { 98 } 99 } 100 101 public static Test suite() throws Exception 102 { 103 return getDeploySetup(SecurityUnitTestCase.class, "jbossnet-security.ear"); 104 } 105 106 public static void main(String [] args) 107 { 108 junit.textui.TestRunner.run(SecurityUnitTestCase.class); 109 } 110 111 } | Popular Tags |