mirror of
https://github.com/201206030/novel-plus.git
synced 2025-07-03 07:56:38 +00:00
上传代码
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
package com.java2nb.novel.controller;
|
||||
|
||||
import com.java2nb.novel.core.bean.UserDetails;
|
||||
import com.java2nb.novel.core.utils.JwtTokenUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
public class BaseController {
|
||||
|
||||
protected JwtTokenUtil jwtTokenUtil;
|
||||
|
||||
|
||||
protected String getToken(HttpServletRequest request){
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if(cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (cookie.getName().equals("Authorization")) {
|
||||
return cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return request.getHeader("Authorization");
|
||||
}
|
||||
|
||||
protected UserDetails getUserDetails(HttpServletRequest request) {
|
||||
String token = getToken(request);
|
||||
if(StringUtils.isBlank(token)){
|
||||
return null;
|
||||
}else{
|
||||
return jwtTokenUtil.getUserDetailsFromToken(token);
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setJwtTokenUtil(JwtTokenUtil jwtTokenUtil) {
|
||||
this.jwtTokenUtil = jwtTokenUtil;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user