| | |
| | | package com.ruoyi.common.core.utils; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | import com.ruoyi.common.core.constant.CacheConstants; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static String getUsername() |
| | | { |
| | | return ServletUtils.getRequest().getHeader(CacheConstants.DETAILS_USERNAME); |
| | | String username = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USERNAME); |
| | | return ServletUtils.urlDecode(username); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static Long getUserId() |
| | | { |
| | | return Convert.toLong(ServletUtils.getRequest().getHeader(CacheConstants.DETAILS_USER_ID)); |
| | | return Convert.toLong(ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USER_ID)); |
| | | } |
| | | |
| | | /** |
| | | * 获取请求token |
| | | */ |
| | | public static String getToken() |
| | | { |
| | | return getToken(ServletUtils.getRequest()); |
| | | } |
| | | |
| | | /** |
| | | * 根据request获取请求token |
| | | */ |
| | | public static String getToken(HttpServletRequest request) |
| | | { |
| | | // 从header获取token标识 |
| | | String token = request.getHeader(SecurityConstants.TOKEN_AUTHENTICATION); |
| | | return replaceTokenPrefix(token); |
| | | } |
| | | |
| | | /** |
| | | * 裁剪token前缀 |
| | | */ |
| | | public static String replaceTokenPrefix(String token) |
| | | { |
| | | // 如果前端设置了令牌前缀,则裁剪掉前缀 |
| | | if (StringUtils.isNotEmpty(token) && token.startsWith(SecurityConstants.TOKEN_PREFIX)) |
| | | { |
| | | token = token.replaceFirst(SecurityConstants.TOKEN_PREFIX, ""); |
| | | } |
| | | return token; |
| | | } |
| | | |
| | | /** |