Compare commits
No commits in common. "7fd71ca8aa3cffe4e05e30ed42f23112fae29bc9" and "70c329a5ccb5455309c4839d68f09ed49550d13f" have entirely different histories.
7fd71ca8aa
...
70c329a5cc
@ -19,6 +19,4 @@ public interface ISmsBaseService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getVerifyCode(String phone);
|
String getVerifyCode(String phone);
|
||||||
|
|
||||||
void checkVerifyCode(String phone, String code);
|
|
||||||
}
|
}
|
||||||
|
@ -23,28 +23,4 @@ public class FolderUtil {
|
|||||||
}
|
}
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除文件
|
|
||||||
*
|
|
||||||
* @param path
|
|
||||||
*/
|
|
||||||
public static void delete(String path) {
|
|
||||||
File file = new File(path);
|
|
||||||
if (!file.exists()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (file.isFile()) {
|
|
||||||
file.delete();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File[] subFiles = file.listFiles();
|
|
||||||
if (subFiles != null) {
|
|
||||||
for (File subFile : subFiles) {
|
|
||||||
delete(subFile.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ public class WStringUtil {
|
|||||||
* @date 2018年2月28日 下午4:28:45
|
* @date 2018年2月28日 下午4:28:45
|
||||||
*/
|
*/
|
||||||
public static String lowerUpper2UnderLine(String str) {
|
public static String lowerUpper2UnderLine(String str) {
|
||||||
return lowerUpper2Separator(str, "_");
|
return lowerUpper2Separator(str, "-");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,11 +77,6 @@
|
|||||||
<artifactId>spring-security-web</artifactId>
|
<artifactId>spring-security-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- spring end -->
|
<!-- spring end -->
|
||||||
<dependency>
|
|
||||||
<groupId>com.auth0</groupId>
|
|
||||||
<artifactId>java-jwt</artifactId>
|
|
||||||
<version>4.2.1</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ public class ResponseAdvice {
|
|||||||
}
|
}
|
||||||
String contentType = request.getContentType();
|
String contentType = request.getContentType();
|
||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
if ((requestURI.contains("/api/") || requestURI.contains("/app/")) || (contentType != null && contentType.contains(MediaType.APPLICATION_JSON_VALUE))) {
|
if ((requestURI.contains("/app/")) || (contentType != null && contentType.contains(MediaType.APPLICATION_JSON_VALUE))) {
|
||||||
response.setCharacterEncoding(ISystemConstant.CHARSET_UTF8);
|
response.setCharacterEncoding(ISystemConstant.CHARSET_UTF8);
|
||||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
response.setStatus(HttpStatus.BAD_REQUEST.value());
|
response.setStatus(HttpStatus.BAD_REQUEST.value());
|
||||||
|
@ -74,14 +74,6 @@ public class EnvManager {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue(String key, String defaultValue) {
|
|
||||||
String value = getValue(key);
|
|
||||||
if (StringUtils.isBlank(value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String value(String key) {
|
public static String value(String key) {
|
||||||
String value = getInstance().getValue(key);
|
String value = getInstance().getValue(key);
|
||||||
if (StringUtils.isBlank(value)) {
|
if (StringUtils.isBlank(value)) {
|
||||||
@ -90,10 +82,6 @@ public class EnvManager {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String value(String key, String defaultValue) {
|
|
||||||
return getInstance().getValue(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnvDao(IEnvDao envDao) {
|
public void setEnvDao(IEnvDao envDao) {
|
||||||
this.envDao = envDao;
|
this.envDao = envDao;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import ink.wgink.interfaces.sms.ISmsBaseService;
|
|||||||
import ink.wgink.login.app.pojo.vos.appsign.AppLoginDefaultVO;
|
import ink.wgink.login.app.pojo.vos.appsign.AppLoginDefaultVO;
|
||||||
import ink.wgink.login.app.pojo.vos.appsign.AppLoginPhoneVO;
|
import ink.wgink.login.app.pojo.vos.appsign.AppLoginPhoneVO;
|
||||||
import ink.wgink.login.app.service.appsign.IAppSignService;
|
import ink.wgink.login.app.service.appsign.IAppSignService;
|
||||||
import ink.wgink.login.base.exceptions.UserAuthenticationException;
|
|
||||||
import ink.wgink.pojo.result.ErrorResult;
|
import ink.wgink.pojo.result.ErrorResult;
|
||||||
import ink.wgink.pojo.result.SuccessResultData;
|
import ink.wgink.pojo.result.SuccessResultData;
|
||||||
import ink.wgink.util.RegexUtil;
|
import ink.wgink.util.RegexUtil;
|
||||||
@ -63,7 +62,13 @@ public class AppSignAppController extends DefaultBaseController {
|
|||||||
if (!RegexUtil.isPhone(appLoginPhoneVO.getUsername())) {
|
if (!RegexUtil.isPhone(appLoginPhoneVO.getUsername())) {
|
||||||
throw new ParamsException("用户名非手机格式");
|
throw new ParamsException("用户名非手机格式");
|
||||||
}
|
}
|
||||||
smsBaseService.checkVerifyCode(appLoginPhoneVO.getUsername(), appLoginPhoneVO.getVerificationCode());
|
String verifyCode = smsBaseService.getVerifyCode(appLoginPhoneVO.getUsername());
|
||||||
|
if (StringUtils.isBlank(verifyCode)) {
|
||||||
|
throw new ParamsException("未发送验证码");
|
||||||
|
}
|
||||||
|
if (!StringUtils.equalsIgnoreCase(verifyCode, appLoginPhoneVO.getVerificationCode())) {
|
||||||
|
throw new ParamsException("验证码错误");
|
||||||
|
}
|
||||||
return new SuccessResultData<>(appSignService.phoneSign(appLoginPhoneVO));
|
return new SuccessResultData<>(appSignService.phoneSign(appLoginPhoneVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,6 @@ public class UserLoginService {
|
|||||||
private void updateLoginInfo(String userId, String address, String currentTime) throws UpdateException {
|
private void updateLoginInfo(String userId, String address, String currentTime) throws UpdateException {
|
||||||
Map<String, Object> params = new HashMap<>(10);
|
Map<String, Object> params = new HashMap<>(10);
|
||||||
params.put("userId", userId);
|
params.put("userId", userId);
|
||||||
params.put("userState", 0);
|
|
||||||
params.put("lastLoginAddress", address);
|
params.put("lastLoginAddress", address);
|
||||||
params.put("lastLoginTime", currentTime);
|
params.put("lastLoginTime", currentTime);
|
||||||
params.put("gmtModified", currentTime);
|
params.put("gmtModified", currentTime);
|
||||||
|
@ -5,8 +5,6 @@ import ink.wgink.exceptions.SearchException;
|
|||||||
import ink.wgink.login.oauth2.client.auth.UserTokenManager;
|
import ink.wgink.login.oauth2.client.auth.UserTokenManager;
|
||||||
import ink.wgink.login.oauth2.client.auth.manager.UserToken;
|
import ink.wgink.login.oauth2.client.auth.manager.UserToken;
|
||||||
import ink.wgink.pojo.bos.UserInfoBO;
|
import ink.wgink.pojo.bos.UserInfoBO;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -28,9 +26,9 @@ import java.io.IOException;
|
|||||||
|
|
||||||
@Order(value = Ordered.HIGHEST_PRECEDENCE)
|
@Order(value = Ordered.HIGHEST_PRECEDENCE)
|
||||||
@Component
|
@Component
|
||||||
@WebFilter(filterName = "UserTokenFilter", urlPatterns = "/*")
|
@WebFilter(filterName = "ContentCachingFilter", urlPatterns = "/*")
|
||||||
public class UserTokenFilter extends OncePerRequestFilter {
|
public class UserTokenFilter extends OncePerRequestFilter {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(UserTokenFilter.class);
|
|
||||||
private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();
|
private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -39,7 +37,7 @@ public class UserTokenFilter extends OncePerRequestFilter {
|
|||||||
String source = request.getHeader("X-SOURCE");
|
String source = request.getHeader("X-SOURCE");
|
||||||
if (StringUtils.isBlank(userId)) {
|
if (StringUtils.isBlank(userId)) {
|
||||||
Object springSecurityContext = request.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
|
Object springSecurityContext = request.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
|
||||||
if (!StringUtils.equals(source, "page")) {
|
if(!StringUtils.equals(source, "page")) {
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -54,9 +52,7 @@ public class UserTokenFilter extends OncePerRequestFilter {
|
|||||||
UserTokenManager userTokenManager = UserTokenManager.getInstance();
|
UserTokenManager userTokenManager = UserTokenManager.getInstance();
|
||||||
UserToken userToken = userTokenManager.get(userId);
|
UserToken userToken = userTokenManager.get(userId);
|
||||||
if (userToken == null) {
|
if (userToken == null) {
|
||||||
LOG.error("用户未登录,userId异常");
|
throw new SearchException("用户未登录,userId异常");
|
||||||
response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
UserInfoBO userInfo = userToken.getUserInfo();
|
UserInfoBO userInfo = userToken.getUserInfo();
|
||||||
userTokenManager.refresh(userInfo, userToken.getGrantedAuthorities());
|
userTokenManager.refresh(userInfo, userToken.getGrantedAuthorities());
|
||||||
|
@ -1,81 +0,0 @@
|
|||||||
package ink.wgink.module.oauth2.filter;
|
|
||||||
|
|
||||||
import ink.wgink.exceptions.SearchException;
|
|
||||||
import ink.wgink.pojo.bos.RoleGrantedAuthorityBO;
|
|
||||||
import ink.wgink.pojo.bos.UserInfoBO;
|
|
||||||
import org.jsoup.internal.StringUtil;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.Ordered;
|
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
import org.springframework.security.core.context.SecurityContext;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolderStrategy;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
|
||||||
|
|
||||||
import javax.servlet.FilterChain;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.annotation.WebFilter;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Order(value = Ordered.HIGHEST_PRECEDENCE)
|
|
||||||
@Component
|
|
||||||
@WebFilter(filterName = "AccessTokenFilter", urlPatterns = "/*")
|
|
||||||
public class AccessTokenFilter extends OncePerRequestFilter {
|
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AccessTokenFilter.class);
|
|
||||||
@Autowired(required = false)
|
|
||||||
private IAccessTokenCheckFilter accessTokenCheckFilter;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
|
||||||
if (accessTokenCheckFilter == null) {
|
|
||||||
filterChain.doFilter(request, response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String authorization = request.getHeader("Auth");
|
|
||||||
if (StringUtil.isBlank(authorization)) {
|
|
||||||
filterChain.doFilter(request, response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!authorization.startsWith("Bearer ")) {
|
|
||||||
LOG.error("用户未登录,authorization异常");
|
|
||||||
response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
|
||||||
}
|
|
||||||
String accessToken = authorization.replace("Bearer ", "");
|
|
||||||
UserInfoBO userInfo = accessTokenCheckFilter.getUserInfo(accessToken);
|
|
||||||
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
|
|
||||||
userInfo.getRoles().forEach(role -> {
|
|
||||||
RoleGrantedAuthorityBO roleGrantedAuthorityBO = new RoleGrantedAuthorityBO(role.getRoleId(), role.getRoleName(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
|
||||||
grantedAuthorities.add(roleGrantedAuthorityBO);
|
|
||||||
});
|
|
||||||
UsernamePasswordAuthenticationToken userAuthenticationTokenResult = new UsernamePasswordAuthenticationToken(userInfo, null, grantedAuthorities);
|
|
||||||
SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder.getContextHolderStrategy();
|
|
||||||
SecurityContext context = securityContextHolderStrategy.createEmptyContext();
|
|
||||||
context.setAuthentication(userAuthenticationTokenResult);
|
|
||||||
securityContextHolderStrategy.setContext(context);
|
|
||||||
request.getSession().setAttribute("SPRING_SECURITY_CONTEXT", context);
|
|
||||||
filterChain.doFilter(request, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AccessToken校验过滤器
|
|
||||||
*/
|
|
||||||
public interface IAccessTokenCheckFilter {
|
|
||||||
|
|
||||||
UserInfoBO getUserInfo(String accessToken);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -274,11 +274,6 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
|
|||||||
return VerifyCodeManager.getInstance().getVerifyCode(phone);
|
return VerifyCodeManager.getInstance().getVerifyCode(phone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void checkVerifyCode(String phone, String code) {
|
|
||||||
VerifyCodeManager.getInstance().checkVerifyCode(phone, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置用户
|
* 设置用户
|
||||||
*
|
*
|
||||||
|
@ -13,7 +13,6 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName: RedisFilesShowCodeServiceImpl
|
* @ClassName: RedisFilesShowCodeServiceImpl
|
||||||
@ -37,15 +36,12 @@ public class RedisFilesShowCodeService implements IFilesShowCodeService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearTimeoutShowCode() {
|
public void clearTimeoutShowCode() {
|
||||||
Set<String> keySet = redisTemplate.keys(FILE_SHOW_CODE_KEY + "**");
|
Set<String> keySet = redisTemplate.keys(FILE_SHOW_CODE_KEY);
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
Set<String> clearKeys = new HashSet<>(16);
|
Set<String> clearKeys = new HashSet<>(16);
|
||||||
long clearTimeoutShowCodeCount = 0;
|
long clearTimeoutShowCodeCount = 0;
|
||||||
for (String key : keySet) {
|
for (String key : keySet) {
|
||||||
FilesShowCode showCode = (FilesShowCode) redisTemplate.opsForValue().get(key);
|
FilesShowCode showCode = getShowCode(key);
|
||||||
if (showCode == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (currentTimeMillis - showCode.getLatestUpdateTime() > SHOW_CODE_TIMEOUT_MILLIS) {
|
if (currentTimeMillis - showCode.getLatestUpdateTime() > SHOW_CODE_TIMEOUT_MILLIS) {
|
||||||
clearKeys.add(FILE_SHOW_CODE_KEY + showCode.getFileId());
|
clearKeys.add(FILE_SHOW_CODE_KEY + showCode.getFileId());
|
||||||
}
|
}
|
||||||
@ -70,7 +66,8 @@ public class RedisFilesShowCodeService implements IFilesShowCodeService {
|
|||||||
public synchronized FilesShowCode getShowCode(String fileId) {
|
public synchronized FilesShowCode getShowCode(String fileId) {
|
||||||
FilesShowCode showCode = (FilesShowCode) redisTemplate.opsForValue().get(FILE_SHOW_CODE_KEY + fileId);
|
FilesShowCode showCode = (FilesShowCode) redisTemplate.opsForValue().get(FILE_SHOW_CODE_KEY + fileId);
|
||||||
if (showCode != null) {
|
if (showCode != null) {
|
||||||
redisTemplate.opsForValue().set(FILE_SHOW_CODE_KEY + fileId, showCode, 1, TimeUnit.MINUTES);
|
showCode.setLatestUpdateTime(System.currentTimeMillis());
|
||||||
|
redisTemplate.opsForValue().set(FILE_SHOW_CODE_KEY + fileId, showCode);
|
||||||
}
|
}
|
||||||
return showCode;
|
return showCode;
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,13 @@ public class UserAppController extends DefaultBaseController {
|
|||||||
if (updatePhonePasswordVO.getNewPassword().length() < 6) {
|
if (updatePhonePasswordVO.getNewPassword().length() < 6) {
|
||||||
throw new ParamsException("新密码长度必须大于6位");
|
throw new ParamsException("新密码长度必须大于6位");
|
||||||
}
|
}
|
||||||
smsBaseService.checkVerifyCode(updatePhonePasswordVO.getPhone(), updatePhonePasswordVO.getVerificationCode());
|
String verifyCode = smsBaseService.getVerifyCode(updatePhonePasswordVO.getPhone());
|
||||||
|
if (StringUtils.isBlank(verifyCode)) {
|
||||||
|
throw new ParamsException("验证码为空");
|
||||||
|
}
|
||||||
|
if (!StringUtils.equalsIgnoreCase(verifyCode, updatePhonePasswordVO.getVerificationCode())) {
|
||||||
|
throw new ParamsException("验证码错误");
|
||||||
|
}
|
||||||
userService.updatePasswordByUsername(updatePhonePasswordVO.getPhone(), updatePhonePasswordVO.getNewPassword());
|
userService.updatePasswordByUsername(updatePhonePasswordVO.getPhone(), updatePhonePasswordVO.getNewPassword());
|
||||||
return new SuccessResult();
|
return new SuccessResult();
|
||||||
}
|
}
|
||||||
|
@ -230,9 +230,6 @@
|
|||||||
UPDATE
|
UPDATE
|
||||||
sys_user
|
sys_user
|
||||||
SET
|
SET
|
||||||
<if test="userState != null">
|
|
||||||
user_state = #{userState},
|
|
||||||
</if>
|
|
||||||
<if test="userLongitude != null and userLongitude != ''">
|
<if test="userLongitude != null and userLongitude != ''">
|
||||||
user_longitude = #{userLongitude},
|
user_longitude = #{userLongitude},
|
||||||
</if>
|
</if>
|
||||||
|
Loading…
Reference in New Issue
Block a user