1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core.net.ssl;
18
19 import java.security.KeyStoreException;
20 import java.security.NoSuchAlgorithmException;
21
22 import javax.net.ssl.TrustManagerFactory;
23
24 import org.apache.logging.log4j.core.config.plugins.Plugin;
25 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
26 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
27
28
29
30
31 @Plugin(name = "TrustStore", category = "Core", printObject = true)
32 public class TrustStoreConfiguration extends AbstractKeyStoreConfiguration {
33
34 private final String trustManagerFactoryAlgorithm;
35
36 public TrustStoreConfiguration(final String location, final String password, final String keyStoreType,
37 final String trustManagerFactoryAlgorithm) throws StoreConfigurationException {
38 super(location, password, keyStoreType);
39 this.trustManagerFactoryAlgorithm = trustManagerFactoryAlgorithm == null ? TrustManagerFactory
40 .getDefaultAlgorithm() : trustManagerFactoryAlgorithm;
41 }
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 @PluginFactory
58 public static TrustStoreConfiguration createKeyStoreConfiguration(
59
60 @PluginAttribute("location") final String location,
61 @PluginAttribute("password") final String password,
62 @PluginAttribute("type") final String keyStoreType,
63 @PluginAttribute("trustManagerFactoryAlgorithm") final String trustManagerFactoryAlgorithm) throws StoreConfigurationException {
64
65 return new TrustStoreConfiguration(location, password, keyStoreType, trustManagerFactoryAlgorithm);
66 }
67
68 public TrustManagerFactory initTrustManagerFactory() throws NoSuchAlgorithmException, KeyStoreException {
69 final TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(this.trustManagerFactoryAlgorithm);
70 tmFactory.init(this.getKeyStore());
71 return tmFactory;
72 }
73
74 @Override
75 public int hashCode() {
76 final int prime = 31;
77 int result = super.hashCode();
78 result = prime * result
79 + ((trustManagerFactoryAlgorithm == null) ? 0 : trustManagerFactoryAlgorithm.hashCode());
80 return result;
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) {
86 return true;
87 }
88 if (!super.equals(obj)) {
89 return false;
90 }
91 if (getClass() != obj.getClass()) {
92 return false;
93 }
94 TrustStoreConfiguration other = (TrustStoreConfiguration) obj;
95 if (trustManagerFactoryAlgorithm == null) {
96 if (other.trustManagerFactoryAlgorithm != null) {
97 return false;
98 }
99 } else if (!trustManagerFactoryAlgorithm.equals(other.trustManagerFactoryAlgorithm)) {
100 return false;
101 }
102 return true;
103 }
104 }