deason 7 years ago
parent
commit
e90d010bf8

+ 6 - 1
src/main/java/cn/com/qmth/examcloud/app/controller/version_1_0/UserAuthRestController.java

@@ -7,13 +7,16 @@
 
 
 package cn.com.qmth.examcloud.app.controller.version_1_0;
 package cn.com.qmth.examcloud.app.controller.version_1_0;
 
 
+import cn.com.qmth.examcloud.app.core.utils.StrUtils;
 import cn.com.qmth.examcloud.app.model.LoginType;
 import cn.com.qmth.examcloud.app.model.LoginType;
 import cn.com.qmth.examcloud.app.model.Result;
 import cn.com.qmth.examcloud.app.model.Result;
 import cn.com.qmth.examcloud.app.model.UserInfo;
 import cn.com.qmth.examcloud.app.model.UserInfo;
+import cn.com.qmth.examcloud.app.model.UserToken;
 import cn.com.qmth.examcloud.app.service.RedisService;
 import cn.com.qmth.examcloud.app.service.RedisService;
 import cn.com.qmth.examcloud.app.service.UserAuthService;
 import cn.com.qmth.examcloud.app.service.UserAuthService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,6 +24,8 @@ import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 
 
+import static cn.com.qmth.examcloud.app.model.Constants.APP_SESSION_EXPIRE_TIME;
+
 /**
 /**
  * 认证中心相关接口
  * 认证中心相关接口
  *
  *
@@ -42,7 +47,7 @@ public class UserAuthRestController {
     @RequestMapping(value = "/user/login", method = {RequestMethod.GET, RequestMethod.POST})
     @RequestMapping(value = "/user/login", method = {RequestMethod.GET, RequestMethod.POST})
     public Result<UserInfo> login(@RequestParam String account, @RequestParam String password, @RequestParam(required = false) String accountType,
     public Result<UserInfo> login(@RequestParam String account, @RequestParam String password, @RequestParam(required = false) String accountType,
                                   @RequestParam(required = false) Long rootOrgId, @RequestParam(required = false) String domain) throws Exception {
                                   @RequestParam(required = false) Long rootOrgId, @RequestParam(required = false) String domain) throws Exception {
-        if (accountType == null) {
+        if (StringUtils.isBlank(accountType)) {
             accountType = LoginType.COMMON_LOGIN_NAME.name();
             accountType = LoginType.COMMON_LOGIN_NAME.name();
         }
         }
         Result<UserInfo> result = userAuthService.login(account, password, accountType, rootOrgId, domain);
         Result<UserInfo> result = userAuthService.login(account, password, accountType, rootOrgId, domain);

+ 4 - 1
src/main/java/cn/com/qmth/examcloud/app/core/config/AccessInterceptor.java

@@ -8,6 +8,9 @@
 package cn.com.qmth.examcloud.app.core.config;
 package cn.com.qmth.examcloud.app.core.config;
 
 
 import cn.com.qmth.examcloud.app.model.DeviceRecord;
 import cn.com.qmth.examcloud.app.model.DeviceRecord;
+import cn.com.qmth.examcloud.app.model.Result;
+import cn.com.qmth.examcloud.app.model.UserInfo;
+import cn.com.qmth.examcloud.app.model.UserToken;
 import cn.com.qmth.examcloud.app.service.DeviceRecordService;
 import cn.com.qmth.examcloud.app.service.DeviceRecordService;
 import cn.com.qmth.examcloud.app.service.RedisService;
 import cn.com.qmth.examcloud.app.service.RedisService;
 import cn.com.qmth.examcloud.app.service.UserAuthService;
 import cn.com.qmth.examcloud.app.service.UserAuthService;
@@ -22,7 +25,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.util.Date;
 import java.util.Date;
 import java.util.Map;
 import java.util.Map;
 
 
-import static cn.com.qmth.examcloud.app.model.Constants.PARAM_PASSWORD;
+import static cn.com.qmth.examcloud.app.model.Constants.*;
 
 
 /**
 /**
  * @author: fengdesheng
  * @author: fengdesheng

+ 6 - 5
src/main/java/cn/com/qmth/examcloud/app/service/RedisService.java

@@ -12,6 +12,7 @@ import cn.com.qmth.examcloud.app.core.utils.JsonMapper;
 import cn.com.qmth.examcloud.app.core.utils.ThreadUtils;
 import cn.com.qmth.examcloud.app.core.utils.ThreadUtils;
 import cn.com.qmth.examcloud.app.model.Constants;
 import cn.com.qmth.examcloud.app.model.Constants;
 import cn.com.qmth.examcloud.app.model.UserToken;
 import cn.com.qmth.examcloud.app.model.UserToken;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -61,8 +62,8 @@ public class RedisService {
      * 缓存用户登录信息
      * 缓存用户登录信息
      */
      */
     public void cacheUserToken(String key, UserToken value, long seconds) {
     public void cacheUserToken(String key, UserToken value, long seconds) {
-        if (key == null) {
-            throw new ApiException("Key must be not null.");
+        if (StringUtils.isEmpty(key)) {
+            throw new ApiException("Key must be not empty.");
         }
         }
         this.set(APP_SESSION_USER_KEY_PREFIX + key, new JsonMapper().toJson(value), seconds);
         this.set(APP_SESSION_USER_KEY_PREFIX + key, new JsonMapper().toJson(value), seconds);
     }
     }
@@ -71,8 +72,8 @@ public class RedisService {
      * 获取缓存中的用户登录信息
      * 获取缓存中的用户登录信息
      */
      */
     public UserToken getUserToken(String key) {
     public UserToken getUserToken(String key) {
-        if (key == null) {
-            throw new ApiException("Key must be not null.");
+        if (StringUtils.isEmpty(key)) {
+            throw new ApiException("Key must be not empty.");
         }
         }
         String value = this.get(APP_SESSION_USER_KEY_PREFIX + key);
         String value = this.get(APP_SESSION_USER_KEY_PREFIX + key);
         if (value != null) {
         if (value != null) {
@@ -96,7 +97,7 @@ public class RedisService {
     public int getSessionTimeout() {
     public int getSessionTimeout() {
         try {
         try {
             String timeout = this.get(Constants.PLATFORM_SESSION_TIMEOUT_KEY);
             String timeout = this.get(Constants.PLATFORM_SESSION_TIMEOUT_KEY);
-            if (timeout != null) {
+            if (StringUtils.isNotEmpty(timeout)) {
                 return Integer.parseInt(timeout);
                 return Integer.parseInt(timeout);
             }
             }
         } catch (Exception e) {
         } catch (Exception e) {