1 22 package org.jboss.test.webservice.jbws309; 23 24 import java.io.File ; 25 import java.rmi.RemoteException ; 26 27 import javax.naming.InitialContext ; 28 import javax.xml.namespace.QName ; 29 import javax.xml.rpc.Call ; 30 import javax.xml.rpc.Service ; 31 import javax.xml.rpc.ServiceFactory ; 32 import javax.xml.rpc.Stub ; 33 34 import junit.framework.Test; 35 36 import org.jboss.security.SecurityAssociation; 37 import org.jboss.security.SimplePrincipal; 38 import org.jboss.test.webservice.WebserviceTestBase; 39 40 51 public class JBWS309TestCase extends WebserviceTestBase 52 { 53 private static final String nsURI = "http://org.jboss.test.webservice/jbws309"; 54 private static final String USERNAME = "kermit"; 55 private static final String PASSWORD = "thefrog"; 56 57 public JBWS309TestCase(String name) 58 { 59 super(name); 60 } 61 62 63 public static Test suite() throws Exception 64 { 65 return getDeploySetup(JBWS309TestCase.class, "ws4ee-jbws309.jar, ws4ee-jbws309-client.jar"); 66 } 67 68 protected void setUp() throws Exception 69 { 70 super.setUp(); 71 SecurityAssociation.setPrincipal(null); 72 SecurityAssociation.setCredential(null); 73 } 74 75 77 public void testRoleSecuredSLSB() throws Exception 78 { 79 InitialContext iniCtx = getClientContext(); 80 OrganizationHome home = (OrganizationHome)iniCtx.lookup("ejb/RoleSecuredSLSB"); 81 82 OrganizationRemote bean = null; 83 try 84 { 85 bean = home.create(); 86 fail("Security exception expected"); 87 } 88 catch (Exception e) 89 { 90 SecurityAssociation.setPrincipal(new SimplePrincipal(USERNAME)); 92 SecurityAssociation.setCredential(PASSWORD); 93 bean = home.create(); 94 } 95 96 String info = bean.getContactInfo("mafia"); 97 assertEquals("The 'mafia' boss is currently out of office, please call again.", info); 98 } 99 100 102 public void testBasicSecuredSLSB() throws Exception 103 { 104 InitialContext iniCtx = getClientContext(); 105 OrganizationHome home = (OrganizationHome)iniCtx.lookup("ejb/BasicSecuredSLSB"); 106 107 OrganizationRemote bean = home.create(); 108 String info = bean.getContactInfo("mafia"); 109 assertEquals("The 'mafia' boss is currently out of office, please call again.", info); 110 } 111 112 public void testBasicSecuredServiceAccess() throws Exception 113 { 114 InitialContext iniCtx = getClientContext(); 115 Service service = (Service )iniCtx.lookup("java:comp/env/service/BasicSecured"); 116 Organization endpoint = (Organization)service.getPort(new QName (nsURI, "BasicSecuredPort"), Organization.class); 117 118 try 119 { 120 endpoint.getContactInfo("mafia"); 121 fail("Security exception expected"); 122 } 123 catch (RemoteException ignore) 124 { 125 } 127 128 Stub stub = (Stub )endpoint; 129 stub._setProperty(Stub.USERNAME_PROPERTY, USERNAME); 130 stub._setProperty(Stub.PASSWORD_PROPERTY, PASSWORD); 131 132 String info = endpoint.getContactInfo("mafia"); 133 assertEquals("The 'mafia' boss is currently out of office, please call again.", info); 134 } 135 136 141 public void testBasicSecuredDIIAccess() throws Exception 142 { 143 String targetAddress = "http://" + getServerHost() + ":8080/ws4ee-jbws309/BasicSecured"; 144 145 File wsdlFile = new File ("resources/webservice/jbws309/META-INF/wsdl/OrganizationService.wsdl"); 146 assertTrue("wsdl file exists", wsdlFile.exists()); 147 148 ServiceFactory factory = ServiceFactory.newInstance(); 149 Service service = factory.createService(wsdlFile.toURL(), new QName (nsURI, "OrganizationService")); 150 Call call = service.createCall(new QName (nsURI, "BasicSecuredPort"), "getContactInfo"); 151 call.setTargetEndpointAddress(targetAddress); 152 153 try 154 { 155 call.invoke(new Object [] { "mafia" }); 156 fail("Security exception expected"); 157 } 158 catch (RemoteException ignore) 159 { 160 } 162 163 call.setProperty(Stub.USERNAME_PROPERTY, USERNAME); 164 call.setProperty(Stub.PASSWORD_PROPERTY, PASSWORD); 165 166 Object retObj = call.invoke(new Object [] { "mafia" }); 167 assertEquals("The 'mafia' boss is currently out of office, please call again.", retObj); 168 } 169 170 public void testRoleSecuredServiceAccess() throws Exception 171 { 172 InitialContext iniCtx = getClientContext(); 173 Service service = (Service )iniCtx.lookup("java:comp/env/service/RoleSecured"); 174 Organization endpoint = (Organization)service.getPort(new QName (nsURI, "RoleSecuredPort"), Organization.class); 175 176 try 177 { 178 endpoint.getContactInfo("mafia"); 179 fail("Security exception expected"); 180 } 181 catch (RemoteException ignore) 182 { 183 } 185 186 Stub stub = (Stub )endpoint; 187 stub._setProperty(Stub.USERNAME_PROPERTY, USERNAME); 188 stub._setProperty(Stub.PASSWORD_PROPERTY, PASSWORD); 189 190 String info = endpoint.getContactInfo("mafia"); 191 assertEquals("The 'mafia' boss is currently out of office, please call again.", info); 192 } 193 } 194 | Popular Tags |