OK, after some trial and error my first impression that an ext plugin would not work because it woud be run later than the time needed, was correct, so I had to change the source code and rebuild using provided ant scripts (thankfully!). Since the http://issues.liferay.com/browse/LPS-4336 link corresponds to an earlier version of Liferay I thought it would be usefull to present an approach. The modification concerns the file com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean of the porta-impl.jar:
1
2 [url=http://issues.liferay.com/browse/LPS-4336][/url]
3public DataSource createInstance() throws Exception {
4 Properties properties = _properties;
5
6 if (properties == null) {
7 properties = PropsUtil.getProperties(_propertyPrefix, true);
8 }
9 else {
10 properties = PropertiesUtil.getProperties(
11 properties, _propertyPrefix, true);
12 }
13
14 Properties defaultProperties = PropsUtil.getProperties(
15 "jdbc.default.", true);
16
17 /**
18 * Overriding code: begin
19 */
20
21 Enumeration<String> propEnum = (Enumeration<String>)defaultProperties.propertyNames();
22
23 while(propEnum.hasMoreElements())
24 {
25 String key = propEnum.nextElement();
26
27 if(key.equalsIgnoreCase("password"))
28 {
29 /*Property jdbc.default.encrypted.password enables one to define whether the provided password is encrypted or not*/
30 boolean isEncrypted = GetterUtil.getBoolean(defaultProperties.getProperty("encrypted.password"));
31
32 if(isEncrypted)
33 {
34 String value = defaultProperties.getProperty(key);
35 Base64 base64 = new Base64();
36 byte[] bytesArray = base64.decode(value.getBytes());
37 value = new String(bytesArray);
38 /*Set the password property in the property member field since it is the one to be taken into account*/
39 properties.setProperty(key, value);
40 }
41 }
42 }
43
44 /**
45 * Overriding code: end
46 */
47
48 PropertiesUtil.merge(defaultProperties, properties);
49
50 properties = defaultProperties;
51//...
52//code continues...
The code part between the two "Overriding code" comments is actually an addition. Nothing was overwritten/removed. The encryption approach follows the one provided in the link of previous post. It is more like an encoding rather than a sophisticated encryption. One can replace with its own encryption choice.
I forgot to add that in this particular case the following fragment of code is sufficient to create an encoding of your db password:
1 Base64 base64 = new Base64();
2 byte[] bytesArray = null;
3 String result = null;
4 bytesArray = base64.encode(password.getBytes());
5 result = new String(bytesArray);
result variable contains the encoded password. Print it and assign it to jdbc.default.password property in portal-ext.properties
Please sign in to flag this as inappropriate.