Roberto Sánchez
2014-09-19 8d5386be38db25a2a41c3bf6c876adee21ca26cc
securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java
....@@ -22,142 +22,144 @@
2222
2323 public class SecurisModule extends AbstractModule {
2424
25
- private static final int DEFAULT_PORT = 9997;
26
- private static final String PROPERTIES_FILE_NAME = "/server.properties";
25
+ private static final int DEFAULT_PORT = 9997;
26
+ private static final String PROPERTIES_FILE_NAME = "/server.properties";
2727
28
- private static final Logger LOG = LogManager.getLogger(SecurisModule.class);
28
+ private static final Logger LOG = LogManager.getLogger(SecurisModule.class);
2929
30
- @Override
31
- protected void configure() {
30
+ @Override
31
+ protected void configure() {
3232
33
- }
33
+ }
3434
35
- public String getPassword() {
36
- return getFilePassword() + " " + "53curi5";
37
- }
35
+ public String getPassword() {
36
+ return getFilePassword() + " " + "53curi5";
37
+ }
3838
39
- public String getFilePassword() {
40
- return "cur151T";
41
- }
39
+ public String getFilePassword() {
40
+ return "cur151T";
41
+ }
4242
43
- public String getUrl(File appDir) {
44
- return String.format("jdbc:h2:%s/db/securis;CIPHER=AES", appDir.getAbsolutePath());
45
- }
43
+ public String getUrl(File appDir) {
44
+ return String.format("jdbc:h2:%s/db/securis;CIPHER=AES", appDir.getAbsolutePath());
45
+ }
4646
47
- @Named("base-uri")
48
- @Provides
49
- @Singleton
50
- public URI getBaseURI() {
51
- // TODO Read from configuration, where?
52
- try {
53
- // String url = MessageFormat.format("http://{0}/", InetAddress.getLocalHost().getHostAddress());
54
- String url = MessageFormat.format("http://{0}/", "0.0.0.0");
55
- LOG.debug("Server url{}", url);
56
- return UriBuilder.fromUri(url).port(getPort()).build();
57
- } catch (IllegalArgumentException | UriBuilderException e) {
58
- return UriBuilder.fromUri("http://localhost/").port(getPort()).build();
59
- }
60
- }
47
+ @Named("base-uri")
48
+ @Provides
49
+ @Singleton
50
+ public URI getBaseURI() {
51
+ // TODO Read from configuration, where?
52
+ try {
53
+ String url = MessageFormat.format("http://{0}/", "0.0.0.0");
54
+ LOG.debug("Server url{}", url);
55
+ return UriBuilder.fromUri(url).port(getPort()).build();
56
+ } catch (IllegalArgumentException | UriBuilderException e) {
57
+ return UriBuilder.fromUri("http://localhost/").port(getPort()).build();
58
+ }
59
+ }
6160
62
- private int getPort() {
63
- Integer port;
64
- Properties prop = new Properties();
65
- try {
66
- prop.load(getClass().getResourceAsStream(PROPERTIES_FILE_NAME));
67
- port = Integer.valueOf(prop.getProperty("port"));
68
- if (port == null)
69
- return DEFAULT_PORT;
70
- else
71
- return port;
72
- } catch (Exception ex) {
73
- return DEFAULT_PORT;
74
- }
75
- }
61
+ private int getPort() {
62
+ Integer port;
63
+ Properties prop = new Properties();
64
+ try {
65
+ prop.load(getClass().getResourceAsStream(PROPERTIES_FILE_NAME));
66
+ port = Integer.valueOf(prop.getProperty("port"));
67
+ if (port == null) {
68
+ return DEFAULT_PORT;
69
+ } else {
70
+ return port;
71
+ }
72
+ } catch (Exception ex) {
73
+ return DEFAULT_PORT;
74
+ }
75
+ }
7676
77
- protected List<String> getAppDbFiles() {
77
+ protected List<String> getAppDbFiles() {
7878
79
- return Arrays.asList("/db/schema.sql");
80
- }
79
+ return Arrays.asList("/db/schema.sql");
80
+ }
8181
82
- @Named("temporary-dir")
83
- @Provides
84
- @Singleton
85
- public File getTemporaryDir() {
86
- String tmp = getAppDir().getAbsolutePath();
87
- tmp += File.separator + ".TEMP";
88
- File ftmp = new File(tmp);
89
- if (!ftmp.exists()) {
90
- if (!ftmp.mkdirs())
91
- return null;
92
- LOG.debug("Created temporary directory for app in: {}", ftmp.getAbsolutePath());
93
- ftmp.deleteOnExit();
94
- }
95
- return ftmp;
96
- }
82
+ @Named("temporary-dir")
83
+ @Provides
84
+ @Singleton
85
+ public File getTemporaryDir() {
86
+ String tmp = getAppDir().getAbsolutePath();
87
+ tmp += File.separator + ".TEMP";
88
+ File ftmp = new File(tmp);
89
+ if (!ftmp.exists()) {
90
+ if (!ftmp.mkdirs()) {
91
+ return null;
92
+ }
93
+ LOG.debug("Created temporary directory for app in: {}", ftmp.getAbsolutePath());
94
+ ftmp.deleteOnExit();
95
+ }
96
+ return ftmp;
97
+ }
9798
98
- @Named("app-dir")
99
- @Provides
100
- @Singleton
101
- public File getAppDir() {
102
- String appDir = System.getProperty("user.home", System.getProperty("user.dir"));
103
- if (appDir == null) {
104
- appDir = ".";
105
- }
106
- appDir += File.separator + ".SeCuris";
107
- File fAppDir = new File(appDir);
108
- if (!fAppDir.exists()) {
109
- if (!fAppDir.mkdirs())
110
- return null;
111
- LOG.debug("Created app working directory app in: {}", fAppDir.getAbsolutePath());
112
- }
113
- return fAppDir;
114
- }
99
+ @Named("app-dir")
100
+ @Provides
101
+ @Singleton
102
+ public File getAppDir() {
103
+ String appDir = System.getProperty("user.home", System.getProperty("user.dir"));
104
+ if (appDir == null) {
105
+ appDir = ".";
106
+ }
107
+ appDir += File.separator + ".SeCuris";
108
+ File fAppDir = new File(appDir);
109
+ if (!fAppDir.exists()) {
110
+ if (!fAppDir.mkdirs()) {
111
+ return null;
112
+ }
113
+ LOG.debug("Created app working directory app in: {}", fAppDir.getAbsolutePath());
114
+ }
115
+ return fAppDir;
116
+ }
115117
116
- @Named("support-email")
117
- @Provides
118
- @Singleton
119
- public String getSupportEmail() {
120
- return "integrity@curistec.com";
121
- }
118
+ @Named("support-email")
119
+ @Provides
120
+ @Singleton
121
+ public String getSupportEmail() {
122
+ return "integrity@curistec.com";
123
+ }
122124
123
- @Named("hash-logo")
124
- @Provides
125
- @Singleton
126
- public String getHashLogo() {
127
- return "1b42616809d4cd8ccf109e3c30d0ab25067f160b30b7354a08ddd563de0096ba";
128
- }
125
+ @Named("hash-logo")
126
+ @Provides
127
+ @Singleton
128
+ public String getHashLogo() {
129
+ return "1b42616809d4cd8ccf109e3c30d0ab25067f160b30b7354a08ddd563de0096ba";
130
+ }
129131
130
- @Named("license-req-file-name")
131
- @Provides
132
- @Singleton
133
- public String getLicenseReqFileName() {
134
- return "license.req";
135
- }
132
+ @Named("license-req-file-name")
133
+ @Provides
134
+ @Singleton
135
+ public String getLicenseReqFileName() {
136
+ return "license.req";
137
+ }
136138
137
- @Named("license-file-name")
138
- @Provides
139
- @Singleton
140
- public String getLicenseFileName() {
141
- return "license.lic";
142
- }
139
+ @Named("license-file-name")
140
+ @Provides
141
+ @Singleton
142
+ public String getLicenseFileName() {
143
+ return "license.lic";
144
+ }
143145
144
- @Provides
145
- @Singleton
146
- public DataSource getDataSource(@Named("app-dir") File appDir) {
146
+ @Provides
147
+ @Singleton
148
+ public DataSource getDataSource(@Named("app-dir") File appDir) {
147149
148
- JdbcDataSource dataSource = new JdbcDataSource();
149
- dataSource.setURL(getUrl(appDir));
150
- dataSource.setUser("curis");
151
- dataSource.setPassword(getPassword());
152
- LOG.debug("JdbcDataSource: {}", dataSource);
153
- return dataSource;
154
- }
150
+ JdbcDataSource dataSource = new JdbcDataSource();
151
+ dataSource.setURL(getUrl(appDir));
152
+ dataSource.setUser("curis");
153
+ dataSource.setPassword(getPassword());
154
+ LOG.debug("JdbcDataSource: {}", dataSource);
155
+ return dataSource;
156
+ }
155157
156
- @Named("db-files")
157
- @Provides
158
- @Singleton
159
- public List<String> getDbFiles() {
160
- return getAppDbFiles();
161
- }
158
+ @Named("db-files")
159
+ @Provides
160
+ @Singleton
161
+ public List<String> getDbFiles() {
162
+ return getAppDbFiles();
163
+ }
162164
163165 }