2 * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.akraino.validation.ui.common;
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
21 import org.apache.log4j.Logger;
22 import org.springframework.web.servlet.HandlerInterceptor;
23 import org.springframework.web.servlet.ModelAndView;
25 public class SessionManagerFilter implements HandlerInterceptor {
27 private static final Logger LOGGER = Logger.getLogger(SessionManagerFilter.class);
30 public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
33 LOGGER.info("user authenticated");
38 public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
41 LOGGER.info("user authenticated");
46 public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object data) throws Exception {
51 * if (StringUtil.notEmpty(req.getHeader("tokenId"))) {
53 * String clientToken = req.getHeader("tokenId");
55 * AccessService service = new AccessService();
57 * UserSession user = service.getUserSession(LoginUtil.decode(LoginUtil.getUserName(clientToken)));
59 * if (user.getTokenId()!= null && !sessionExpired(user)) {
61 * if (user.getTokenId().equals(LoginUtil.getPassword(clientToken))) { // user authorized return true;
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); }
66 * } else { // bad request, no authToken sent in the request res.sendError(400); }
68 } catch (Exception e) {