01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */
18: package org.apache.ivy.util;
19:
20: import java.util.ArrayList;
21: import java.util.Collection;
22: import java.util.List;
23: import java.util.Properties;
24:
25: /**
26: * An implementation of Properties which stores the values encrypted. The use is transparent from
27: * the user point of view (use as any Properties instance), except that get, put and putAll do not
28: * handle encryption/decryption. This means that get returns the encrypted value, while put and
29: * putAll puts given values without encrypting them. It this thus recommended to void using them,
30: * use setProperty and getProperty instead.
31: */
32: public class EncrytedProperties extends Properties {
33:
34: public EncrytedProperties() {
35: super ();
36: }
37:
38: public synchronized Object setProperty(String key, String value) {
39: return StringUtils.decrypt((String) super .setProperty(key,
40: StringUtils.encrypt(value)));
41: }
42:
43: public String getProperty(String key) {
44: return StringUtils.decrypt(super .getProperty(key));
45: }
46:
47: public String getProperty(String key, String defaultValue) {
48: return StringUtils.decrypt(super .getProperty(key, StringUtils
49: .encrypt(defaultValue)));
50: }
51:
52: public boolean containsValue(Object value) {
53: return super .containsValue(StringUtils.encrypt((String) value));
54: }
55:
56: public synchronized boolean contains(Object value) {
57: return super .contains(StringUtils.encrypt((String) value));
58: }
59:
60: public Collection values() {
61: List ret = new ArrayList(super .values());
62: for (int i = 0; i < ret.size(); i++) {
63: ret.set(i, StringUtils.decrypt((String) ret.get(i)));
64: }
65: return ret;
66: }
67: }
|