1 22 package org.jboss.test.securitymgr.ejb; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.lang.SecurityManager ; 27 import java.lang.reflect.Field ; 28 import java.net.ServerSocket ; 29 import java.net.Socket ; 30 import java.security.Permission ; 31 import java.security.Principal ; 32 import javax.ejb.CreateException ; 33 import javax.ejb.EJBException ; 34 import javax.ejb.SessionBean ; 35 import javax.ejb.SessionContext ; 36 37 import org.jboss.logging.Logger; 38 39 import org.jboss.security.SecurityAssociation; 40 41 47 public class IOStatelessSessionBean implements SessionBean 48 { 49 static final Logger log = Logger.getLogger(IOStatelessSessionBean.class); 50 51 private SessionContext sessionContext; 52 53 public void ejbCreate() throws CreateException 54 { 55 } 56 public void ejbActivate() 57 { 58 } 59 public void ejbPassivate() 60 { 61 } 62 public void ejbRemove() 63 { 64 } 65 66 public void setSessionContext(SessionContext context) 67 { 68 sessionContext = context; 69 } 70 71 73 public String read(String path) throws IOException 74 { 75 log.debug("read, path="+path); 76 File tstPath = new File (path); 77 if( tstPath.exists() == false ) 78 path = null; 79 return path; 80 } 81 82 public void write(String path) throws IOException 83 { 84 log.debug("write, path="+path); 85 File tstPath = new File (path); 86 tstPath.createNewFile(); 87 } 88 89 public void listen(int port) throws IOException 90 { 91 log.debug("Creating server listening port: "+port); 92 ServerSocket ss = new ServerSocket (port); 93 log.debug("Listening"); 94 ss.close(); 95 } 96 97 public void connect(String host, int port) throws IOException 98 { 99 log.debug("connect, host: "+host+", port: "+port); 100 Socket s = new Socket (host, port); 101 log.debug("Connected"); 102 s.close(); 103 } 104 105 public void createClassLoader() 106 { 107 log.debug("createClassLoader"); 108 ClassLoader cl = new ClassLoader () 110 { 111 }; 112 log.debug("Created ClassLoader"); 113 } 114 public void getContextClassLoader() 115 { 116 log.debug("Begin getContextClassLoader"); 118 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 119 log.debug("End getContextClassLoader"); 120 } 121 public void setContextClassLoader() 122 { 123 log.debug("Begin setContextClassLoader"); 124 ClassLoader cl = null; 125 Thread.currentThread().setContextClassLoader(cl); 126 log.debug("End setContextClassLoader"); 127 } 128 public void createSecurityMgr() 129 { 130 log.debug("createSecurityMgr"); 131 SecurityManager secmgr = new SecurityManager () 132 { 133 public void checkPermission(Permission p) 134 { 135 } 136 }; 137 System.setSecurityManager(secmgr); 138 } 139 140 144 public void renameThread() 145 { 146 log.debug("renameThread"); 147 Thread t = Thread.currentThread(); 148 t.setName("Hijacked name"); 149 log.debug("Renamed current thread"); 150 } 151 public void createThread() 152 { 153 log.debug("createThread"); 154 Thread t = new Thread ("IOSession.createThread"); 155 t.start(); 156 log.debug("Started a thread"); 157 } 158 159 162 public void useReflection() 163 { 164 log.debug("useReflection"); 165 try 166 { 167 Field secret = System .class.getDeclaredField("secret"); 168 Object value = secret.get(null); 169 } 170 catch(NoSuchFieldException e) 171 { 172 } 173 catch(IllegalAccessException e) 174 { 175 } 176 log.debug("Search for System.secret did not fail with a SecurityException"); 177 } 178 179 public void loadLibrary() 180 { 181 log.debug("loadLibrary"); 182 System.loadLibrary("jdwp"); 183 log.debug("Called System.loadLibrary"); 184 } 185 186 public void changeSystemOut() 187 { 188 log.debug("changeSystemOut"); 189 System.setOut(null); 190 } 191 public void changeSystemErr() 192 { 193 log.debug("changeSystemErr"); 194 System.setErr(null); 195 } 196 197 public void systemExit(int status) 198 { 199 log.debug("systemExit"); 200 System.exit(status); 201 } 202 203 } 204 | Popular Tags |