-
-
Save schatterjee4/e3fb6b60ac3d382e747bf3135d1421ef to your computer and use it in GitHub Desktop.
Coordinating session timeout from Spring MVC (embedded Tomcat with Spring Boot) to AngularJS REST invocations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('App', []) | |
.factory('sessionTimeoutInterceptor', function($log, $window) { | |
return { | |
response: function(response){ | |
if (response.headers('x-login') === 'true') { | |
$log.debug('Intercepted login redirect', response); | |
$window.location.reload(); | |
} | |
return response; | |
} | |
} | |
}) | |
.config(function($httpProvider){ | |
$httpProvider.interceptors.push('sessionTimeoutInterceptor'); | |
}) | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class ViewController { | |
@RequestMapping("/") | |
String index() { | |
return "index"; | |
} | |
@RequestMapping("/login") | |
ModelAndView loginPage(HttpServletRequest request, HttpServletResponse response, Model model) { | |
response.addHeader("x-login", "true"); | |
CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class | |
.getName()); | |
final ModelAndView modelAndView = new ModelAndView() | |
.addObject("csrf", csrf); | |
modelAndView.setViewName("login"); | |
return modelAndView; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment