View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.core.net.ssl;
18  
19  import java.util.Arrays;
20  
21  import org.apache.logging.log4j.status.StatusLogger;
22  
23  /**
24   *
25   */
26  public class StoreConfiguration<T> {
27      protected static final StatusLogger LOGGER = StatusLogger.getLogger();
28  
29      private String location;
30      private char[] password; // TODO get and set in some obfuscated or encrypted format?
31  
32      public StoreConfiguration(final String location, final char[] password) {
33          this.location = location;
34          this.password = password;
35      }
36  
37      /**
38       * Clears the secret fields in this object.
39       */
40      public void clearSecrets() {
41          this.location = null;
42          if (password != null) {
43              Arrays.fill(password, Character.MIN_VALUE);
44              this.password = null;
45          }
46      }
47  
48      /**
49       * @deprecated Use StoreConfiguration(String, char[])
50       */
51      @Deprecated
52      public StoreConfiguration(final String location, final String password) {
53          this.location = location;
54          this.password = password == null ? null : password.toCharArray();
55      }
56  
57      public String getLocation() {
58          return this.location;
59      }
60  
61      public void setLocation(final String location) {
62          this.location = location;
63      }
64  
65      /**
66       *
67       * @deprecated Use getPasswordAsCharArray()
68       */
69      @Deprecated
70      public String getPassword() {
71          return String.valueOf(this.password);
72      }
73  
74      public char[] getPasswordAsCharArray() {
75          return this.password;
76      }
77  
78      public void setPassword(final char[] password) {
79          this.password = password;
80      }
81  
82      /**
83       *
84       * @deprecated Use getPasswordAsCharArray()
85       */
86      @Deprecated
87      public void setPassword(final String password) {
88          this.password = password == null ? null : password.toCharArray();
89      }
90  
91      /**
92       * @throws StoreConfigurationException May be thrown by subclasses
93       */
94      protected T load() throws StoreConfigurationException {
95          return null;
96      }
97  
98      @Override
99      public int hashCode() {
100         final int prime = 31;
101         int result = 1;
102         result = prime * result + ((location == null) ? 0 : location.hashCode());
103         result = prime * result + Arrays.hashCode(password);
104         return result;
105     }
106 
107     @Override
108     public boolean equals(final Object obj) {
109         if (this == obj) {
110             return true;
111         }
112         if (obj == null) {
113             return false;
114         }
115         if (getClass() != obj.getClass()) {
116             return false;
117         }
118         final StoreConfiguration<?> other = (StoreConfiguration<?>) obj;
119         if (location == null) {
120             if (other.location != null) {
121                 return false;
122             }
123         } else if (!location.equals(other.location)) {
124             return false;
125         }
126         if (!Arrays.equals(password, other.password)) {
127             return false;
128         }
129         return true;
130     }
131 }