1- /*
1+ /**
22 * Copyright 2016.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,10 +35,12 @@ public class ConfigController implements CheckObject{
3535 * Logging object.
3636 */
3737 private static final org .slf4j .Logger LOGGER = LoggerFactory .getLogger (ConfigController .class );
38+
3839 /**
3940 * Maven project data object.
4041 */
4142 private final Maven mavenData ;
43+
4244 /**
4345 * KeyServer configuration data object.
4446 */
@@ -110,7 +112,11 @@ public String getProjectPublicUrl(){
110112 public InetAddress getServerAddress (){
111113 String address = this .keyserverConfig .getServerAddress ();
112114 try {
113- return InetAddress .getByName (address );
115+ if ((address != null ) && (!address .isEmpty ())){
116+ return InetAddress .getByName (address );
117+ } else {
118+ throw (new UnknownHostException ("Empty Address." ));
119+ }
114120 } catch (UnknownHostException ex ) {
115121 // Error level.
116122 LOGGER .error ("Unknown Host Exception with the server IP addres: {}" , address );
@@ -130,7 +136,7 @@ public InetAddress getServerAddress(){
130136 */
131137 public int getServerPort (){
132138 String port = this .keyserverConfig .getServerPort ();
133- if (port != null ){
139+ if (( port != null ) && (! port . isEmpty () && ( Integer . parseInt ( port ) > 0 )) ){
134140 return Integer .parseInt (port );
135141 } else {
136142 // Error level.
@@ -157,7 +163,14 @@ public String getServerKeyStoreFile(){
157163 * @since v0.3.0
158164 */
159165 public String getServerKeyStorePassword (){
160- return this .keyserverConfig .getKeyStorePassword ();
166+ String password = this .keyserverConfig .getKeyStorePassword ();
167+ if ((password != null ) && (!password .isEmpty ())){
168+ return password ;
169+ } else {
170+ // Error level.
171+ LOGGER .error ("Not valid password specified for the KS Key Store Password: {}" , password );
172+ return null ;
173+ }
161174 }
162175
163176 /**
@@ -168,7 +181,14 @@ public String getServerKeyStorePassword(){
168181 * @since v0.4.0
169182 */
170183 public String getServerKeyManagerPassword (){
171- return this .keyserverConfig .getKeyManagerPassword ();
184+ String password = this .keyserverConfig .getKeyManagerPassword ();
185+ if ((password != null ) && (!password .isEmpty ())){
186+ return password ;
187+ } else {
188+ // Error level.
189+ LOGGER .error ("Not valid password specified for the KS Key Manager Password: {}" , password );
190+ return null ;
191+ }
172192 }
173193
174194 /**
@@ -177,12 +197,10 @@ public String getServerKeyManagerPassword(){
177197 * @return The value in milliseconds or -1 if the value is not valid.
178198 */
179199 public long getIdleTimeout () {
180- if (this .keyserverConfig .getServerIdleTimeout ().isEmpty ()){
181- return -1 ;
182- }
183- int time = Integer .valueOf (this .keyserverConfig .getServerIdleTimeout ());
184- if (time > 0 ){
185- return time ;
200+ if ((this .keyserverConfig .getServerIdleTimeout () != null ) &&
201+ (!this .keyserverConfig .getServerIdleTimeout ().isEmpty ()) &&
202+ (Integer .valueOf (this .keyserverConfig .getServerIdleTimeout ()) > 0 )){
203+ return Integer .valueOf (this .keyserverConfig .getServerIdleTimeout ());
186204 } else {
187205 // Warning level.
188206 LOGGER .warn ("Jetty connection Idle Timeout value is not valid." );
@@ -198,16 +216,20 @@ public long getIdleTimeout() {
198216 * @since v0.4.0
199217 */
200218 public String [] getServerIpWhiteList () {
201- if (this .keyserverConfig .getServerIpWhiteList ()==null ){
219+ if (( this .keyserverConfig .getServerIpWhiteList ()==null ) || this . keyserverConfig . getServerIpWhiteList (). isEmpty () ){
202220 // Not defined.
203221 return null ;
204222 }
205223 String tmp = this .keyserverConfig .getServerIpWhiteList ();
206224 if (tmp .contains ("&" )){
207225 // Contains multiples IPs.
208- return tmp .split ("&" );
226+ String [] output = tmp .split ("&" );
227+ for (int i = 0 ; i < output .length ; i ++){
228+ output [i ]=output [i ].trim (); // Remove white spaces.
229+ }
230+ return output ;
209231 } else {
210- // Only contains a IP.
232+ // Only contains an IP.
211233 String [] value = {tmp };
212234 return value ;
213235 }
@@ -222,6 +244,9 @@ public String[] getServerIpWhiteList() {
222244 public InetAddress getDbAddress (){
223245 String address = this .keyserverConfig .getDbAddress ();
224246 try {
247+ if (address == null ){
248+ throw (new UnknownHostException ("Address null." ));
249+ }
225250 return InetAddress .getByName (address );
226251 } catch (UnknownHostException ex ) {
227252 // Error level.
@@ -242,7 +267,7 @@ public InetAddress getDbAddress(){
242267 */
243268 public int getDbPort (){
244269 String port = this .keyserverConfig .getDbPort ();
245- if (port != null ){
270+ if (( port != null ) && (! port . isEmpty ()) && ( Integer . parseInt ( port ) > 0 ) ){
246271 return Integer .parseInt (port );
247272 } else {
248273 // Error level.
@@ -259,7 +284,7 @@ public int getDbPort(){
259284 */
260285 public String getDbPassword (){
261286 String password = this .keyserverConfig .getDbPassword ();
262- if (password != null ){
287+ if (( password != null ) && (! password . isEmpty ()) ){
263288 return password ;
264289 } else {
265290 // Error level.
@@ -276,7 +301,7 @@ public String getDbPassword(){
276301 */
277302 public int getDbIndex (){
278303 String index = this .keyserverConfig .getDbIndex ();
279- if (index != null ){
304+ if (( index != null ) && (! index . isEmpty ())&&( Integer . valueOf ( index ) > 0 ) ){
280305 return Integer .valueOf (index );
281306 } else {
282307 // Warning level.
@@ -289,16 +314,15 @@ public int getDbIndex(){
289314 * This method is used to get the DB time interval when the PING will be
290315 * send. The Redis DB connection status is monitored periodically in a
291316 * parallel thread.
292- * @return Integer with the time in milliseconds.
317+ * @return Integer with the time in milliseconds. If the field is not
318+ * present or invalid (lower than 100ms), returns -1.
293319 * @since v0.3.3
294320 */
295321 public int getChkDbInterval (){
296- if (this .keyserverConfig .getChkDbInterval ().isEmpty ()){
297- return -1 ;
298- }
299- int time = Integer .valueOf (this .keyserverConfig .getChkDbInterval ());
300- if (time >= 100 ){
301- return time ;
322+ if ((this .keyserverConfig .getChkDbInterval ()!= null ) &&
323+ (!this .keyserverConfig .getChkDbInterval ().isEmpty ()) &&
324+ (Integer .valueOf (this .keyserverConfig .getChkDbInterval ()) >= 100 )){
325+ return Integer .valueOf (this .keyserverConfig .getChkDbInterval ());
302326 } else {
303327 // Warning level.
304328 LOGGER .warn ("DB connection check interval value is not valid. "
@@ -307,17 +331,6 @@ public int getChkDbInterval(){
307331 }
308332 }
309333
310- /**
311- * This method is used to get the IP 'white list' file name for KeyServer
312- * access control.
313- * @return String with the 'white list' file name. If the field is not present,
314- * returns 'null'.
315- * @since v0.3.0
316- */
317- public String getWhiteList (){
318- return this .keyserverConfig .getWhiteList ();
319- }
320-
321334 /**
322335 * This method is used to set the interval value in milliseconds for check
323336 * if there are a new KeyServer version available on GitHub.
@@ -327,15 +340,13 @@ public String getWhiteList(){
327340 * @since v0.3.3
328341 */
329342 public int getChkUpdateInterval (){
330- if (this .keyserverConfig .getChkUpdateInterval ().isEmpty ()){
331- return -1 ;
332- }
333- int time = Integer .valueOf (this .keyserverConfig .getChkUpdateInterval ());
334- if (time >= 60000 ){
335- return time ;
343+ if ((this .keyserverConfig .getChkUpdateInterval () != null ) &&
344+ (!this .keyserverConfig .getChkUpdateInterval ().isEmpty ()) &&
345+ (Integer .valueOf (this .keyserverConfig .getChkUpdateInterval ()) >= 60000 )){
346+ return Integer .valueOf (this .keyserverConfig .getChkUpdateInterval ());
336347 } else {
337348 // Warning level.
338- LOGGER .warn ("KeyServer updates check interval value is not valid." );
349+ LOGGER .warn ("KeyServer updates check interval value is not valid (must be greater than 60000) ." );
339350 return -1 ;
340351 }
341352 }
0 commit comments