鉴权逻辑更新.
This commit is contained in:
+1
@@ -37,6 +37,7 @@ public enum ExceptionConstant {
|
||||
PARAMS_INVALID(2, "参数不正确"),
|
||||
PARAMS_NOT_NULL(3, "参数[%s]不能为空"),
|
||||
USER_NAME_OR_PASSWORD_ERROR(4, "用户名或密码错误"),
|
||||
USER_DISBLE(5, "当前用户已被禁止登录"),
|
||||
SYSTEM_ERROR(500, "系统异常"),
|
||||
;
|
||||
|
||||
|
||||
+7
@@ -28,6 +28,7 @@ import fun.asgc.neutrino.core.web.context.HttpRequestWrapper;
|
||||
import fun.asgc.neutrino.core.web.context.HttpResponseWrapper;
|
||||
import fun.asgc.neutrino.core.web.interceptor.HandlerInterceptor;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.*;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
import fun.asgc.neutrino.proxy.server.service.UserService;
|
||||
@@ -58,8 +59,14 @@ public class BaseAuthInterceptor implements HandlerInterceptor {
|
||||
if (null == userDO) {
|
||||
throw ServiceException.create(ExceptionConstant.USER_NOT_LOGIN);
|
||||
}
|
||||
if (EnableStatusEnum.DISABLE.getStatus().equals(userDO.getEnable())) {
|
||||
throw ServiceException.create(ExceptionConstant.USER_DISBLE);
|
||||
}
|
||||
systemContext.setToken(authorize);
|
||||
systemContext.setUser(userDO);
|
||||
|
||||
// token续期
|
||||
BeanManager.getBean(UserService.class).updateTokenExpirationTime(authorize);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
+7
@@ -22,12 +22,16 @@
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
import fun.asgc.neutrino.core.db.annotation.Insert;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.core.db.annotation.Update;
|
||||
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
@@ -60,4 +64,7 @@ public interface UserTokenMapper extends SqlMapper {
|
||||
*/
|
||||
@Delete("delete from user_token where token = ?")
|
||||
void deleteByToken(String token);
|
||||
|
||||
@Update("update user_token set expiration_time = :expirationTime where token = :token")
|
||||
void updateTokenExpirationTime(@Param("token") String token, @Param("expirationTime") Date expirationTime);
|
||||
}
|
||||
|
||||
+4
@@ -51,6 +51,10 @@ public class UserDO {
|
||||
* 登录密码
|
||||
*/
|
||||
private String loginPassword;
|
||||
/**
|
||||
* 是否禁用
|
||||
*/
|
||||
private Integer enable;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
+6
-3
@@ -108,9 +108,12 @@ public class UserService {
|
||||
if (null == userTokenDO) {
|
||||
return null;
|
||||
}
|
||||
UserDO userDO = userMapper.findById(userTokenDO.getUserId());
|
||||
// TODO 校验用户是否已被禁用
|
||||
return userDO;
|
||||
return userMapper.findById(userTokenDO.getUserId());
|
||||
}
|
||||
|
||||
public void updateTokenExpirationTime(String token) {
|
||||
Date now = new Date();
|
||||
Date expirationTime = DateUtil.addDate(now, Calendar.HOUR, 1);
|
||||
userTokenMapper.updateTokenExpirationTime(token, expirationTime);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user