-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
crivera
committed
Aug 15, 2016
1 parent
c5e31c1
commit bf183e1
Showing
21 changed files
with
22,772 additions
and
90 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.config; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.servlet.ModelAndView; | ||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | ||
|
||
import com.model.User; | ||
import com.utils.Constants; | ||
|
||
public class WebHandlerInterceptor extends HandlerInterceptorAdapter { | ||
|
||
/** | ||
* | ||
* @param env | ||
* @param userService | ||
*/ | ||
public WebHandlerInterceptor() { | ||
|
||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* | ||
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter# | ||
* preHandle(javax.servlet.http .HttpServletRequest, | ||
* javax.servlet.http.HttpServletResponse, java.lang.Object) | ||
*/ | ||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) | ||
throws Exception { | ||
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ||
if (auth != null && (auth.getPrincipal() instanceof User)) { | ||
User user = (User) auth.getPrincipal(); | ||
request.setAttribute(Constants.TOKEN, user.getToken()); | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, | ||
ModelAndView modelAndView) throws Exception { | ||
super.postHandle(request, response, handler, modelAndView); | ||
} | ||
|
||
} |
Oops, something went wrong.