Roberto Sánchez
2013-12-19 cc3f9054f478d9698e240bfb644d0d9de9a37c85
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package net.curisit.securis.ioc;
import java.io.File;
import java.net.URI;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriBuilderException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
public class SecurisModule extends AbstractModule {
   private static final int DEFAULT_PORT = 9997;
   private static final String PROPERTIES_FILE_NAME = "/server.properties";
   private static final Logger log = LoggerFactory.getLogger(SecurisModule.class);
   @Override
   protected void configure() {
   }
   public String getPassword() {
       return getFilePassword() + " " + "cur1s1nt3grity";
   }
   public String getFilePassword() {
       return "cur151T";
   }
   public String getUrl(File appDir) {
       return String.format("jdbc:h2:%s/db/curisintegrity_cs;CIPHER=AES", appDir.getAbsolutePath());
   }
   @Named("base-uri")
   @Provides
   @Singleton
   public URI getBaseURI() {
       // TODO Read from configuration, where?
       try {
           // String url = MessageFormat.format("http://{0}/", InetAddress.getLocalHost().getHostAddress());
           String url = MessageFormat.format("http://{0}/", "0.0.0.0");
           log.debug("Server url{}", url);
           return UriBuilder.fromUri(url).port(getPort()).build();
       } catch (IllegalArgumentException | UriBuilderException e) {
           return UriBuilder.fromUri("http://localhost/").port(getPort()).build();
       }
   }
   private int getPort() {
       Integer port;
       Properties prop = new Properties();
       try {
           prop.load(getClass().getResourceAsStream(PROPERTIES_FILE_NAME));
           port = Integer.valueOf(prop.getProperty("port"));
           if (port == null)
               return DEFAULT_PORT;
           else
               return port;
       } catch (Exception ex) {
           return DEFAULT_PORT;
       }
   }
   protected List<String> getAppDbFiles() {
       return Arrays.asList("/db/schema.sql");
   }
   // @Provides
   // @Singleton
   // public HelloWorld provideHelloWorld() {
   // if (args.length > 0 && args[0].equals("fi")) {
   // return new HelloWorldFI();
   // } else {
   // return new HelloWorldPL();
   // }
   // }
}