Browse Source

Merge branch 'dev' of ssh://10.10.101.21/source/sso-parent into hotfix-partner-wangmh

wangmh 7 years ago
parent
commit
95bb7be305

+ 4 - 0
sso-manage-console/build.gradle

@@ -34,6 +34,10 @@ dependencies {
   compile('commons-codec:commons-codec:1.11')
   compile("mysql:mysql-connector-java:5.1.41")
   compile("com.alibaba:druid:1.1.6")
+  compile("net.sf.ehcache:ehcache:2.10.3")
+  compile("org.hibernate:hibernate-ehcache") {
+    exclude(group: 'net.sf.ehcache', module: 'ehcache-core')
+  }
 
   testCompile('org.springframework.boot:spring-boot-starter-test')
 }

+ 34 - 0
sso-manage-console/src/main/java/com/uas/sso/sso/backend/CacheConfiguration.java

@@ -0,0 +1,34 @@
+package com.uas.sso.sso.backend;
+
+import org.springframework.beans.factory.annotation.Configurable;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.cache.ehcache.EhCacheCacheManager;
+import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.io.ClassPathResource;
+
+/**
+ * @author wangmh
+ * @create 2018-07-05 20:04
+ * @desc
+ **/
+@Configurable
+@EnableCaching
+public class CacheConfiguration {
+
+    @Bean
+    public EhCacheManagerFactoryBean ehCacheManagerFactoryBean() {
+        EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
+        ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource(
+                "spring/ehcache.xml"));
+        ehCacheManagerFactoryBean.setShared(true);
+        return ehCacheManagerFactoryBean;
+    }
+
+    @Bean
+    public EhCacheCacheManager cacheManager() {
+        EhCacheCacheManager cacheManager = new EhCacheCacheManager();
+        cacheManager.setCacheManager(ehCacheManagerFactoryBean().getObject());
+        return cacheManager;
+    }
+}

+ 3 - 1
sso-manage-console/src/main/java/com/uas/sso/sso/backend/api/AppealBackendController.java

