Roberto Sánchez
2013-12-17 cbed80ba1ec72590c704a24a60d50862297c4cd9
#333 feature - Create SECuris repo, first steps
4 files added
2 files modified
changed files
securis/pom.xml patch | view | blame | history
securis/src/main/java/net/curisit/securis/MainApp.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java patch | view | blame | history
securis/src/main/resources/db/schema.sql patch | view | blame | history
securis/src/main/resources/log4j.xml patch | view | blame | history
securis/src/main/resources/server.properties patch | view | blame | history
securis/pom.xml
....@@ -27,4 +27,16 @@
2727 <version>0.0.1-SNAPSHOT</version>
2828 </dependency>
2929 </dependencies>
30
+ <build>
31
+ <plugins>
32
+ <plugin>
33
+ <groupId>org.apache.maven.plugins</groupId>
34
+ <artifactId>maven-compiler-plugin</artifactId>
35
+ <configuration>
36
+ <source>1.7</source>
37
+ <target>1.7</target>
38
+ </configuration>
39
+ </plugin>
40
+ </plugins>
41
+ </build>
3042 </project>
securis/src/main/java/net/curisit/securis/MainApp.java
....@@ -12,6 +12,7 @@
1212
1313 public static void main(String[] args) {
1414 log.info("SeCuris init...");
15
+
1516 }
1617
1718 }
securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java
....@@ -0,0 +1,96 @@
1
+package net.curisit.securis.ioc;
2
+
3
+import java.io.File;
4
+import java.net.URI;
5
+import java.text.MessageFormat;
6
+import java.util.Arrays;
7
+import java.util.List;
8
+import java.util.Properties;
9
+
10
+import javafx.application.Application;
11
+
12
+import javax.inject.Named;
13
+import javax.inject.Singleton;
14
+import javax.ws.rs.core.UriBuilder;
15
+import javax.ws.rs.core.UriBuilderException;
16
+
17
+import org.slf4j.Logger;
18
+import org.slf4j.LoggerFactory;
19
+
20
+import com.google.inject.AbstractModule;
21
+import com.google.inject.Provides;
22
+
23
+public class SecurisModule extends AbstractModule {
24
+
25
+ Application app = null;
26
+
27
+ private static final int DEFAULT_PORT = 9997;
28
+ private static final String PROPERTIES_FILE_NAME = "/server.properties";
29
+
30
+ private static final Logger log = LoggerFactory.getLogger(SecurisModule.class);
31
+
32
+ public SecurisModule(Application app) {
33
+ this.app = app;
34
+ }
35
+
36
+ public SecurisModule() {
37
+ this.app = null;
38
+ }
39
+
40
+ @Override
41
+ protected void configure() {
42
+
43
+ }
44
+
45
+ public String getPassword() {
46
+ return getFilePassword() + " " + "cur1s1nt3grity";
47
+ }
48
+
49
+ public String getFilePassword() {
50
+ return "cur151T";
51
+ }
52
+
53
+ public String getUrl(File appDir) {
54
+ return String.format("jdbc:h2:%s/db/curisintegrity_cs;CIPHER=AES", appDir.getAbsolutePath());
55
+ }
56
+
57
+ @Named("base-uri")
58
+ @Provides
59
+ @Singleton
60
+ public URI getBaseURI() {
61
+ // TODO Read from configuration, where?
62
+ try {
63
+ // String url = MessageFormat.format("http://{0}/", InetAddress.getLocalHost().getHostAddress());
64
+ String url = MessageFormat.format("http://{0}/", "0.0.0.0");
65
+ log.debug("Server url{}", url);
66
+ return UriBuilder.fromUri(url).port(getPort()).build();
67
+ } catch (IllegalArgumentException | UriBuilderException e) {
68
+ return UriBuilder.fromUri("http://localhost/").port(getPort()).build();
69
+ }
70
+ }
71
+
72
+ private int getPort() {
73
+ Integer port;
74
+ Properties prop = new Properties();
75
+ try {
76
+ prop.load(getClass().getResourceAsStream(PROPERTIES_FILE_NAME));
77
+ port = Integer.valueOf(prop.getProperty("port"));
78
+ if (port == null)
79
+ return DEFAULT_PORT;
80
+ else
81
+ return port;
82
+ } catch (Exception ex) {
83
+ return DEFAULT_PORT;
84
+ }
85
+ }
86
+
87
+ protected List<String> getAppDbFiles() {
88
+
89
+ return Arrays.asList("/db/schema.sql");
90
+ }
91
+
92
+ protected Application getApp() {
93
+ return this.app;
94
+ }
95
+
96
+}
securis/src/main/resources/db/schema.sql
securis/src/main/resources/log4j.xml
....@@ -0,0 +1,26 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3
+
4
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
5
+
6
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
7
+ <param name="Target" value="System.out"/>
8
+ <layout class="org.apache.log4j.PatternLayout">
9
+ <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
10
+ </layout>
11
+ </appender>
12
+
13
+ <logger name="net.curisit">
14
+ <level value="INFO"/>
15
+ </logger>
16
+
17
+ <logger name="sandbox">
18
+ <level value="DEBUG"/>
19
+ </logger>
20
+
21
+ <root>
22
+ <priority value ="WARN" />
23
+ <appender-ref ref="console" />
24
+ </root>
25
+
26
+</log4j:configuration>
securis/src/main/resources/server.properties
....@@ -0,0 +1 @@
1
+port=9997