Skip to content

Commit

Permalink
Merge pull request #2 from cne/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
oscargdd committed Apr 3, 2016
2 parents d6618d6 + 8b6fc14 commit 550fa2b
Show file tree
Hide file tree
Showing 29 changed files with 2,322 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Specific config files for the project
*.properties
!application.properties
/Librerias
/KeyServer/logs


# Created by https://www.gitignore.io

### Java ###
*.class

# Mobile Tools for Java (J2ME)
Expand All @@ -10,3 +20,62 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*


### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
.nb-gradle/


### NotepadPP ###
# Notepad++ backups #
*.bak

### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties


### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk


### Linux ###
*~

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*
/KeyServer/nbproject/private/
/KeyServer/target/
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# KeyServer Change Log

v0.1.3
--------------------------------------------------------------------------------
Features:
- KeyServer accepts multiples connections (system default limited).
- KeyServer log to a file.
123 changes: 123 additions & 0 deletions KeyServer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<name>KeyServer</name>
<url>https://pdihub.hi.inet/cne/cne-keyserver</url>
<modelVersion>4.0.0</modelVersion>
<groupId>es.tid.keyserver</groupId>
<artifactId>keyserver</artifactId>
<version>v0.1.3</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<developers>
<developer>
<id>jgm221</id>
<name>Javier Gusano Martinez</name>
<email>[email protected]</email>
<properties>
<active>true</active>
</properties>
</developer>
<developer>
<id>jgm1986</id>
<name>Javier Gusano Martinez</name>
<email>[email protected]</email>
<properties>
<active>true</active>
</properties>
</developer>
<developer>
<id>oscargdd</id>
<name>Oscar Gonzalez de Dios</name>
<email>[email protected]</email>
<properties>
<active>true</active>
</properties>
</developer>
</developers>

<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<mainClass>keyserver/KeyServer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>keyserver/KeyServer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
126 changes: 126 additions & 0 deletions KeyServer/src/main/java/es/tid/keyserver/config/ConfigFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* Copyright 2016.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package es.tid.keyserver.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import es.tid.keyserver.keyserver.CheckObject;
import org.slf4j.LoggerFactory;

/**
* Class for use external configuration files.
* @author <a href="mailto:[email protected]">Javier Gusano Martinez</a>
*/
public class ConfigFile implements CheckObject{
/**
* Logging object.
*/
private static final org.slf4j.Logger logger =
LoggerFactory.getLogger(ConfigFile.class);
/**
* Property object with configuration parameters.
*/
private Properties configFile;
/**
* Flag for check if the object is correctly initialized.
*/
boolean isInitializated = false;

/**
* Default class constructor.
* @param fileRoute Contains the name and route to the external
* configuration file.
*/
public ConfigFile(String fileRoute){
File propertiesFile = new File(fileRoute);
String fileLocation;
if((propertiesFile.exists() && propertiesFile.canRead())){
fileLocation = fileRoute;
} else {
logger.warn("Can't access to the specified config file or "
+ "doesn't exists: {}", fileRoute);
System.out.print(" - New config file on default location...");
fileLocation = "general.properties";
newDefaultProperties(fileLocation);
}
configFile = new Properties();
// Load the config file parammeters.
try {
configFile.load(new FileInputStream(fileLocation));
this.isInitializated = true;
} catch (IOException ex) {
logger.error("Cannot load the configuration file for KeyServer.");
logger.trace("Exceiption message: {}", ex.toString());
this.isInitializated = false;
}
}

/**
* This method is used to get a value from a configuration key.
* @param param Label of the configuration parameter.
* @return Value associated to the configuration parameter specified as
* input.
*/
public String getParameter(String param){
return configFile.getProperty(param);
}

/**
* Method used to create a new configuration file on specific route with
* default parameters.
* @param fileLocation Route and name to the new configuration file. By
* default use "general.properties"
*/
private void newDefaultProperties(String fileLocation) {
try {
FileOutputStream newConfigFile = new FileOutputStream(fileLocation);
Properties defaultParameters = new Properties();
// Default parammeters:
defaultParameters.setProperty("serverAddress", "127.0.0.1");
defaultParameters.setProperty("serverPort", "443");
defaultParameters.setProperty("serverBacklog", "0");
defaultParameters.setProperty("serverKeyFile","HTTPS_keystore.ks");
defaultParameters.setProperty("serverKeyPass","123456");
defaultParameters.setProperty("dbAddress","127.0.0.1");
defaultParameters.setProperty("dbPort", "6379");
// Save parameters on file
defaultParameters.store(newConfigFile, null);
// Close config file.
newConfigFile.close();
} catch (FileNotFoundException ex) {
logger.error("Cannot create a new config file with default parameters.");
logger.trace("Exceiption message: {}", ex.toString());
System.exit(-1);
} catch (IOException ex) {
logger.error("Cannot save a new config file with default parameters.");
logger.trace("Exceiption message: {}", ex.toString());
System.exit(-1);
}
}

/**
* Return true if the object is correctly initialized or false if not.
* @return Object initialization status.
*/
@Override
public boolean isCorrectlyInitialized() {
return isInitializated;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* This package contains all necessary to load and manipulate external
* configuration files for KeyServer.
* <p>
* The external configuration file contains all fields to determine how the
* KeyServer tool will be run.
* @since 0.1.0
*/
package es.tid.keyserver.config;
Loading

0 comments on commit 550fa2b

Please sign in to comment.