@@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Optional;
+
 /**
  * Api interface implementations for managing appeal.
  *
@@ -39,7 +41,7 @@ public class AppealBackendController {
             @RequestParam(required = false) String keyword) {
 
         return new ResultBean<>(
-                appealService.showAppealsByPagination(page, type, fromApp, status, key, keyword));
+                appealService.showAppealsByPagination(page, type, fromApp, status, key, Optional.ofNullable(keyword).map(String::trim).orElse(null)));
     }
 
     @RequestMapping(method = RequestMethod.PUT, path = "/{appealId}/approveAppealRequest",

+ 3 - 1
sso-manage-console/src/main/java/com/uas/sso/sso/backend/api/UserManageController.java

@@ -8,6 +8,8 @@ import com.uas.sso.sso.backend.dto.UpdateUserInfo;
 import com.uas.sso.sso.backend.service.UserBackendService;
 import com.uas.sso.sso.backend.support.ResultBean;
 import java.util.List;
+import java.util.Optional;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Pageable;
 import org.springframework.http.MediaType;
@@ -45,7 +47,7 @@ public class UserManageController {
             @RequestParam(required = false) String keyword) {
         // Controller中的Pageable类型参数默认根据查询参数 page 和 size 注入并实例化
         return new ResultBean<>(
-                userBackendService.showUserByPagination(page, fromApp, mobileValidCode, identityValidCode, key, keyword));
+                userBackendService.showUserByPagination(page, fromApp, mobileValidCode, identityValidCode, key, Optional.ofNullable(keyword).map(String::trim).orElse(null)));
     }
 
     @RequestMapping(method = RequestMethod.GET, path = "//showEnUserByPagination",

+ 2 - 1
sso-manage-console/src/main/java/com/uas/sso/sso/backend/api/UserSpaceManageController.java

@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
+import java.util.Optional;
 
 /**
  * Api interface implementations for managing user space.
@@ -41,7 +42,7 @@ public class UserSpaceManageController {
             @RequestParam(required = false) String key,
             @RequestParam(required = false) String keyword) {
 
-        return new ResultBean<>(spaceService.showSpaceByPagination(page, validCode, fromApp, key, keyword));
+        return new ResultBean<>(spaceService.showSpaceByPagination(page, validCode, fromApp, key, Optional.ofNullable(keyword).map(String::trim).orElse(null)));
     }
 
     @RequestMapping(method = RequestMethod.PUT, path = "//modifySpaceInfo",

+ 2 - 3
sso-manage-console/src/main/java/com/uas/sso/sso/backend/service/impl/UserBackendServiceImpl.java

@@ -263,9 +263,8 @@ public class UserBackendServiceImpl implements UserBackendService {
         user.setEmailValidCode((short) Status.NOT_APPLYING.getCode());
         user.setIdentityValidCode((short) Status.NOT_APPLYING.getCode());
         user.setPassword(InfoAsyncUtils.encryptePassword(Const.ENCRY_FORMAT, user.getPassword(), user.getSalt()));
-        user.setUserRecord(new UserRecord());
-        user.getUserRecord().setUser(user);
-        user.getUserRecord().setUserUU(user.getUserUU());
+        UserRecord userRecord = new UserRecord(user.getUserUU());
+        userRecordDao.save(userRecord);
         user.setFromApp("sso");
         userDao.save(user);
 

+ 1 - 1
sso-manage-console/src/main/java/com/uas/sso/sso/backend/service/impl/UserSpaceServiceImpl.java

@@ -136,7 +136,7 @@ public class UserSpaceServiceImpl implements UserSpaceService {
             }
         }
 
-        if (!spaceInfo.getBusinessCode().equals(userspace.getBusinessCode())) {
+        if (spaceInfo.getBusinessCode() != null && !spaceInfo.getBusinessCode().equals(userspace.getBusinessCode())) {
             Userspace oldSpace = userspaceDao.findByBusinessCode(spaceInfo.getBusinessCode());
             if (oldSpace != null) {
                 throw new ValidationFailedException(String.format("企业营业执照号'%s'已被注册,请确认 ", spaceInfo.getBusinessCode()));

+ 11 - 0
sso-manage-console/src/main/resources/application.yml

@@ -15,6 +15,17 @@ spring:
   jpa:
     database: mysql
     show-sql: false
+    properties:
+      javax:
+        persistence:
+          sharedCache:
+            mode: ENABLE_SELECTIVE
+      hibernate:
+        cache:
+          use_second_level_cache: true
+          use_query_cache: true
+          region:
+            factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
   thymeleaf:
     mode: LEGACYHTML5
 # 避免自动建表更新账户中心的数据库结构

+ 25 - 9
sso-server/src/main/java/com/uas/sso/controller/AppealController.java

@@ -1,24 +1,16 @@
 package com.uas.sso.controller;
 
-import com.alibaba.fastjson.JSON;
-import com.uas.sso.SSOHelper;
-import com.uas.sso.SSOToken;
 import com.uas.sso.entity.*;
-import com.uas.sso.exception.AccountException;
 import com.uas.sso.exception.VisibleError;
 import com.uas.sso.service.*;
-import com.uas.sso.support.SystemSession;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.ModelMap;
-import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.Optional;
-
-
 /**
  * @author wangmh
  * @create 2018-01-16 8:50
@@ -48,6 +40,9 @@ public class AppealController extends BaseController {
      */
     @RequestMapping(value = "/check/mobile", method = RequestMethod.GET)
     public ModelMap checkMobile(String mobile) {
+        if (StringUtils.isEmpty(mobile)) {
+            return error("手机号不能为空");
+        }
         String token = getMobileToken(mobile);
         ModelMap data = new ModelMap("token", token);
         data.put("code", request.getSession().getAttribute("code"));
@@ -87,14 +82,34 @@ public class AppealController extends BaseController {
      */
     @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
     public ModelMap resetPwd(Appeal appeal, @RequestParam String token, String code, String password, @RequestParam(defaultValue = "sso") String appId) {
+        checkAppeal(appeal);
         // 校验验证码
         checkMobileCode(token, appeal.getMobile(), code);
         appealService.submitResetPwd(appId, appeal, password);
         return success();
     }
 
+    private void checkAppeal(Appeal appeal) {
+        if (StringUtils.isEmpty(appeal.getMobile())) {
+            throw new VisibleError("手机号不能为空");
+        }
+        if (StringUtils.isEmpty(appeal.getDescription())) {
+            throw new VisibleError("申述说明不能为空");
+        }
+        if (StringUtils.isEmpty(appeal.getContactName())) {
+            throw new VisibleError("姓名不能为空");
+        }
+        if (StringUtils.isEmpty(appeal.getContactTel())) {
+            throw new VisibleError("联系电话不能为空");
+        }
+        if (StringUtils.isEmpty(appeal.getContactEmail())) {
+            throw new VisibleError("电子邮箱不能为空");
+        }
+    }
+
     @RequestMapping(value = "/changeAdmin", method = RequestMethod.POST)
     public ModelMap changeAdmin(Appeal appeal, @RequestParam String token, String code, Userspace userspace, @RequestParam(defaultValue = "sso") String appId) {
+        checkAppeal(appeal);
         // 校验验证码
         checkMobileCode(token, appeal.getMobile(), code);
 
@@ -119,6 +134,7 @@ public class AppealController extends BaseController {
      */
     @RequestMapping(value = "/account", method = RequestMethod.POST)
     public ModelMap validAccount(Appeal appeal, String token, String code, String password, @RequestParam(defaultValue = "sso") String appId) {
+        checkAppeal(appeal);
         // 校验token
         Token existToken = tokenService.findOne(token);
         if (existToken == null || existToken.isExpired()) {

+ 4 - 3
sso-server/src/main/java/com/uas/sso/entity/Userspace.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.annotation.JSONField;
 import java.io.Serializable;
 import java.sql.Timestamp;
 import java.util.List;
+import java.util.Optional;
 import javax.persistence.*;
 
 import com.uas.sso.core.Const;
@@ -280,7 +281,7 @@ public class Userspace implements Serializable {
     }
 
     public String getSpaceName() {
-        if (spaceName.contains(Const.REPEAT_SEPARATOR)) {
+        if (spaceName != null && spaceName.contains(Const.REPEAT_SEPARATOR)) {
             return spaceName.substring(0, spaceName.indexOf(Const.REPEAT_SEPARATOR));
         }
         return spaceName;
@@ -331,7 +332,7 @@ public class Userspace implements Serializable {
     }
 
     public String getBusinessCode() {
-        if (businessCode.contains(Const.REPEAT_SEPARATOR)) {
+        if (businessCode != null && businessCode.contains(Const.REPEAT_SEPARATOR)) {
             return businessCode.substring(0, businessCode.indexOf(Const.REPEAT_SEPARATOR));
         }
         return businessCode;
@@ -588,7 +589,7 @@ public class Userspace implements Serializable {
         userSpaceView.setSpaceUU(this.getSpaceUU());
         userSpaceView.setSpaceName(this.getSpaceName());
         userSpaceView.setCorporation(this.getCorporation());
-        userSpaceView.setRegisterDate(this.getRegisterDate().getTime());
+        userSpaceView.setRegisterDate(Optional.ofNullable(registerDate).map(Timestamp::getTime).orElse(null));
         userSpaceView.setAdmin(this.getAdmin().toView());
         userSpaceView.setAdminUU(this.getAdminUU());
         userSpaceView.setBusinessCode(this.getBusinessCode());