1 package org.openkilda.controller;
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.boot.autoconfigure.web.ErrorController;
8 import org.springframework.security.authentication.AnonymousAuthenticationToken;
9 import org.springframework.security.core.Authentication;
10 import org.springframework.security.core.context.SecurityContextHolder;
11 import org.springframework.ui.Model;
12 import org.springframework.web.bind.annotation.RequestMapping;
13 import org.springframework.web.servlet.ModelAndView;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpSession;
26 private static final Logger LOGGER = LoggerFactory.getLogger(
BaseController.class);
46 final String viewName) {
47 ModelAndView modelAndView;
50 LOGGER.info(
"[validateAndRedirect] Logged in user. view name: " + viewName +
", User name: " + userInfo.
getName());
52 modelAndView =
new ModelAndView(viewName);
54 LOGGER.error(
"[validateAndRedirect] User in not logged in, redirected to login page. Requested view name: " + viewName);
66 @RequestMapping(
"/403")
67 public ModelAndView
error(final Model model) {
77 @RequestMapping(
"/error")
89 HttpSession session = request.getSession();
93 }
catch (IllegalStateException ex) {
95 "[getLoggedInUser] Exception while retrieving user information from session. Exception: " 96 + ex.getLocalizedMessage(),
99 if (userInfo == null) {
100 session = request.getSession(
false);
115 Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
116 if (null != authentication) {
117 boolean isValid = (authentication.isAuthenticated()
118 && !(authentication instanceof AnonymousAuthenticationToken));
121 userEntity = userRepository.findByUserId(userEntity.
getUserId());
StatusEntity getStatusEntity()
ModelAndView error(final Model model)
static final String ERROR
static final String SESSION_OBJECT
ModelAndView validateAndRedirect(final HttpServletRequest request, final String viewName)
UserInfo getLoggedInUser(final HttpServletRequest request)
static final String LOGIN
static final String ERROR_403