जैसा कि @Ryan का उल्लेख है, कृपया इस समाधान को लागू करने से पहले टॉमकैट के Tomcat Password FAQ पढ़ें। आप केवल अस्पष्टता को सुरक्षा नहीं जोड़ रहे हैं।
@ जेरोम डेलट्रे का उत्तर सरल जेडीबीसी डेटा स्रोतों के लिए काम करेगा, लेकिन डेटासेट निर्माण (जैसे oracle.jdbc.xa.client.OracleXADataSource) के हिस्से के रूप में कनेक्ट होने वाले अधिक जटिल लोगों के लिए नहीं।
यह वैकल्पिक दृष्टिकोण है जो मौजूदा कारखाने को कॉल करने से पहले पासवर्ड को संशोधित करता है। नीचे मूलभूत डेटासोर्स के लिए एक कारखाने का एक उदाहरण है और एक परमाणु जेटीए संगत एक्सए डेटासोर्स के लिए एक है।
बुनियादी उदाहरण:
public class MyEncryptedPasswordFactory extends BasicDataSourceFactory {
@Override
public Object getObjectInstance(Object obj, Name name, Context context, Hashtable<?, ?> environment)
throws Exception {
if (obj instanceof Reference) {
Reference ref = (Reference) obj;
DecryptPasswordUtil.replacePasswordWithDecrypted(ref, "password");
return super.getObjectInstance(obj, name, context, environment);
} else {
throw new IllegalArgumentException(
"Expecting javax.naming.Reference as object type not " + obj.getClass().getName());
}
}
}
Atomikos उदाहरण:
public class MyEncryptedAtomikosPasswordFactory extends EnhancedTomcatAtomikosBeanFactory {
@Override
public Object getObjectInstance(Object obj, Name name, Context context, Hashtable<?, ?> environment)
throws NamingException {
if (obj instanceof Reference) {
Reference ref = (Reference) obj;
DecryptPasswordUtil.replacePasswordWithDecrypted(ref, "xaProperties.password");
return super.getObjectInstance(obj, name, context, environment);
} else {
throw new IllegalArgumentException(
"Expecting javax.naming.Reference as object type not " + obj.getClass().getName());
}
}
}
संदर्भ में अद्यतन कर रहा है पासवर्ड मूल्य:
public class DecryptPasswordUtil {
public static void replacePasswordWithDecrypted(Reference reference, String passwordKey) {
if(reference == null) {
throw new IllegalArgumentException("Reference object must not be null");
}
// Search for password addr and replace with decrypted
for (int i = 0; i < reference.size(); i++) {
RefAddr addr = reference.get(i);
if (passwordKey.equals(addr.getType())) {
if (addr.getContent() == null) {
throw new IllegalArgumentException("Password must not be null for key " + passwordKey);
}
String decrypted = yourDecryptionMethod(addr.getContent().toString());
reference.remove(i);
reference.add(i, new StringRefAddr(passwordKey, decrypted));
break;
}
}
}
}
एक बार .jar इन कक्षाओं युक्त फ़ाइल बिलाव के classpath में कर रहे हैं आप उनका उपयोग करने के लिए अपने server.xml अद्यतन कर सकते हैं।
<Resource factory="com.mycompany.MyEncryptedPasswordFactory" username="user" password="encryptedPassword" ...other options... />
<Resource factory="com.mycompany.MyEncryptedAtomikosPasswordFactory" type="com.atomikos.jdbc.AtomikosDataSourceBean" xaProperties.user="user" xaProperties.password="encryptedPassword" ...other options... />
सुनिश्चित नहीं हैं कि इस बिल्ला config फ़ाइलों के साथ क्या करना है क्या। – dacracot