1 21 22 package org.apache.derbyTesting.functionTests.tests.derbynet; 23 24 import java.sql.CallableStatement ; 25 import java.sql.Connection ; 26 import java.sql.DriverManager ; 27 import java.sql.Statement ; 28 import java.sql.PreparedStatement ; 29 import java.sql.ResultSet ; 30 import java.sql.SQLException ; 31 import org.apache.derbyTesting.functionTests.util.JDBCTestDisplayUtil; 32 import org.apache.derby.impl.tools.ij.util; 33 import org.apache.derbyTesting.functionTests.util.TestUtil; 34 35 38 39 public class checkSecMgr 40 { 41 42 public static void main (String args[]) 43 { 44 try 45 { 46 Connection conn = null; 47 util.getPropertyArg(args); 48 conn = util.startJBMS(); 49 testIllegalPropertySet(conn); 52 cleanUp(conn); 53 } 54 catch (Exception e) 55 { 56 e.printStackTrace(); 57 } 58 } 59 60 public static void testIllegalDBCreate() throws Exception 61 { 62 System.out.println("Security Manager Test Starts"); 63 Class.forName("com.ibm.db2.jcc.DB2Driver"); 65 Connection conn = null; 66 67 String hostName = TestUtil.getHostName(); 77 String databaseURL; 78 if (hostName.equals("localhost")) 79 { 80 databaseURL = TestUtil.getJdbcUrlPrefix() + hostName + 81 "/\"D:/wombat;create=true\""; 82 } 83 else 84 { 85 databaseURL = TestUtil.getJdbcUrlPrefix() + hostName + "wombat"; 86 } 87 java.util.Properties properties = new java.util.Properties (); 89 properties.put ("user", "cs"); 90 properties.put ("password", "cs"); 91 92 try { 93 conn = DriverManager.getConnection(databaseURL, properties); 94 System.out.println("FAILED: Expected Security Exception"); 95 } 96 catch (SQLException se) { 97 System.out.println("Expected Security Exception"); 98 JDBCTestDisplayUtil.ShowCommonSQLException(System.out, se); 99 } 100 } 101 102 103 106 public static void testIllegalPropertySet(Connection conn) 107 { 108 System.out.println("testIllegalPropertySet"); 109 try { 110 String createproc = "CREATE PROCEDURE setIllegalPropertyProc() DYNAMIC RESULT SETS 0 LANGUAGE JAVA EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.derbynet.checkSecMgr.setIllegalPropertyProc' PARAMETER STYLE JAVA"; 111 PreparedStatement pstmt = conn.prepareStatement(createproc); 112 pstmt.executeUpdate(); 113 CallableStatement cstmt = conn.prepareCall("{call setIllegalPropertyProc()}"); 114 System.out.println("execute the procedure setting illegal property"); 115 cstmt.executeUpdate(); 116 System.out.println("FAILED: Should have gotten security Exception"); 117 } catch (SQLException se) 118 { 119 System.out.println("Expected Security Exception"); 120 JDBCTestDisplayUtil.ShowCommonSQLException(System.out, se); 121 } 122 } 123 124 public static void setIllegalPropertyProc() 125 { 126 System.setProperty("notAllowed", "somevalue"); 127 } 128 129 public static void cleanUp(Connection conn) throws SQLException 130 { 131 Statement stmt = conn.createStatement(); 132 try { 133 stmt.executeUpdate("drop procedure setIllegalPropertyProc"); 134 } catch (SQLException se) { 135 JDBCTestDisplayUtil.ShowCommonSQLException(System.out, se); 136 } 137 } 138 139 } 140 | Popular Tags |