View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.api.core.security;
17  
18  import java.io.Serializable;
19  import java.util.Properties;
20  
21  /**
22   * Responsible to read configuration properties to secure property values.
23   */
24  public class SecurityConfigurationLoader implements Serializable
25  {
26    // ********************************* Fields *********************************
27  
28    // --- constants ------------------------------------------------------------
29  
30    /**
31     * The class version identifier.
32     * <p>
33     * The value of this constant is {@value}.
34     * </p>
35     */
36    private static final long serialVersionUID = 1L;
37  
38    /**
39     * The key to the identifier for the source the configuration has been loaded
40     * from.
41     * <p>
42     * The value of this constant is {@value}.
43     * </p>
44     */
45    public static final String SECURITY_ID = "de.smartics.properties.security.id";
46  
47    /**
48     * The key with which the security key is stored in the system properties.
49     * <p>
50     * The value of this constant is {@value}.
51     * </p>
52     */
53    public static final String SECURITY_KEY =
54        "de.smartics.properties.security.key";
55  
56    /**
57     * The key with which the algorithm to construct the security key is stored in
58     * the system properties.
59     * <p>
60     * A sample value is {@code AES}.
61     * </p>
62     * <p>
63     * The value of this constant is {@value}.
64     * </p>
65     */
66    public static final String SECURITY_ALGORITHM =
67        "de.smartics.properties.security.algorithm";
68  
69    /**
70     * The key with which the security provider to encrypt and decrypt property
71     * values is stored in the system properties. If no value is provided, the
72     * system's default provider will be used.
73     * <p>
74     * The value of this constant is {@value}.
75     * </p>
76     */
77    public static final String SECURITY_PROVIDER =
78        "de.smartics.properties.security.provider";
79  
80    /**
81     * The key with which the transformation to encrypt and decrypt property
82     * values is stored in the system properties.
83     * <p>
84     * A sample value is {@code AES/ECB/PKCS5Padding}.
85     * </p>
86     * <p>
87     * The value of this constant is {@value}.
88     * </p>
89     */
90    public static final String SECURITY_TRANSFORMATION =
91        "de.smartics.properties.security.transformation";
92  
93    // --- members --------------------------------------------------------------
94  
95    // ****************************** Initializer *******************************
96  
97    // ****************************** Constructors ******************************
98  
99    /**
100    * Default constructor.
101    */
102   SecurityConfigurationLoader()
103   {
104   }
105 
106   // ****************************** Inner Classes *****************************
107 
108   // ********************************* Methods ********************************
109 
110   // --- init -----------------------------------------------------------------
111 
112   // --- get&set --------------------------------------------------------------
113 
114   // --- business -------------------------------------------------------------
115 
116   /**
117    * Loads the security configuration.
118    *
119    * @return the security configuration.
120    * @throws IllegalStateException on any problem reading the security
121    *           properties.
122    */
123   Properties load() throws IllegalStateException
124   {
125     try
126     {
127       final SecurityConfigurationPropertiesLoader propertiesLoader =
128           new SecurityConfigurationPropertiesLoader();
129       final Properties properties = propertiesLoader.load();
130       return properties;
131     }
132     catch (final IllegalStateException e)
133     {
134       final SecurityConfigurationJndiLoader jndiLoader =
135           new SecurityConfigurationJndiLoader();
136       final Properties properties = jndiLoader.load();
137       return properties;
138     }
139   }
140 
141   // --- object basics --------------------------------------------------------
142 
143 }