1 19 20 package com.sslexplorer.upgrade; 21 22 import java.io.File ; 23 import java.sql.Connection ; 24 import java.sql.PreparedStatement ; 25 import java.sql.ResultSet ; 26 import java.sql.Statement ; 27 28 public class AuthSchemeUpgrade extends AbstractDatabaseUpgrade { 29 30 AuthSchemeUpgrade(File oldDbDir, File newDbDir) { 31 super("Authentication Schemes", 32 "Copies authentication schemes and the modules they contain to the . " 33 + "new installation. Any schemes created will be enabled by default but not policies " 34 + "will be attached.", true, "explorer_configuration", "explorer_configuration", oldDbDir, newDbDir); 35 } 36 37 public void doUpgrade(Upgrader upgrader, Connection oldConx, Connection newConx) throws Exception { 38 upgrader.info("Migrating all authentication schemes"); 40 Statement stmt = oldConx.createStatement(); 41 try { 42 ResultSet rs = stmt.executeQuery("SELECT * FROM AUTH_SCHEMES"); 43 try { 44 while (rs.next()) { 45 String authScheme = rs.getString("ID"); 46 PreparedStatement ps = newConx.prepareStatement("SELECT * FROM AUTH_SCHEMES WHERE RESOURCE_NAME = ?"); 47 boolean found = false; 48 try { 49 ps.setString(1, authScheme); 50 ResultSet rs2 = ps.executeQuery(); 51 try { 52 if (rs2.next()) { 53 found = true; 54 } 55 } finally { 56 rs2.close(); 57 } 58 } finally { 59 ps.close(); 60 } 61 62 if (found) { 63 upgrader.warn(" Auth scheme '" + authScheme + "' already exists, skipping"); 64 } else { 65 insertScheme(upgrader, newConx, oldConx, authScheme); 66 } 67 } 68 } finally { 69 rs.close(); 70 } 71 } finally { 72 stmt.close(); 73 } 74 75 } 76 77 private void insertScheme(Upgrader upgrader, Connection newConx, Connection oldConx, String authScheme) throws Exception { 78 79 PreparedStatement ps = newConx.prepareStatement("INSERT INTO AUTH_SCHEMES (RESOURCE_NAME," 80 + "RESOURCE_DESCRIPTION, DATE_CREATED,DATE_AMENDED,ENABLED) VALUES (?,?,NOW(),NOW(), 1)"); 81 try { 82 upgrader.info(" " + authScheme); 83 ps.setString(1, authScheme); 84 ps.setString(2, authScheme); 85 try { 86 ps.execute(); 87 } catch (Exception e) { 88 upgrader.warn("Failed to insert auth scheme " + authScheme + ". Probably already exists."); 89 } 90 PreparedStatement ps2 = newConx.prepareStatement("SELECT RESOURCE_ID FROM AUTH_SCHEMES WHERE RESOURCE_NAME = ?"); 91 try { 92 ps2.setString(1, authScheme); 93 ResultSet rs2 = ps2.executeQuery(); 94 try { 95 if (rs2.next()) { 96 PreparedStatement ps3 = oldConx.prepareStatement("SELECT * FROM AUTH_SEQUENCE WHERE ID = ?"); 97 try { 98 ps3.setString(1, authScheme); 99 ResultSet rs3 = ps3.executeQuery(); 100 try { 101 while (rs3.next()) { 102 String moduleId = rs3.getString("MODULE_ID"); 103 upgrader.warn(" [" + moduleId + "]"); 104 PreparedStatement ps4 = newConx 105 .prepareStatement("INSERT INTO AUTH_SEQUENCE (SCHEME_ID,MODULE_ID,SEQUENCE) VALUES(?,?,?)"); 106 try { 107 ps4.setInt(1, rs2.getInt("RESOURCE_ID")); 108 ps4.setString(2, moduleId); 109 ps4.setInt(3, rs3.getInt("SEQUENCE")); 110 try { 111 ps4.execute(); 112 } catch (Exception e) { 113 upgrader.warn("Failed to insert authentication sequence. Probably already exists."); 114 } 115 } finally { 116 ps4.close(); 117 } 118 } 119 } finally { 120 rs3.close(); 121 } 122 } finally { 123 ps3.close(); 124 } 125 } 126 } finally { 127 rs2.close(); 128 } 129 } finally { 130 ps2.close(); 131 } 132 } finally { 133 ps.close(); 134 } 135 136 } 137 138 } 139 | Popular Tags |