Skip to content

Commit b5b7ea0

Browse files
committed
Merge branch 'release/v0.4.2'
2 parents b076b4d + 00c458a commit b5b7ea0

42 files changed

Lines changed: 2141 additions & 471 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ script:
55
- mvn verify -X -f ./pom.xml
66
- mvn package
77
- mvn javadoc:javadoc
8-
- mvn site
8+
- mvn clean site
9+
- mvn com.gavinmogan:codacy-maven-plugin:coverage -DcoverageReportFile=target/site/cobertura/coverage.xml -DprojectToken=$CODACY_PROJECT_TOKEN -DapiToken=$CODACY_PROJECT_TOKEN
910
- mvn versions:display-dependency-updates
10-
- mvn versions:display-plugin-updates
11+
- mvn versions:display-plugin-updates

CHANGELOG

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# KeyServer Change Log
22

3+
v0.4.2
4+
--------------------------------------------------------------------------------
5+
Features:
6+
- Code improvements for an execution more robust.
7+
- More unitary tests.
8+
- Code coverage report.
9+
10+
Bug fixes:
11+
- Fixed code quality errors.
12+
13+
314
v0.4.1
415
--------------------------------------------------------------------------------
516
Features:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Open Source KeyServer [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0ea08a24d820457fae1a921252965d3f)](https://www.codacy.com/app/jgm1986/KeyServer?utm_source=github.com&utm_medium=referral&utm_content=mami-project/KeyServer&utm_campaign=Badge_Grade)
1+
# Open Source KeyServer [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0ea08a24d820457fae1a921252965d3f)](https://www.codacy.com/app/jgm1986/KeyServer?utm_source=github.com&utm_medium=referral&utm_content=mami-project/KeyServer&utm_campaign=Badge_Grade) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/0ea08a24d820457fae1a921252965d3f)](https://www.codacy.com/app/jgm1986/KeyServer?utm_source=github.com&utm_medium=referral&utm_content=jgm1986/KeyServer&utm_campaign=Badge_Coverage)
22

33
Repository branch status:
44

pom.xml

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- The Basics -->
55
<groupId>es.tid.keyserver</groupId>
66
<artifactId>KeyServer</artifactId>
7-
<version>v0.4.1</version>
7+
<version>v0.4.2</version>
88
<packaging>jar</packaging>
99
<prerequisites>
1010
<maven>3.0</maven>
@@ -31,11 +31,13 @@
3131
<groupId>ch.qos.logback</groupId>
3232
<artifactId>logback-classic</artifactId>
3333
<version>${logback-classic-version}</version>
34+
<scope>runtime</scope>
3435
</dependency>
3536
<dependency>
3637
<groupId>ch.qos.logback</groupId>
3738
<artifactId>logback-core</artifactId>
3839
<version>${logback-core-version}</version>
40+
<scope>runtime</scope>
3941
</dependency>
4042
<dependency>
4143
<groupId>org.eclipse.jetty</groupId>
@@ -80,6 +82,9 @@
8082
<plugin>
8183
<artifactId>maven-project-info-reports-plugin</artifactId>
8284
<version>2.9</version>
85+
<configuration>
86+
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
87+
</configuration>
8388
</plugin>
8489
<plugin>
8590
<artifactId>maven-assembly-plugin</artifactId>
@@ -109,9 +114,37 @@
109114
<resource>
110115
<directory>src/main/resources</directory>
111116
<filtering>true</filtering>
117+
<excludes>
118+
<exclude>logback-test.xml</exclude>
119+
</excludes>
112120
</resource>
113121
</resources>
114122
</build>
123+
124+
<!-- Reporting -->
125+
<reporting>
126+
<plugins>
127+
<plugin>
128+
<groupId>org.apache.maven.plugins</groupId>
129+
<artifactId>maven-project-info-reports-plugin</artifactId>
130+
<version>2.9</version>
131+
<configuration>
132+
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
133+
</configuration>
134+
</plugin>
135+
<plugin>
136+
<groupId>org.codehaus.mojo</groupId>
137+
<artifactId>cobertura-maven-plugin</artifactId>
138+
<version>2.7</version>
139+
<configuration>
140+
<formats>
141+
<format>html</format>
142+
<format>xml</format>
143+
</formats>
144+
</configuration>
145+
</plugin>
146+
</plugins>
147+
</reporting>
115148

116149
<!-- More Project Information -->
117150
<name>OpenSource KeyServer</name>
@@ -126,8 +159,8 @@
126159
</license>
127160
</licenses>
128161
<organization>
129-
<name>Telefonica</name>
130-
<url>http://www.telefonica.com</url>
162+
<name>MAMI Project</name>
163+
<url>https://www.mami-project.eu</url>
131164
</organization>
132165
<developers>
133166
<developer>

src/main/java/es/tid/keyserver/config/ConfigController.java

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
}

src/main/java/es/tid/keyserver/config/keyserver/ConfigFile.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package es.tid.keyserver.config.keyserver;
1718

1819
import java.io.File;
@@ -60,8 +61,8 @@ public ConfigFile(String fileRoute, String [] requiredFields){
6061
} else {
6162
LOGGER.warn("Can't access to the specified config file or "
6263
+ "doesn't exists: {}", fileRoute);
63-
LOGGER.info("New config file on default location...");
64-
fileLocation = "general.properties";
64+
LOGGER.info("New config file on default location: {}", fileRoute);
65+
fileLocation = fileRoute;
6566
if(!newDefaultProperties(fileLocation)){
6667
// If the default properties file can't be created correctly,
6768
// enable error flag and exit from the class constructor.
@@ -188,17 +189,6 @@ public String getDbIndex(){
188189
return this.getParameter("dbIndex");
189190
}
190191

191-
/**
192-
* This method is used to get the IP whitelist file name for KeyServer
193-
* access control.
194-
* @return String with the whitelist file name. If the field is not present,
195-
* returns 'null'.
196-
* @since v0.3.0
197-
*/
198-
public String getWhiteList(){
199-
return this.getParameter("whiteList");
200-
}
201-
202192
/**
203193
* This method is used to get the DB time interval when the PING will be
204194
* send. The Redis DB connection status is monitored periodically in a
@@ -252,6 +242,9 @@ public String getServerIpWhiteList() {
252242
*/
253243
private boolean newDefaultProperties(String fileLocation) {
254244
try {
245+
File file = new File(fileLocation);
246+
file.getParentFile().mkdir();
247+
file.createNewFile();
255248
FileOutputStream newConfigFile = new FileOutputStream(fileLocation);
256249
Properties defaultParameters = new Properties();
257250
// Check updates interval:

0 commit comments

Comments
 (0)