Roberto Sánchez
2013-12-26 6d04b0ae0f4eeb9f0963b1595d0f2e7469fa5f3f
securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java
....@@ -9,9 +9,11 @@
99
1010 import javax.inject.Named;
1111 import javax.inject.Singleton;
12
+import javax.sql.DataSource;
1213 import javax.ws.rs.core.UriBuilder;
1314 import javax.ws.rs.core.UriBuilderException;
1415
16
+import org.h2.jdbcx.JdbcDataSource;
1517 import org.slf4j.Logger;
1618 import org.slf4j.LoggerFactory;
1719
....@@ -31,7 +33,7 @@
3133 }
3234
3335 public String getPassword() {
34
- return getFilePassword() + " " + "cur1s1nt3grity";
36
+ return getFilePassword() + " " + "53curi5";
3537 }
3638
3739 public String getFilePassword() {
....@@ -39,7 +41,7 @@
3941 }
4042
4143 public String getUrl(File appDir) {
42
- return String.format("jdbc:h2:%s/db/curisintegrity_cs;CIPHER=AES", appDir.getAbsolutePath());
44
+ return String.format("jdbc:h2:%s/db/securis;CIPHER=AES", appDir.getAbsolutePath());
4345 }
4446
4547 @Named("base-uri")
....@@ -77,14 +79,85 @@
7779 return Arrays.asList("/db/schema.sql");
7880 }
7981
80
- // @Provides
81
- // @Singleton
82
- // public HelloWorld provideHelloWorld() {
83
- // if (args.length > 0 && args[0].equals("fi")) {
84
- // return new HelloWorldFI();
85
- // } else {
86
- // return new HelloWorldPL();
87
- // }
88
- // }
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
+ }
97
+
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
+ }
115
+
116
+ @Named("support-email")
117
+ @Provides
118
+ @Singleton
119
+ public String getSupportEmail() {
120
+ return "integrity@curistec.com";
121
+ }
122
+
123
+ @Named("hash-logo")
124
+ @Provides
125
+ @Singleton
126
+ public String getHashLogo() {
127
+ return "1b42616809d4cd8ccf109e3c30d0ab25067f160b30b7354a08ddd563de0096ba";
128
+ }
129
+
130
+ @Named("license-req-file-name")
131
+ @Provides
132
+ @Singleton
133
+ public String getLicenseReqFileName() {
134
+ return "license.req";
135
+ }
136
+
137
+ @Named("license-file-name")
138
+ @Provides
139
+ @Singleton
140
+ public String getLicenseFileName() {
141
+ return "license.lic";
142
+ }
143
+
144
+ @Provides
145
+ @Singleton
146
+ public DataSource getDataSource(@Named("app-dir") File appDir) {
147
+
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
+ }
155
+
156
+ @Named("db-files")
157
+ @Provides
158
+ @Singleton
159
+ public List<String> getDbFiles() {
160
+ return getAppDbFiles();
161
+ }
89162
90163 }