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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package net.curisit.securis.services;
import java.io.IOException;
import java.net.URI;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * Basic services for login a nd basic app wrkflow
 * 
 * @author roberto <roberto.sanchez@curisit.net>
 */
@Path("/")
public class BasicServices {
   // private LicenseHelper licenseHelper = InjectorFactory.getInjector().getInstance(LicenseHelper.class);
   private static final Logger log = LoggerFactory.getLogger(BasicServices.class);
   public BasicServices() {
   }
   /**
    * 
    * @return the server version in format majorVersion.minorVersion
    */
   @GET
   @Produces(
       { MediaType.TEXT_HTML })
   public Response index() {
       URI uri = UriBuilder.fromUri("/login").build();
       return Response.seeOther(uri).build();
       // return Response.ok().entity("License server").build();
   }
   @GET
   @Path("/login")
   @Produces(
       { MediaType.TEXT_HTML })
   public Response login() {
       try {
           String index = IOUtils.toString(this.getClass().getResourceAsStream("/static/login.html"));
           return Response.ok().entity(index).build();
       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       return Response.serverError().build();
   }
   @POST
   @Path("/login")
   @Produces(
       { MediaType.TEXT_HTML })
   public Response login(@FormParam("user") String user, @FormParam("password") String password, @Context HttpServletRequest request) {
       log.info("Request: " + request.getParameter("user"));
       log.info("user/pass: {} == {} ? ", user, password);
       // log.info("user: {} == {} ? " + request.getParameter("user"), user);
       URI uri = UriBuilder.fromUri("/main").build();
       return Response.seeOther(uri).build();
   }
   /**
    * @return the version of the three entities that can be synchronized (Users, DataSet and Settings)
    */
   @GET
   @Path("/main")
   @Produces(
       { MediaType.TEXT_HTML })
   public Response main() {
       try {
           String index = IOUtils.toString(this.getClass().getResourceAsStream("/static/main.html"));
           return Response.ok().entity(index).build();
       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       return Response.status(Status.FORBIDDEN).build();
   }
   //
   // private <T> ServiceResponse<T> buildErrorResponse(ServiceResponse<T> response, String msgErrorCode) {
   // response.setSuccess(false);
   // response.setErrorMessage(localManager.getString(msgErrorCode));
   // response.setErrorMessageCode(msgErrorCode);
   // return response;
   // }
   //
   // private Date calculateCaducation() {
   // Integer licenseExpiration = systemParams.getParamAsInt(SystemParams.Keys.CONFIG_SERVER_LICENSE_EXPIRATION);
   // if (licenseExpiration == null)
   // licenseExpiration = DEFAULT_LICENSE_EXPIRATION;
   // return Utils.addDays(new Date(), licenseExpiration);
   // }
   //
   // private boolean validateLicense(String license) {
   // BasicApplication ba = basicApplicationDao.findByLicense(license);
   // return (ba != null);
   // }
   //
   // private boolean validateVersion(int minorVersion, int majorVersion) {
   // return (versionManager.getMajorVersion() == majorVersion);
   // }
   //
   // private BasicApplication findBasicApp(String license) {
   // BasicApplication ba = basicApplicationDao.findByLicense(license);
   // return ba;
   // }
   //
   // private License generateLicense() {
   // // TODO complete all field of the license
   // License license = new License();
   // license.setCustomerCode(systemParams.getParam(SystemParams.Keys.CONFIG_COMMON_CUSTOMER_CODE));
   // license.setCSCode(systemParams.getParam(SystemParams.Keys.CONFIG_COMMON_CS_CODE));
   // license.setCRCLogo("00000000");
   // license.setExpirationDate(calculateCaducation());
   // license.setInstallCode(codeGenerator.generateInstalationNumber());
   // return license;
   // }
}