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.util.Arrays;
20 import java.util.Objects;
21
22 import org.apache.logging.log4j.status.StatusLogger;
23
24
25
26
27 public class StoreConfiguration<T> {
28 protected static final StatusLogger LOGGER = StatusLogger.getLogger();
29
30 private String location;
31 private PasswordProvider passwordProvider;
32
33 public StoreConfiguration(final String location, final PasswordProvider passwordProvider) {
34 this.location = location;
35 this.passwordProvider = Objects.requireNonNull(passwordProvider, "passwordProvider");
36 }
37
38
39
40
41 @Deprecated
42 public StoreConfiguration(final String location, final char[] password) {
43 this(location, new MemoryPasswordProvider(password));
44 }
45
46
47
48
49 @Deprecated
50 public StoreConfiguration(final String location, final String password) {
51 this(location, new MemoryPasswordProvider(password == null ? null : password.toCharArray()));
52 }
53
54
55
56
57 public void clearSecrets() {
58 this.location = null;
59 this.passwordProvider = null;
60 }
61
62 public String getLocation() {
63 return this.location;
64 }
65
66 public void setLocation(final String location) {
67 this.location = location;
68 }
69
70
71
72
73
74 @Deprecated
75 public String getPassword() {
76 return String.valueOf(this.passwordProvider.getPassword());
77 }
78
79 public char[] getPasswordAsCharArray() {
80 return this.passwordProvider.getPassword();
81 }
82
83 public void setPassword(final char[] password) {
84 this.passwordProvider = new MemoryPasswordProvider(password);
85 }
86
87
88
89
90
91 @Deprecated
92 public void setPassword(final String password) {
93 this.passwordProvider = new MemoryPasswordProvider(password == null ? null : password.toCharArray());
94 }
95
96
97
98
99 protected T load() throws StoreConfigurationException {
100 return null;
101 }
102
103 @Override
104 public int hashCode() {
105 final int prime = 31;
106 int result = 1;
107 result = prime * result + ((location == null) ? 0 : location.hashCode());
108 result = prime * result + Arrays.hashCode(passwordProvider.getPassword());
109 return result;
110 }
111
112 @Override
113 public boolean equals(final Object obj) {
114 if (this == obj) {
115 return true;
116 }
117 if (obj == null) {
118 return false;
119 }
120 if (getClass() != obj.getClass()) {
121 return false;
122 }
123 final StoreConfiguration<?> other = (StoreConfiguration<?>) obj;
124 if (location == null) {
125 if (other.location != null) {
126 return false;
127 }
128 } else if (!location.equals(other.location)) {
129 return false;
130 }
131 if (!Arrays.equals(passwordProvider.getPassword(), other.passwordProvider.getPassword())) {
132 return false;
133 }
134 return true;
135 }
136 }