1 22 package org.jboss.test.webservice.samples; 23 24 import junit.framework.Test; 25 import org.jboss.security.SecurityAssociation; 26 import org.jboss.security.SimplePrincipal; 27 import org.jboss.test.webservice.WebserviceTestBase; 28 29 import javax.naming.InitialContext ; 30 import javax.xml.namespace.QName ; 31 import javax.xml.rpc.Service ; 32 import javax.xml.rpc.Stub ; 33 import java.rmi.RemoteException ; 34 35 36 42 public class ServerSideEJBSecTestCase extends WebserviceTestBase 43 { 44 public static final String USERNAME = "kermit"; 45 public static final String PASSWORD = "thefrog"; 46 47 public ServerSideEJBSecTestCase(String name) 48 { 49 super(name); 50 } 51 52 53 public static Test suite() throws Exception 54 { 55 return getDeploySetup(ServerSideEJBSecTestCase.class, "ws4ee-samples-server-ejb-sec.jar, ws4ee-samples-server-ejb-sec-client.jar"); 56 } 57 58 protected void setUp() throws Exception 59 { 60 super.setUp(); 61 SecurityAssociation.setPrincipal(null); 62 SecurityAssociation.setCredential(null); 63 } 64 65 67 public void testRoleSecuredSLSB() throws Exception 68 { 69 InitialContext iniCtx = getClientContext(); 70 OrganizationHome home = (OrganizationHome)iniCtx.lookup("ejb/RoleSecuredSLSB"); 71 72 OrganizationRemote bean = null; 73 try 74 { 75 bean = home.create(); 76 fail("Security exception expected"); 77 } 78 catch (Exception e) 79 { 80 SecurityAssociation.setPrincipal(new SimplePrincipal(USERNAME)); 82 SecurityAssociation.setCredential(PASSWORD); 83 bean = home.create(); 84 } 85 86 String info = bean.getContactInfo("mafia"); 87 assertEquals("The 'mafia' boss is currently out of office, please call again.", info); 88 } 89 90 92 public void testBasicSecuredSLSB() throws Exception 93 { 94 InitialContext iniCtx = getClientContext(); 95 OrganizationHome home = (OrganizationHome)iniCtx.lookup("ejb/BasicSecuredSLSB"); 96 97 OrganizationRemote bean = home.create(); 98 String info = bean.getContactInfo("mafia"); 99 assertEquals("The 'mafia' boss is currently out of office, please call again.", info); 100 } 101 102 public void testBasicSecuredServiceAccess() throws Exception 103 { 104 InitialContext iniCtx = getClientContext(); 105 Service service = (Service )iniCtx.lookup("java:comp/env/service/BasicSecured"); 106 QName portName = new QName ("http://org.jboss.test.webservice/samples", "BasicSecuredPort"); 107 Organization endpoint = (Organization)service.getPort(portName, Organization.class); 108 109 try 110 { 111 endpoint.getContactInfo("mafia"); 112 fail("Security exception expected"); 113 } 114 catch (RemoteException ignore) 115 { 116 } 118 119 Stub stub = (Stub )endpoint; 120 stub._setProperty(Stub.USERNAME_PROPERTY, USERNAME); 121 stub._setProperty(Stub.PASSWORD_PROPERTY, PASSWORD); 122 123 String info = endpoint.getContactInfo("mafia"); 124 assertEquals("The 'mafia' boss is currently out of office, please call again.", info); 125 } 126 127 public void testRoleSecuredServiceAccess() throws Exception 128 { 129 InitialContext iniCtx = getClientContext(); 130 Service service = (Service )iniCtx.lookup("java:comp/env/service/RoleSecured"); 131 QName portName = new QName ("http://org.jboss.test.webservice/samples", "RoleSecuredPort"); 132 Organization endpoint = (Organization)service.getPort(portName, Organization.class); 133 134 try 135 { 136 endpoint.getContactInfo("mafia"); 137 fail("Security exception expected"); 138 } 139 catch (RemoteException ignore) 140 { 141 } 143 144 Stub stub = (Stub )endpoint; 145 stub._setProperty(Stub.USERNAME_PROPERTY, USERNAME); 146 stub._setProperty(Stub.PASSWORD_PROPERTY, PASSWORD); 147 148 String info = endpoint.getContactInfo("mafia"); 149 assertEquals("The 'mafia' boss is currently out of office, please call again.", info); 150 } 151 } 152 | Popular Tags |