UI initial implementation.
[validation.git] / ui / src / main / java / org / akraino / validation / ui / common / SessionManagerFilter.java
1 /*
2  * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.akraino.validation.ui.common;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.apache.log4j.Logger;
22 import org.springframework.web.servlet.HandlerInterceptor;
23 import org.springframework.web.servlet.ModelAndView;
24
25 public class SessionManagerFilter implements HandlerInterceptor {
26
27     private static final Logger LOGGER = Logger.getLogger(SessionManagerFilter.class);
28
29     @Override
30     public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
31             throws Exception {
32
33         LOGGER.info("user authenticated");
34
35     }
36
37     @Override
38     public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
39             throws Exception {
40
41         LOGGER.info("user authenticated");
42
43     }
44
45     @Override
46     public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object data) throws Exception {
47
48         try {
49             return true;
50             /*
51              * if (StringUtil.notEmpty(req.getHeader("tokenId"))) {
52              *
53              * String clientToken = req.getHeader("tokenId");
54              *
55              * AccessService service = new AccessService();
56              *
57              * UserSession user = service.getUserSession(LoginUtil.decode(LoginUtil.getUserName(clientToken)));
58              *
59              * if (user.getTokenId()!= null && !sessionExpired(user)) {
60              *
61              * if (user.getTokenId().equals(LoginUtil.getPassword(clientToken))) { // user authorized return true;
62              *
63              * } else { // unauthorized access res.sendError(401); } } else { // session does not exist/expired,
64              * temporary re-direct, ask user to re-login res.sendError(307); }
65              *
66              * } else { // bad request, no authToken sent in the request res.sendError(400); }
67              */
68         } catch (Exception e) {
69             LOGGER.error(e);
70         }
71
72
73         return false;
74     }
75
76
77 }