1 package org.kuali.common.jdbc;
2
3 import java.util.Arrays;
4 import java.util.List;
5 import java.util.Properties;
6
7 import org.kuali.common.util.CollectionUtils;
8 import org.kuali.common.util.property.Constants;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11
12
13
14
15 public class DriverManagerDataSource extends org.springframework.jdbc.datasource.DriverManagerDataSource {
16
17 private static final Logger logger = LoggerFactory.getLogger(DriverManagerDataSource.class);
18
19 List<String> nullPasswordTokens = Arrays.asList(new String[] { Constants.NULL, Constants.NONE });
20
21 public DriverManagerDataSource() {
22 super();
23 }
24
25 public DriverManagerDataSource(String url, Properties conProps) {
26 super(url, conProps);
27 }
28
29 public DriverManagerDataSource(String url, String username, String password) {
30 super(url, username, password);
31 nullifyPassword();
32 }
33
34 public DriverManagerDataSource(String url) {
35 super(url);
36 }
37
38
39
40
41
42 public void nullifyPassword() {
43 String pw = super.getPassword();
44 List<String> tokens = CollectionUtils.toEmpty(nullPasswordTokens);
45
46 boolean nullifyPassword = (pw != null) && tokens.contains(pw);
47 if (nullifyPassword) {
48 logger.info("Database password for '{}' is '{}' Setting to null.", super.getUsername(), pw);
49 super.setPassword(null);
50 }
51 }
52
53 public List<String> getNullPasswordTokens() {
54 return nullPasswordTokens;
55 }
56
57 public void setNullPasswordTokens(List<String> nullPasswordTokens) {
58 this.nullPasswordTokens = nullPasswordTokens;
59 }
60 }