|
19 | 19 |
|
20 | 20 | package com.cloud.upgrade.dao; |
21 | 21 |
|
22 | | -import java.io.InputStream; |
| 22 | +import java.io.*; |
23 | 23 | import java.sql.Connection; |
24 | 24 | import java.sql.PreparedStatement; |
25 | 25 | import java.sql.ResultSet; |
|
29 | 29 | import java.util.Map; |
30 | 30 | import java.util.Set; |
31 | 31 |
|
| 32 | +import com.cloud.utils.crypt.*; |
32 | 33 | import org.apache.log4j.Logger; |
33 | 34 |
|
34 | 35 | import com.cloud.hypervisor.Hypervisor; |
@@ -66,6 +67,65 @@ public InputStream[] getPrepareScripts() { |
66 | 67 | @Override |
67 | 68 | public void performDataMigration(Connection conn) { |
68 | 69 | updateSystemVmTemplates(conn); |
| 70 | + markUnnecessarySecureConfigsAsUnsecure(conn); |
| 71 | + } |
| 72 | + |
| 73 | + private void markUnnecessarySecureConfigsAsUnsecure(Connection conn) { |
| 74 | + String[] unsecureItems = new String[] { |
| 75 | + "ldap.basedn", |
| 76 | + "ldap.bind.principal", |
| 77 | + "ldap.email.attribute", |
| 78 | + "ldap.firstname.attribute", |
| 79 | + "ldap.group.object", |
| 80 | + "ldap.group.user.uniquemember", |
| 81 | + "ldap.lastname.attribute", |
| 82 | + "ldap.search.group.principle", |
| 83 | + "ldap.truststore", |
| 84 | + "ldap.user.object", |
| 85 | + "ldap.username.attribute" |
| 86 | + }; |
| 87 | + |
| 88 | + for (String name : unsecureItems) { |
| 89 | + uncrypt(conn, name); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * if encrypted, decrypt the ldap hostname and port and then update as they are not encrypted now. |
| 95 | + */ |
| 96 | + private void uncrypt(Connection conn, String name) |
| 97 | + { |
| 98 | + String value = null; |
| 99 | + try ( |
| 100 | + PreparedStatement prepSelStmt = conn.prepareStatement("SELECT conf.category,conf.value FROM `cloud`.`configuration` conf WHERE conf.name= ?"); |
| 101 | + ) { |
| 102 | + prepSelStmt.setString(1,name); |
| 103 | + try ( |
| 104 | + ResultSet resultSet = prepSelStmt.executeQuery(); |
| 105 | + ) { |
| 106 | + if (resultSet.next()) { |
| 107 | + if ("Secure".equals(resultSet.getString(1))) { |
| 108 | + value = DBEncryptionUtil.decrypt(resultSet.getString(2)); |
| 109 | + try ( |
| 110 | + PreparedStatement prepUpdStmt= conn.prepareStatement("UPDATE `cloud`.`configuration` set category = 'Advanced', value = ? where name is ?" ); |
| 111 | + ) { |
| 112 | + prepUpdStmt.setString(1, value); |
| 113 | + prepUpdStmt.setString(2, name); |
| 114 | + prepUpdStmt.execute(); |
| 115 | + } catch (SQLException e) { |
| 116 | + if (LOG.isInfoEnabled()) { |
| 117 | + LOG.info("failed to update configuration item '"+name+"' with value '"+value+"'"); |
| 118 | + if (LOG.isDebugEnabled()) { |
| 119 | + LOG.debug(""); |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | + } |
| 126 | + } catch (SQLException e) { |
| 127 | + throw new CloudRuntimeException("failed to update configuration item '"+name+"' with value '"+value+"'", e); |
| 128 | + } |
69 | 129 | } |
70 | 130 |
|
71 | 131 | @SuppressWarnings("serial") |
|
0 commit comments