Browse Source

添加个人注册接口 日志框架

wangmh 8 years ago
parent
commit
6df49c91b2
39 changed files with 3393 additions and 3 deletions
  1. 6 0
      pom.xml
  2. 57 0
      sso-common/pom.xml
  3. 57 0
      sso-common/src/main/java/com/uas/sso/AccountConfig.java
  4. 63 0
      sso-common/src/main/java/com/uas/sso/ResultWrap.java
  5. 19 0
      sso-common/src/main/java/com/uas/sso/exception/AccountException.java
  6. 118 0
      sso-common/src/main/java/com/uas/sso/support/Page.java
  7. 1167 0
      sso-common/src/main/java/com/uas/sso/util/AccountUtils.java
  8. 95 0
      sso-common/src/main/java/com/uas/sso/util/BeanUtil.java
  9. 60 0
      sso-common/src/main/java/com/uas/sso/util/FlexJsonUtil.java
  10. 119 0
      sso-common/src/main/java/com/uas/sso/web/AccountConfigurer.java
  11. 13 3
      sso-server/pom.xml
  12. 122 0
      sso-server/src/main/java/com/uas/sso/controller/BaseController.java
  13. 77 0
      sso-server/src/main/java/com/uas/sso/controller/PersonalRegisterController.java
  14. 30 0
      sso-server/src/main/java/com/uas/sso/controller/UserManagerController.java
  15. 45 0
      sso-server/src/main/java/com/uas/sso/core/Const.java
  16. 35 0
      sso-server/src/main/java/com/uas/sso/core/Level.java
  17. 35 0
      sso-server/src/main/java/com/uas/sso/core/PasswordStrength.java
  18. 38 0
      sso-server/src/main/java/com/uas/sso/core/Status.java
  19. 55 0
      sso-server/src/main/java/com/uas/sso/core/Type.java
  20. 14 0
      sso-server/src/main/java/com/uas/sso/dao/RegisterLogDao.java
  21. 57 0
      sso-server/src/main/java/com/uas/sso/dao/UserDao.java
  22. 15 0
      sso-server/src/main/java/com/uas/sso/dao/UserLogDao.java
  23. 38 0
      sso-server/src/main/java/com/uas/sso/entity/App.java
  24. 17 0
      sso-server/src/main/java/com/uas/sso/entity/BaseLog.java
  25. 112 0
      sso-server/src/main/java/com/uas/sso/entity/RegisterLog.java
  26. 372 0
      sso-server/src/main/java/com/uas/sso/entity/User.java
  27. 148 0
      sso-server/src/main/java/com/uas/sso/entity/UserLog.java
  28. 23 0
      sso-server/src/main/java/com/uas/sso/exception/VisibleError.java
  29. 32 0
      sso-server/src/main/java/com/uas/sso/logging/Logger.java
  30. 25 0
      sso-server/src/main/java/com/uas/sso/logging/RegisterBufferedLogger.java
  31. 27 0
      sso-server/src/main/java/com/uas/sso/logging/UserBufferedLogger.java
  32. 31 0
      sso-server/src/main/java/com/uas/sso/service/BaseLogService.java
  33. 12 0
      sso-server/src/main/java/com/uas/sso/service/RegisterLogService.java
  34. 13 0
      sso-server/src/main/java/com/uas/sso/service/UserLogService.java
  35. 48 0
      sso-server/src/main/java/com/uas/sso/service/UserService.java
  36. 32 0
      sso-server/src/main/java/com/uas/sso/service/impl/RegisterLogServiceImpl.java
  37. 32 0
      sso-server/src/main/java/com/uas/sso/service/impl/UserLogServiceImpl.java
  38. 86 0
      sso-server/src/main/java/com/uas/sso/service/impl/UserServiceImpl.java
  39. 48 0
      sso-server/src/main/java/com/uas/sso/web/advice/ExceptionHandlerAdvice.java

+ 6 - 0
pom.xml

@@ -14,6 +14,7 @@
 
     <modules>
         <module>sso-server</module>
+        <module>sso-common</module>
     </modules>
 
     <properties>
@@ -43,6 +44,11 @@
                 <artifactId>fastjson</artifactId>
                 <version>${fastjson.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.springframework</groupId>
+                <artifactId>spring-context</artifactId>
+                <version>${spring.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 

+ 57 - 0
sso-common/pom.xml

@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>sso-parent</artifactId>
+        <groupId>com.uas.sso</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+    <artifactId>sso-common</artifactId>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.uas.account</groupId>
+            <artifactId>sso-core</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-beans</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tomcat.embed</groupId>
+            <artifactId>tomcat-embed-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>net.sf.flexjson</groupId>
+            <artifactId>flexjson</artifactId>
+            <version>2.1</version>
+        </dependency>
+    </dependencies>
+    <distributionManagement>
+        <!-- 发布release仓库 -->
+        <repository>
+            <id>platform-release</id>
+            <name>platform-release</name>
+            <url>http://113.105.74.141:8081/artifactory/libs-release-local</url>
+        </repository>
+        <!-- 发布快照版本 -->
+        <snapshotRepository>
+            <id>platform-snapshots</id>
+            <name>platform-snapshots</name>
+            <url>http://113.105.74.141:8081/artifactory/libs-snapshot-local</url>
+        </snapshotRepository>
+    </distributionManagement>
+</project>

+ 57 - 0
sso-common/src/main/java/com/uas/sso/AccountConfig.java

@@ -0,0 +1,57 @@
+package com.uas.sso;
+
+import com.uas.sso.SSOConfig;
+
+/**
+ * 账户中心配置
+ * 
+ * @author yingp
+ * 
+ */
+public class AccountConfig extends SSOConfig {
+
+	public static final String ACCOUNT_CENTER = "sso";
+
+	/**
+	 * 无需绑定到任何企业的个人账号,默认绑定到-1
+	 */
+	public static final String DEFAULT_SPACE_ID = "-1";
+
+	/**
+	 * 账户中心的接口,App注册企业信息到账户中心
+	 * 
+	 * <pre>
+	 * 账户中心保存的资料有限,因此App里面也需要有自定义的企业信息表来存放业务字段;
+	 * App里面最好是在自己系统保存成功后,再调用账户中心的接口,即使出错也可回滚。
+	 * </pre>
+	 */
+	public static String getSpaceSaveUrl() {
+		return getInstance().getProperty("account.us.save.url");
+	}
+
+	/**
+	 * 账户中心的接口,App注册用户信息到账户中心
+	 * 
+	 * <pre>
+	 * 账户中心保存的资料有限,因此App里面也需要有自定义的用户信息表来存放业务字段;
+	 * App里面最好是在自己系统保存成功后,再调用账户中心的接口,即使出错也可回滚。
+	 * </pre>
+	 */
+	public static String getUserSaveUrl() {
+		return getInstance().getProperty("account.user.save.url");
+	}
+
+	/**
+	 * 账户中心的接口,供商务平台和ERP系统查询自己当期企业的合作伙伴
+	 */
+	public static String getEnPartnersUrl() {
+		return getInstance().getProperty("account.user.getPartners.url");
+	}
+
+	/**
+	 * 账户中心接口,跳转到企业圈
+	 */
+	public static String getContactPageUrl() {
+		return getInstance().getProperty("account.user.getContactPage.url");
+	}
+}

+ 63 - 0
sso-common/src/main/java/com/uas/sso/ResultWrap.java

@@ -0,0 +1,63 @@
+package com.uas.sso;
+
+public class ResultWrap {
+
+	private Object content;
+
+	private Boolean success;
+
+	private Boolean error;
+
+	private Integer errCode;
+
+	private String errMsg;
+
+	public Boolean isSuccess() {
+		return null != success && success;
+	}
+
+	public Boolean isError() {
+		return null != error && error;
+	}
+
+	public Boolean getSuccess() {
+		return success;
+	}
+
+	public void setSuccess(Boolean success) {
+		this.success = success;
+	}
+
+	public Integer getErrCode() {
+		return errCode;
+	}
+
+	public void setErrCode(Integer errCode) {
+		this.errCode = errCode;
+	}
+
+	public String getErrMsg() {
+		return errMsg;
+	}
+
+	public void setErrMsg(String errMsg) {
+		this.errMsg = errMsg;
+	}
+
+	public Object getContent() {
+		return content;
+	}
+
+	public void setContent(Object content) {
+		this.content = content;
+	}
+
+	public Boolean getError() {
+		return error;
+	}
+
+	public void setError(Boolean error) {
+		this.error = error;
+	}
+
+}

+ 19 - 0
sso-common/src/main/java/com/uas/sso/exception/AccountException.java

@@ -0,0 +1,19 @@
+package com.uas.sso.exception;
+
+public class AccountException extends RuntimeException {
+
+	private static final long serialVersionUID = 1L;
+
+	public AccountException(String message) {
+		super(message);
+	}
+
+	public AccountException(Throwable throwable) {
+		super(throwable);
+	}
+
+	public AccountException(String message, Throwable throwable) {
+		super(message, throwable);
+	}
+
+}

+ 118 - 0
sso-common/src/main/java/com/uas/sso/support/Page.java

@@ -0,0 +1,118 @@
+package com.uas.sso.support;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class Page<T> implements Serializable {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+    /**
+     * 页数
+     */
+	private int number;
+
+    /**
+     * 每页大小
+     */
+    private int size;
+
+    /**
+     * 获取数据数量
+     */
+    private int numberOfElements;
+
+    /**
+     * 数据
+     */
+    private List<T> content;
+
+    /**
+     * 是否为第一页
+     */
+    private boolean first;
+
+    /**
+     * 是否为最后一页
+     */
+    private boolean last;
+
+    /**
+     * 总页数
+     */
+    private long totalElements;
+
+	public Page() {
+
+	}
+
+	public Page(int pageNumber, int pageSize, List<T> content, int totalElements) {
+		this.number = pageNumber;
+		this.size = pageSize;
+		this.content = content;
+		this.numberOfElements = content == null || content.isEmpty() ? 0 : content.size();
+		this.totalElements = totalElements;
+		this.first = pageNumber == 1;
+		this.last = pageNumber >= (int) Math.floor((double) totalElements / pageSize);
+	}
+
+	public int getNumber() {
+		return number;
+	}
+
+	public void setNumber(int number) {
+		this.number = number;
+	}
+
+	public int getSize() {
+		return size;
+	}
+
+	public void setSize(int size) {
+		this.size = size;
+	}
+
+	public int getNumberOfElements() {
+		return numberOfElements;
+	}
+
+	public void setNumberOfElements(int numberOfElements) {
+		this.numberOfElements = numberOfElements;
+	}
+
+	public List<T> getContent() {
+		return content;
+	}
+
+	public void setContent(List<T> content) {
+		this.content = content;
+	}
+
+	public boolean isFirst() {
+		return first;
+	}
+
+	public void setFirst(boolean first) {
+		this.first = first;
+	}
+
+	public boolean isLast() {
+		return last;
+	}
+
+	public void setLast(boolean last) {
+		this.last = last;
+	}
+
+	public long getTotalElements() {
+		return totalElements;
+	}
+
+	public void setTotalElements(long totalElements) {
+		this.totalElements = totalElements;
+	}
+
+}

+ 1167 - 0
sso-common/src/main/java/com/uas/sso/util/AccountUtils.java

@@ -0,0 +1,1167 @@
+package com.uas.sso.util;
+
+/**
+ * 客户端使用,操作企业资料、用户资料
+ *
+ * @author yingp
+ *
+ */
+public class AccountUtils {
+
+/// 之后方法会恢复并修改
+//	/**
+//	 * 修改用户信息
+//	 *
+//	 * @param user
+//	 * @param userDetail
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static List<User> saveUser(User user, UserDetail userDetail) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			JSONObject formData = new JSONObject();
+//			if (userDetail != null) {
+//				formData = JSON.parseObject(JSON.toJSONString(userDetail));
+//			}
+//			if (user != null) {
+//				if (user.getUid() == null) {
+//					user.setUid(userDetail.getMobile());
+//				}
+//				if (user.getSecondUID() == null) {
+//					user.setSecondUID(userDetail.getEmail());
+//				}
+//				if (user.getAppId() != null && user.getDialectUID() != null) {
+//					if (user.getAppId().equals("b2b") || user.getAppId().equals("mall")) {
+//						user.setSalt(user.getDialectUID());
+//					}
+//				}
+//				formData.putAll(JSON.parseObject(JSON.toJSONString(user)));
+//			}
+//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (result.isError()) {
+//					throw new Exception(result.getErrMsg());
+//				} else {
+//					return JSON.parseArray(JSON.toJSONString(result.getContent()), User.class);
+//				}
+//			}
+//		}
+//		return null;
+//	}
+//
+//	/**
+//	 * 修改用户信息
+//	 *
+//	 * @param dialectUID
+//	 *            个人唯一标识
+//	 * @param spaceDialectUID
+//	 *            企业唯一标识
+//	 * @param userDetail
+//	 *            个人详细信息
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static List<User> saveUser(Object dialectUID, Object spaceDialectUID, UserDetail userDetail) throws Exception {
+//		User user = new User();
+//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
+//		user.setDialectUID(dialectUID.toString());
+//		if (spaceDialectUID != null) {
+//			user.setSpaceDialectUID(spaceDialectUID.toString());
+//		}
+//		return saveUser(user, userDetail);
+//	}
+//
+//	/**
+//	 * 保存与当前应用无关的用户信息,借用appId=sso
+//	 *
+//	 * @param uid
+//	 * @param spaceUID
+//	 * @param userDetail
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static List<User> saveCustUser(Object uid, Object spaceUID, UserDetail userDetail) throws Exception {
+//		User user = new User();
+//		user.setAppId(AccountConfig.ACCOUNT_CENTER);
+//		user.setDialectUID(uid.toString());
+//		user.setSpaceUID(spaceUID.toString());
+//		return saveUser(user, userDetail);
+//	}
+//
+//	/**
+//	 * 添加用户信息
+//	 *
+//	 * @param dialectUID
+//	 *            个人唯一标识
+//	 * @param spaceDialectUID
+//	 *            企业唯一标识
+//	 * @param userDetail
+//	 *            个人详细信息
+//	 * @param noEncryPwd
+//	 *            明文密码
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static List<User> addUser(Object dialectUID, Object spaceDialectUID, UserDetail userDetail, String noEncryPwd) throws Exception {
+//		User user = new User();
+//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
+//		user.setDialectUID(dialectUID.toString());
+//		if (spaceDialectUID != null) {
+//			user.setSpaceDialectUID(spaceDialectUID.toString());
+//		}
+//		user.setPassword(noEncryPwd);
+//		return saveUser(user, userDetail);
+//	}
+//
+//	/**
+//	 * 修改手机号
+//	 * @param oldTel
+//	 * @param newTel
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static List<User> updateTel (String oldTel, String newTel) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			saveUrl = saveUrl + "/updateTel";
+//			JSONObject formData = new JSONObject();
+//			formData.put("oldTel", oldTel);
+//			formData.put("newTel", newTel);
+//			formData.put("appId", SSOHelper.getSSOService().getConfig().getAppName());
+//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
+//			if (!res.isSuccess()) {
+//				throw new Exception(res.getContent());
+//			} else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (result.isError()) {
+//					throw new Exception(result.getErrMsg());
+//				} else {
+//					return JSON.parseArray(JSON.toJSONString(result.getContent()), User.class);
+//				}
+//			}
+//		}
+//		return null;
+//	}
+//
+//	/**
+//	 * 修改邮箱
+//	 * @param oldTel
+//	 * @param newEmail
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static List<User> updateEmail (String oldTel, String newEmail) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			saveUrl = saveUrl + "/updateEmail";
+//			JSONObject formData = new JSONObject();
+//			formData.put("oldTel", oldTel);
+//			formData.put("newEmail", newEmail);
+//			formData.put("appId", SSOHelper.getSSOService().getConfig().getAppName());
+//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
+//			if (!res.isSuccess()) {
+//				throw new Exception(res.getContent());
+//			} else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (result.isError()) {
+//					throw new Exception(result.getErrMsg());
+//				} else {
+//					return JSON.parseArray(JSON.toJSONString(result.getContent()), User.class);
+//				}
+//			}
+//		}
+//		return null;
+//	}
+//
+//	public static List<UserSpace> saveUserSpace(UserSpace space, UserSpaceDetail spaceDetail) throws Exception {
+//		String saveUrl = AccountConfig.getSpaceSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			JSONObject formData = new JSONObject();
+//			if (spaceDetail != null) {
+//				formData = JSON.parseObject(JSON.toJSONString(spaceDetail));
+//			}
+//			if (space != null) {
+//				if (space.getUid() == null) {
+//					space.setUid(spaceDetail.getBusinessCode());
+//				}
+//				formData.putAll(JSON.parseObject(JSON.toJSONString(space)));
+//			}
+//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (result.isError()) {
+//					throw new Exception(result.getErrMsg());
+//				} else {
+//					return JSON.parseArray(JSON.toJSONString(result.getContent()), UserSpace.class);
+//				}
+//			}
+//		}
+//		return null;
+//	}
+//
+//	public static List<UserSpace> saveUserSpace(Object dialectUID, UserSpaceDetail spaceDetail) throws Exception {
+//		UserSpace userSpace = new UserSpace();
+//		userSpace.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
+//		userSpace.setDialectUID(dialectUID.toString());
+//		return saveUserSpace(userSpace, spaceDetail);
+//	}
+//
+//	/**
+//	 * 解除绑定的应用
+//	 *
+//	 * @param userSpace
+//	 * @throws Exception
+//	 */
+//	public static void unbindUserSpace(UserSpace userSpace) throws Exception {
+//		String saveUrl = AccountConfig.getSpaceSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			JSONObject formData = JSON.parseObject(JSON.toJSONString(userSpace));
+//			formData.put("_operate", "unbind");
+//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//		}
+//	}
+//
+//	/**
+//	 * 解除绑定的应用
+//	 *
+//	 * @param uid
+//	 * @throws Exception
+//	 */
+//	public static void unbindUserSpace(String uid) throws Exception {
+//		unbindUserSpace(SSOHelper.getSSOService().getConfig().getAppName(), uid);
+//	}
+//
+//	/**
+//	 * 解除绑定的应用
+//	 *
+//	 * @param appId
+//     * @param uid
+//	 * @throws Exception
+//	 */
+//	public static void unbindUserSpace(String appId, String uid) throws Exception {
+//		UserSpace userSpace = new UserSpace();
+//		userSpace.setAppId(appId);
+//		userSpace.setUid(uid);
+//		unbindUserSpace(userSpace);
+//	}
+//
+//	/**
+//	 * 解除绑定的云账号
+//	 *
+//	 * @param user
+//	 * @throws Exception
+//	 */
+//	public static void unbindUser(User user) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
+//			formData.put("_operate", "unbind");
+//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//		}
+//	}
+//
+//	/**
+//	 * 解除绑定的云账号
+//	 *
+//	 * @param dialectUID
+//     * @param spaceDialectUID
+//	 * @throws Exception
+//	 */
+//	public static void unbindUser(Object dialectUID, Object spaceDialectUID) throws Exception {
+//		User user = new User();
+//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
+//		user.setDialectUID(dialectUID.toString());
+//		if (spaceDialectUID != null) {
+//			user.setSpaceDialectUID(spaceDialectUID.toString());
+//		}
+//		unbindUser(user);
+//	}
+//
+//	/**
+//	 * 校验密码
+//	 *
+//	 * @param user
+//	 * @throws Exception
+//	 */
+//	public static boolean checkPassword(User user) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
+//			formData.put("_operate", "check");
+//			ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (!result.isSuccess())
+//					throw new Exception(result.getErrMsg());
+//				else
+//					return true;
+//			}
+//		}
+//		return false;
+//	}
+//
+//	/**
+//	 * 校验密码
+//	 *
+//	 * @param dialectUID
+//	 * @param spaceDialectUID
+//	 * @param password
+//	 * @throws Exception
+//	 */
+//	public static boolean checkPassword(Object dialectUID, Object spaceDialectUID, String password) throws Exception {
+//		User user = new User();
+//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
+//		user.setDialectUID(dialectUID.toString());
+//		if (spaceDialectUID != null) {
+//			user.setSpaceDialectUID(spaceDialectUID.toString());
+//		}
+//		user.setPassword(password);
+//		return checkPassword(user);
+//	}
+//
+//	/**
+//	 * 校验密码
+//	 *
+//	 * <pre>
+//	 * 全匹配模式
+//	 * </pre>
+//	 *
+//	 * @param user
+//	 * @throws Exception
+//	 */
+//	public static boolean fuzzyCheckPassword(User user) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
+//			formData.put("_operate", "fuzzyCheck");
+//			ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (!result.isSuccess())
+//					throw new Exception(result.getErrMsg());
+//				else
+//					return true;
+//			}
+//		}
+//		return false;
+//	}
+//
+//	/**
+//	 * 校验密码
+//	 *
+//	 * <pre>
+//	 * 全匹配模式
+//	 * </pre>
+//	 *
+//	 * @param dialectUID
+//	 * @param spaceDialectUID
+//	 * @param password
+//	 * @throws Exception
+//	 */
+//	public static boolean fuzzyCheckPassword(Object dialectUID, Object spaceDialectUID, String password) throws Exception {
+//		User user = new User();
+//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
+//		user.setDialectUID(dialectUID.toString());
+//		if (spaceDialectUID != null) {
+//			user.setSpaceDialectUID(spaceDialectUID.toString());
+//		}
+//		user.setPassword(password);
+//		return fuzzyCheckPassword(user);
+//	}
+//
+//	/**
+//	 * 重置密码
+//	 *
+//	 * @param user
+//	 * @throws Exception
+//	 */
+//	public static void resetPassword(User user) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+////		saveUrl = saveUrl + "/resetPwd";
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
+//			formData.put("_operate", "reset");
+//			ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (!result.isSuccess())
+//					throw new Exception(result.getErrMsg());
+//			}
+//		}
+//	}
+//
+//	/**
+//	 * 重置密码
+//	 *
+//	 * @param dialectUID
+//	 *            应用自己的用户唯一标识
+//	 * @param spaceDialectUID
+//	 *            企业唯一标识
+//	 * @param noEncryPwd
+//	 *            新密码(明文)
+//	 * @throws Exception
+//	 */
+//	public static void resetPassword(Object dialectUID, Object spaceDialectUID, String noEncryPwd) throws Exception {
+//		User user = new User();
+//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
+//		user.setDialectUID(dialectUID.toString());
+//		if (spaceDialectUID != null) {
+//			user.setSpaceDialectUID(spaceDialectUID.toString());
+//		}
+//		user.setPassword(noEncryPwd);
+//		resetPassword(user);
+//	}
+//
+//	/**
+//	 * 重置密码
+//	 *
+//	 * @param mobile
+//	 *            手机号
+//	 * @param noEncryPwd
+//	 *            新密码(明文)
+//	 * @throws Exception
+//	 */
+//	public static void resetPassword(String mobile, String noEncryPwd) throws Exception {
+//		User user = new User();
+//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
+//		user.setUid(mobile);
+//		user.setPassword(noEncryPwd);
+//		resetPassword(user);
+//	}
+//
+//	/**
+//	 * 获取校验码
+//	 *
+//	 * @param username
+//	 *            手机号或邮箱地址
+//	 * @return
+//	 */
+//	public static void sendValidCode(String username) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			ResponseWrap res = HttpUtil.doGet(saveUrl, new ModelMap("_operate", "getVcode").addAttribute("username", username));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (!result.isSuccess())
+//					throw new Exception(result.getErrMsg());
+//			}
+//		}
+//	}
+//
+//	/**
+//	 * 验证校验码
+//	 *
+//	 * @param username
+//	 *            手机号或邮箱地址
+//	 * @param validCode
+//	 *            校验码
+//	 * @return
+//	 */
+//	public static boolean checkValidCode(String username, String validCode) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			ResponseWrap res = HttpUtil.doGet(saveUrl, new ModelMap("_operate", "checkVcode").addAttribute("username", username)
+//					.addAttribute("validCode", validCode));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (!result.isSuccess())
+//					throw new Exception(result.getErrMsg());
+//				else
+//					return true;
+//			}
+//		}
+//		return false;
+//	}
+//
+//	public static String getAccessToken(String appId, String spaceDialectUID, String uid) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			saveUrl = saveUrl + "/getToken";
+//			JSONObject formData = new JSONObject();
+//			formData.put("appId", appId);
+//			formData.put("spaceDialectUID", spaceDialectUID);
+//			formData.put("uid", uid);
+//			ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
+//			if (!res.isSuccess()) {
+//				throw new Exception(res.getContent());
+//			} else {
+//				return res.getContent();
+//			}
+//		}
+//        return null;
+//    }
+//
+//	/**
+//	 * 验证密码,返回绑定身份信息的token
+//	 *
+//	 * @return
+//	 */
+//	public static String getAccessToken(User user) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
+//			formData.put("_operate", "getToken");
+//			ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (!result.isSuccess())
+//					throw new Exception(result.getErrMsg());
+//				else
+//					return String.valueOf(result.getContent());
+//			}
+//		}
+//		return null;
+//	}
+//
+//	/**
+//	 * 验证token,返回当前应用相关的身份信息
+//	 *
+//	 * @return
+//	 */
+//	public static UserView checkAccessToken(String token) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			ResponseWrap res = HttpUtil.doGet(
+//					saveUrl,
+//					new ModelMap("_operate", "checkToken").addAttribute("token", token).addAttribute("appId",
+//							SSOHelper.getSSOService().getConfig().getAppName()));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+//				if (!result.isSuccess())
+//					throw new Exception(result.getErrMsg());
+//				else
+//					return JSON.parseObject(JSON.toJSONString(result.getContent()), UserView.class);
+//			}
+//		}
+//		return null;
+//	}
+//
+//	/**
+//	 * 用token验证登录
+//	 *
+//	 * @param request
+//	 * @param response
+//	 * @param token
+//	 * @throws Exception
+//	 */
+//	public static UserView loginByAccessToken(HttpServletRequest request, HttpServletResponse response, String token) throws Exception {
+//		UserView user = checkAccessToken(token);
+//		if (null != user) {
+//			SSOToken st = new SSOToken(request, user.getUid());
+//			st.setData(JSON.toJSONString(user));
+//			SSOHelper.setSSOCookie(request, response, st, true);
+//		}
+//		return user;
+//	}
+//
+//	/**
+//	 * 传入当前登录的企业的营业执照号,查询发出的申请
+//	 *
+//	 * @param businessCode
+//	 * @param statusCode
+//	 * @param keyword
+//	 * @param pageNumber
+//	 * @param pageSize
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static Page<PartnershipRecord> getAllRequest(String businessCode, Integer statusCode, String keyword, int pageNumber,
+//														int pageSize) throws Exception {
+//		String getUrl = AccountConfig.getEnPartnersUrl();
+//		if (!StringUtils.isEmpty(getUrl)) {
+//			ResponseWrap res = HttpUtil.doGet(getUrl, new ModelMap("_operate", "getAllRequest").addAttribute("businessCode", businessCode)
+//					.addAttribute("statusCode", statusCode).addAttribute("businessCode", businessCode).addAttribute("keyword", keyword)
+//					.addAttribute("pageNumber", pageNumber).addAttribute("pageSize", pageSize));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			return JSONObject.parseObject(res.getContent(), new TypeReference<Page<PartnershipRecord>>() {
+//			});
+//		}
+//		return null;
+//	}
+//
+//	/**
+//	 * 通过已存在uu过滤,取出全部合作伙伴(UAS接口用)
+//	 * @param businessCode
+//	 * @param statusCode
+//	 * @param keyword
+//	 * @param pageNumber
+//	 * @param pageSize
+//	 * @param partnerUUs
+//	 * @return
+//	 */
+//	public static Page<PartnershipRecord> getRequestFilterByPartnerUUs(String businessCode, Integer statusCode, String keyword, List<Long> partnerUUs, int pageNumber, int pageSize) throws Exception {
+//		String getUrl = AccountConfig.getEnPartnersUrl();
+//		if (!StringUtils.isEmpty(getUrl)) {
+//			ResponseWrap res = HttpUtil.doGet(getUrl, new ModelMap("_operate", "getAllRequestFilterByPartnerUUs").addAttribute("businessCode", businessCode)
+//					.addAttribute("statusCode", statusCode).addAttribute("keyword", keyword).addAttribute("partnerUUs", JSON.toJSON(partnerUUs))
+//					.addAttribute("pageNumber", pageNumber).addAttribute("pageSize", pageSize));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			return JSON.parseObject(res.getContent(), new TypeReference<Page<PartnershipRecord>>() {
+//			});
+//		}
+//		return null;
+//	}
+//
+//	/**
+//	 * 进入企业圈
+//	 *
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static String redirectContactPage() throws Exception {
+//		String enterUrl = AccountConfig.getContactPageUrl();
+//		return enterUrl;
+//	}
+//
+//	/**
+//	 * 通过关键词搜索企业信息
+//	 *
+//	 * @param keyword
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static Page<UserSpaceDetail> getUserSpacesByKeyword(String keyword, int pageNumber, int pageSize) throws Exception {
+//		String Url = AccountConfig.getEnPartnersUrl();
+//		if (!StringUtils.isEmpty(Url)) {
+//			ResponseWrap res = HttpUtil.doGet(Url,
+//					new ModelMap("_operate", "getUserSpaces").addAttribute("keyword", keyword).addAttribute("pageNumber", pageNumber)
+//							.addAttribute("pageSize", pageSize));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			return JSON.parseObject(res.getContent(), new TypeReference<Page<UserSpaceDetail>>() {
+//			});
+//		}
+//		return null;
+//	}
+//
+//	/**
+//	 * 通过手机号搜索用户账号信息
+//	 *
+//	 * @param uid
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static List<User> getUserInfoByUid(String uid) throws Exception {
+//		String Url = AccountConfig.getSpaceSaveUrl();
+//		if (!StringUtils.isEmpty(Url)) {
+//			ResponseWrap res = HttpUtil.doGet(Url + "/userInfo",
+//					new ModelMap("uid", uid));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			String resText = res.getContent();
+//			JSONObject object = JSON.parseObject(resText);
+//			String contentText = object.getString("content");
+//			return JSON.parseArray(contentText, User.class);
+//		}
+//		return null;
+//	}
+//
+//	/**
+//	 * 通过营业执照号获取企业应用
+//	 *
+//	 * @param uid
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static List<UserSpace> getUserSpaceByUid(String uid) throws Exception {
+//		String Url = AccountConfig.getSpaceSaveUrl();
+//		if (!StringUtils.isEmpty(Url)) {
+//			ResponseWrap res = HttpUtil.doGet(Url + "/" + uid);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			String resText = res.getContent();
+//			JSONObject object = JSON.parseObject(resText);
+//			String contentText = object.getString("content");
+//			return JSON.parseArray(contentText, UserSpace.class);
+//		}
+//		return null;
+//	}
+//
+//	/**
+//	 * 新增一条合作关系记录
+//	 *
+//	 * @param record
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static String addNewRecord(PartnershipRecord record) throws Exception {
+//		String url = AccountConfig.getEnPartnersUrl();
+//		String result = null;
+//		if (!StringUtils.isEmpty(url)) {
+//			JSONObject formData = JSON.parseObject(JSON.toJSONString(record));
+//			formData.put("_operate", "addPartner");
+//			ResponseWrap res = HttpUtil.doPost(url, formData);
+//			result = res.getContent();
+//		}
+//		return result;
+//	}
+//
+//	/**
+//	 * 同步供应商关系为合作关系记录
+//	 *
+//	 * @param record
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static String synchronizeRecord(PartnershipRecord record) throws Exception {
+//		String url = AccountConfig.getEnPartnersUrl();
+//		String result = null;
+//		if (!StringUtils.isEmpty(url)) {
+//			JSONObject formData = JSON.parseObject(JSON.toJSONString(record));
+//			formData.put("_operate", "synchronizePartner");
+//			ResponseWrap res = HttpUtil.doPost(url, formData);
+//			result = res.getContent();
+//		}
+//		return result;
+//	}
+//
+//	/**
+//	 * 通过id和申请人的电话进行确认
+//	 *
+//	 * @param id
+//	 * @param vendUserTel
+//     * @param appId
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static String acceptRequest(Long id, String vendUserTel, String appId) throws Exception {
+//		String url = AccountConfig.getEnPartnersUrl();
+//		String result = null;
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doGet(
+//					url,
+//					new ModelMap("_operate", "acceptRequest").addAttribute("id", id).addAttribute("vendUserTel", vendUserTel)
+//							.addAttribute("appId", appId));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				result = res.getContent();
+//			}
+//		}
+//		return result;
+//	}
+//
+//	/**
+//	 * 申请不通过,通过申请人的电话操作,并标出原因
+//	 *
+//	 * @param id
+//	 * @param reason
+//	 * @param vendUserTel
+//     * @param appId
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static String rejectRequest(Long id, String reason, String vendUserTel, String appId) throws Exception {
+//		String url = AccountConfig.getEnPartnersUrl();
+//		String result = null;
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doGet(
+//					url,
+//					new ModelMap("_operate", "rejectRequest").addAttribute("id", id).addAttribute("reason", reason)
+//							.addAttribute("vendUserTel", vendUserTel).addAttribute("appId", appId));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				result = res.getContent();
+//			}
+//		}
+//		return result;
+//	}
+//
+//	/**
+//	 * 通过当前企业号和企业列表中的企业号查询申请状态
+//	 *
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static RequsetStatus getStatusByCustUidAndVendUid(String custUid, String vendUid) throws Exception {
+//		String url = AccountConfig.getEnPartnersUrl();
+//		RequsetStatus request = new RequsetStatus();
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doGet(url, new ModelMap("_operate", "getRequestStatus").addAttribute("custUid", custUid)
+//					.addAttribute("vendUid", vendUid));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else {
+//				request = JSON.parseObject(res.getContent(), RequsetStatus.class);
+//			}
+//		}
+//		return request;
+//	}
+//
+//	/**
+//	 * 搜索词通过id返回数据
+//	 *
+//	 * @param ids
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static List<UserSpaceDetail> findAll(String ids) throws Exception {
+//		String url = AccountConfig.getEnPartnersUrl();
+//		List<UserSpaceDetail> details = new ArrayList<UserSpaceDetail>();
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doGet(url, new ModelMap("_operate", "findAll").addAttribute("ids", ids));
+//			if(!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else
+//				details = JSONObject.parseArray(res.getContent(), UserSpaceDetail.class);
+//		}
+//		return details;
+//	}
+//
+//	/**
+//	 * 通过企业营业执照查询收到的待处理的请求
+//	 *
+//	 * @param businessCode
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static String getRequestTodo(String businessCode) throws Exception {
+//		String url = AccountConfig.getEnPartnersUrl();
+//		String result = null;
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doGet(url,
+//					new ModelMap("_operate", "getRequestTodo").addAttribute("businessCode", businessCode));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else
+//				result = res.getContent();
+//		}
+//		return result;
+//	}
+//
+//	/**
+//	 * 其他应用发起邀请注册,同步数据
+//	 *
+//	 * @param jsonStr
+//	 * @throws Exception
+//	 */
+//	public static void synchroInvitation(String jsonStr) throws Exception {
+//		String url = AccountConfig.getEnPartnersUrl();
+//		if (!StringUtils.isEmpty(url)) {
+//			HttpUtil.doPost(url, new ModelMap("_operate", "invitation").addAttribute("jsonStr", jsonStr));
+//		}
+//	}
+//
+//	/**
+//	 * ERP、SAAS新开账套名称校验
+//	 *
+//	 * @param name
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static String validName(String name) throws Exception {
+//		String result = null;
+//		String url = AccountConfig.getSpaceSaveUrl();
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doGet(url, new ModelMap("_operate", "validName").addAttribute("name", name),
+//					50);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else
+//				result = res.getContent();
+//		}
+//		return result;
+//	}
+//
+//	/**
+//	 * ERP、SAAS新开账套名称校验
+//	 *
+//	 * @param businessCode
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static String validBusinessCode(String businessCode) throws Exception {
+//		String result = null;
+//		String url = AccountConfig.getSpaceSaveUrl();
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doGet(url,
+//					new ModelMap("_operate", "validBusinessCode").addAttribute("businessCode", businessCode), 50);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else
+//				result = res.getContent();
+//		}
+//		return result;
+//	}
+//
+//	/**
+//	 * 通过营业执照号查找 企业详细信息
+//	 *
+//	 * @param
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static UserSpaceDetail findByBusinessCode(String businessCode) throws Exception {
+//		String result = null;
+//		String url = AccountConfig.getSpaceSaveUrl();
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doGet(url,
+//					new ModelMap("_operate", "findByBusinessCode").addAttribute("businessCode", businessCode), 50);
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else
+//				result = res.getContent();
+//		}
+//		return JSON.parseObject(result,UserSpaceDetail.class);
+//	}
+//
+//	/**
+//	 * ERP、SAAS新开账套
+//	 *
+//	 * @param userSpaceDetail
+//	 * @param users
+//	 * @throws Exception
+//	 */
+//	public static String applyApp(UserSpaceDetail userSpaceDetail, List<UserDetail> users) throws Exception {
+//		String url = AccountConfig.getSpaceSaveUrl();
+//		String result = null;
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doPost(url, new ModelMap("_operate", "registerBranchAccount")
+//							.addAttribute("detail", JSON.toJSON(userSpaceDetail))
+//							.addAttribute("userInfos", JSON.toJSON(users)));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else
+//				result = res.getContent();
+//		}
+//		return result;
+//	}
+//
+//	/**
+//	 * 商城个人账号增加企业注册
+//	 *
+//	 * @param userSpaceDetail
+//	 * @throws Exception
+//	 */
+//	public static String applyAppForMall(UserSpaceDetail userSpaceDetail) throws Exception {
+//		String url = AccountConfig.getSpaceSaveUrl();
+//		String result = null;
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doPost(url,
+//					new ModelMap("_operate", "registForMall")
+//					.addAttribute("detail", JSON.toJSON(userSpaceDetail)));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else
+//				result = res.getContent();
+//		}
+//		return result;
+//	}
+//
+//	/**
+//	 * 设置hr账号
+//	 *
+//	 * @param user
+//	 * @param detail
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static String setHrAccount(User user, UuzcUserSpaceDetail detail) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		saveUrl = saveUrl + "/setHrAccount";
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			JSONObject formData = new JSONObject();
+//			if (detail != null) {
+//				formData = JSON.parseObject(JSON.toJSONString(detail));
+//			}
+//			if (null != user) {
+//				formData.putAll(JSON.parseObject(JSON.toJSONString(user)));
+//			}
+//			ResponseWrap response = HttpUtil.doPost(saveUrl, formData);
+//			if (!response.isSuccess())
+//				throw new Exception(response.getContent());
+//			else {
+//				return response.getContent();
+//			}
+//		}
+//		return null;
+//	}
+//
+//    /**
+//     * 根据营业执照获取众创需要的企业资料
+//     *
+//     * @param businessCode
+//     * @return
+//     * @throws Exception
+//     */
+//    public static UuzcUserSpaceDetail getUuzcUserSpaceDetail(String businessCode) throws Exception {
+//        String saveUrl = AccountConfig.getUserSaveUrl();
+//        if (!StringUtils.isEmpty(saveUrl)) {
+//            ResponseWrap response = HttpUtil.doGet(saveUrl  + "/uuzcSpace" , new ModelMap("businessCode", businessCode));
+//            if (!response.isSuccess())
+//                throw new Exception(response.getContent());
+//            else {
+//                return JSONObject.parseObject(response.getContent(), UuzcUserSpaceDetail.class);
+//            }
+//        }
+//        return null;
+//    }
+//
+//	/**
+//	 * 判断当前企业是否设置了hr
+//	 *
+//	 * @param businessCode
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static String getHrAccount(String businessCode) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			ResponseWrap response = HttpUtil.doGet(saveUrl  + "/hrcount" , new ModelMap("businessCode", businessCode));
+//			if (!response.isSuccess())
+//				throw new Exception(response.getContent());
+//			else {
+//				return response.getContent();
+//			}
+//		}
+//		return null;
+//	}
+//
+//    /**
+//     * 获取当前企业的HR信息
+//     *
+//     * @param businessCode
+//     * @return
+//     * @throws Exception
+//     */
+//    public static User getHrInfo(String businessCode) throws Exception {
+//        String saveUrl = AccountConfig.getUserSaveUrl();
+//        if (!StringUtils.isEmpty(saveUrl)) {
+//            ResponseWrap response = HttpUtil.doGet(saveUrl + "/hrInfo" , new ModelMap("businessCode", businessCode));
+//            if (!response.isSuccess())
+//                throw new Exception(response.getContent());
+//            else {
+//                return JSONObject.parseObject(response.getContent(), User.class);
+//            }
+//        }
+//        return null;
+//    }
+//
+//	/**
+//	 * 获取当前企业人员账号信息
+//	 *
+//	 * @param businessCode
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public static List<User> getEmployees(String businessCode) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		saveUrl = saveUrl + "/employees";
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			ResponseWrap response = HttpUtil.doPost(saveUrl, new ModelMap("businessCode", businessCode));
+//			if (!response.isSuccess())
+//				throw new Exception(response.getContent());
+//			else {
+//				return JSON.parseArray(response.getContent(), User.class);
+//			}
+//		}
+//		return null;
+//	}
+//
+//	/**
+//	 * 保存用户密保问题
+//	 * @param questions
+//	 * @throws Exception
+//	 */
+//	public static void saveUserQuestions(List<UserQuestion> questions) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		saveUrl = saveUrl + "/save/question";
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			ResponseWrap res = HttpUtil.doPost(saveUrl, new ModelMap("question", questions));
+//			if (!res.isSuccess()) {
+//				throw new Exception(res.getContent());
+//			}
+//		}
+//	}
+//
+//	/**
+//	 * 保存用户密保问题
+//	 * @param userQuestion
+//	 * @throws Exception
+//	 */
+//	public static void saveUserQuestion(UserQuestion userQuestion) throws Exception {
+//		String saveUrl = AccountConfig.getUserSaveUrl();
+//		saveUrl = saveUrl + "/save/question";
+//		if (!StringUtils.isEmpty(saveUrl)) {
+//			JSONObject formData = JSON.parseObject(JSON.toJSONString(userQuestion));
+//			formData.put("_count", "one");
+//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
+//			if (!res.isSuccess()) {
+//				throw new Exception(res.getContent());
+//			}
+//		}
+//	}
+//
+//	/**
+//	 * 根据imId获取用户userUU(没有则返回null)
+//	 */
+//	public static User getUserByImId (Long imId) throws Exception {
+//		String url = AccountConfig.getUserSaveUrl();
+//		User result = null;
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doGet(url,
+//					new ModelMap("_operate", "getUserByImId")
+//							.addAttribute("imId", imId));
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//			else
+//				result = JSON.parseObject(res.getContent(), User.class);
+//		}
+//		return result;
+//	}
+//
+//	/**
+//	 * 根据营业执照号分页查找该企业的用户
+//	 * @param businessCode
+//	 * @param pageNumber
+//	 * @param pageSize
+//	 * @return
+//	 * @throws Exception
+//	 */
+//	public Page<User> findUsersByBusinessCode(String businessCode, int pageNumber, int pageSize) throws Exception {
+//		String url = AccountConfig.getUserSaveUrl();
+//		if (!StringUtils.isEmpty(url)) {
+//			url = url + "/findByBusinessCode";
+//			String appId = SSOHelper.getSSOService().getConfig().getAppName();
+//			ModelMap data = new ModelMap();
+//			data.put("businessCode", businessCode);
+//			data.put("appId", appId);
+//			data.put("pageNumber", pageNumber);
+//			data.put("pageSize", pageSize);
+//			ResponseWrap res = HttpUtil.doGet(url, data);
+//			if (!res.isSuccess()) {
+//				throw new Exception(res.getContent());
+//			} else {
+//				return JSON.parseObject(res.getContent(), new TypeReference<Page<User>>() {});
+//			}
+//		}
+//		return null;
+//	}
+}

+ 95 - 0
sso-common/src/main/java/com/uas/sso/util/BeanUtil.java

@@ -0,0 +1,95 @@
+package com.uas.sso.util;
+
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.BeanWrapper;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.FatalBeanException;
+import org.springframework.util.Assert;
+import org.springframework.util.ClassUtils;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+
+public class BeanUtil extends BeanUtils {
+
+	/**
+	 * @param source
+	 * @param target
+	 * @param onlyNotNull
+	 *            只复制不为空的属性
+	 * @param ignoreProperties
+	 * @throws BeansException
+	 */
+	public static void copyProperties(Object source, Object target, boolean onlyNotNull, String... ignoreProperties) throws BeansException {
+		copyProperties(source, target, onlyNotNull, null, ignoreProperties);
+	}
+
+	/**
+	 * Copy the property values of the given source bean into the given target
+	 * bean.
+	 * <p>
+	 * Note: The source and target classes do not have to match or even be
+	 * derived from each other, as long as the properties match. Any bean
+	 * properties that the source bean exposes but the target bean does not will
+	 * silently be ignored.
+	 * 
+	 * @param source
+	 *            the source bean
+	 * @param target
+	 *            the target bean
+	 * @param editable
+	 *            the class (or interface) to restrict property setting to
+	 * @param ignoreProperties
+	 *            array of property names to ignore
+	 * @throws BeansException
+	 *             if the copying failed
+	 * @see BeanWrapper
+	 */
+	private static void copyProperties(Object source, Object target, boolean onlyNotNull, Class<?> editable, String... ignoreProperties)
+			throws BeansException {
+
+		Assert.notNull(source, "Source must not be null");
+		Assert.notNull(target, "Target must not be null");
+
+		Class<?> actualEditable = target.getClass();
+		if (editable != null) {
+			if (!editable.isInstance(target)) {
+				throw new IllegalArgumentException("Target class [" + target.getClass().getName() + "] not assignable to Editable class ["
+						+ editable.getName() + "]");
+			}
+			actualEditable = editable;
+		}
+		PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
+		List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null);
+
+		for (PropertyDescriptor targetPd : targetPds) {
+			Method writeMethod = targetPd.getWriteMethod();
+			if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) {
+				PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
+				if (sourcePd != null) {
+					Method readMethod = sourcePd.getReadMethod();
+					if (readMethod != null && ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType())) {
+						try {
+							if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
+								readMethod.setAccessible(true);
+							}
+							Object value = readMethod.invoke(source);
+							if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
+								writeMethod.setAccessible(true);
+							}
+							if ((onlyNotNull && null != value) || !onlyNotNull) {
+								writeMethod.invoke(target, value);
+							}
+						} catch (Throwable ex) {
+							throw new FatalBeanException("Could not copy property '" + targetPd.getName() + "' from source to target", ex);
+						}
+					}
+				}
+			}
+		}
+	}
+
+}

+ 60 - 0
sso-common/src/main/java/com/uas/sso/util/FlexJsonUtil.java

@@ -0,0 +1,60 @@
+package com.uas.sso.util;
+
+import flexjson.JSONDeserializer;
+import flexjson.JSONSerializer;
+
+import java.util.*;
+
+/**
+ * <h1>flexjson</h1><br>
+ * 1.序列化json字符串时较快,优于jackson<br>
+ * 2.但是数据量较大时,序列化有问题<br>
+ * 3.反序列化较慢
+ * 
+ * @author yingp
+ * 
+ */
+public class FlexJsonUtil {
+
+	public static <T> T fromJson(String json, Class<?> cls) {
+		return new JSONDeserializer<T>().use(null, cls).deserialize(json);
+	}
+
+	public static <K, V> Map<K, V> fromJson(String json) {
+		if (json != null) {
+			Map<K, V> map = new HashMap<K, V>();
+			return new JSONDeserializer<Map<K, V>>().use(null, map.getClass()).deserialize(json);
+		}
+		return null;
+	}
+
+	public String toJson() {
+		return new JSONSerializer().exclude("*.class").serialize(this);
+	}
+
+	public static String toJson(Object obj) {
+		if (obj == null) {
+			return null;
+		}
+		return new JSONSerializer().exclude("*.class").serialize(obj);
+	}
+
+	public static String toJsonDeep(Object obj) {
+		if (obj == null) {
+			return null;
+		}
+		return new JSONSerializer().exclude("*.class").deepSerialize(obj);
+	}
+
+	public static <T> String toJsonArray(Collection<?> collection) {
+		return new JSONSerializer().exclude("*.class").serialize(collection);
+	}
+
+	public static <T> String toJsonArrayDeep(Collection<?> collection) {
+		return new JSONSerializer().exclude("*.class").deepSerialize(collection);
+	}
+
+	public static <T> List<T> fromJsonArray(String json, Class<?> cls) {
+		return new JSONDeserializer<List<T>>().use(null, ArrayList.class).use("values", cls).deserialize(json);
+	}
+}

+ 119 - 0
sso-common/src/main/java/com/uas/sso/web/AccountConfigurer.java

@@ -0,0 +1,119 @@
+package com.uas.sso.web;
+
+import com.uas.sso.AccountConfig;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+/**
+ * 账户中心配置
+ * 
+ * <pre>
+ * 包含sso配置和账户设置
+ * </pre>
+ * 
+ * @author yingp
+ *
+ */
+public class AccountConfigurer extends AccountConfig implements ApplicationContextAware {
+
+	/**
+	 * Parameter specifying the location of the account config file
+	 */
+	protected static final Logger logger = Logger.getLogger(SSOConfigurer.class.getName());
+	private static final String CONFIG_LOCATION_PARAM = "AccountConfigLocation";
+	private String configPath = "account.properties";
+	private ApplicationContext applicationContext;
+
+	public AccountConfigurer() {
+		/* 支持无参构造函数 */
+	}
+
+	public AccountConfigurer(String configPath) {
+		this.configPath = configPath;
+	}
+
+	/**
+	 * 
+	 * web.xml 启动监听, 初始化
+	 * 
+	 * @param servletContext
+	 * 
+	 */
+	public void init(ServletContext servletContext) {
+		setConfigPath(servletContext.getInitParameter(CONFIG_LOCATION_PARAM));
+		init();
+	}
+
+	/**
+	 * 
+	 * Spring bean 注入初始化
+	 * <p>
+	 * xml 配置方法:
+	 * 
+	 * <bean id="accountConfig" class="com.uas.sso.web.AccountConfigurer"
+	 * init-method="init"> <property name="configPath"
+	 * value="classpath:account.properties" /> </bean>
+	 * </p>
+	 * 
+	 */
+	public void init() {
+		Properties prop = null;
+
+		try {
+			File file = getApplicationContext().getResource(getConfigPath()).getFile();
+			prop = getInputStream(new FileInputStream(file));
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		/**
+		 * 初始化
+		 */
+		if (prop != null) {
+			this.initProperties(prop);
+		} else {
+			logger.severe("Initializing is not available AccountConfigLocation on the classpath");
+		}
+	}
+
+	public void shutdown() {
+		logger.info("Uninstalling Account ");
+	}
+
+	private Properties getInputStream(InputStream in) {
+		Properties p = null;
+		try {
+			p = new Properties();
+			p.load(in);
+		} catch (Exception e) {
+			logger.severe(" account read config file error. \n" + e.toString());
+		}
+		return p;
+	}
+
+	public String getConfigPath() {
+		return configPath;
+	}
+
+	public void setConfigPath(String configPath) {
+		this.configPath = configPath;
+	}
+
+	@Override
+	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+		this.applicationContext = applicationContext;
+	}
+
+	public ApplicationContext getApplicationContext() {
+		return applicationContext;
+	}
+
+}

+ 13 - 3
sso-server/pom.xml

@@ -4,9 +4,9 @@
 	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
-	<groupId>com.uas.sso</groupId>
-	<artifactId>sso-parent</artifactId>
-	<version>0.0.1-SNAPSHOT</version>
+		<groupId>com.uas.sso</groupId>
+		<artifactId>sso-parent</artifactId>
+		<version>0.0.1-SNAPSHOT</version>
 	</parent>
 	<artifactId>sso-server</artifactId>
 	<packaging>war</packaging>
@@ -50,6 +50,16 @@
 			<groupId>com.alibaba</groupId>
 			<artifactId>fastjson</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>com.uas.account</groupId>
+			<artifactId>sso-core</artifactId>
+			<version>0.0.1</version>
+		</dependency>
+		<dependency>
+			<groupId>com.uas.sso</groupId>
+			<artifactId>sso-common</artifactId>
+			<version>0.0.1-SNAPSHOT</version>
+		</dependency>
 	</dependencies>
 
 	<build>

+ 122 - 0
sso-server/src/main/java/com/uas/sso/controller/BaseController.java

@@ -0,0 +1,122 @@
+package com.uas.sso.controller;
+
+import com.alibaba.fastjson.JSON;
+import com.uas.sso.core.PasswordStrength;
+import com.uas.sso.exception.VisibleError;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.ui.ModelMap;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * controller基础类
+ * 
+ * @author yingp
+ *
+ */
+public class BaseController {
+
+	protected static final String defultCharset = "UTF-8";
+
+	@Autowired
+	protected HttpServletRequest request;
+
+	@Autowired
+	protected HttpServletResponse response;
+
+	protected static boolean isSuccess(ModelMap map) {
+		return Boolean.TRUE.equals(map.get("success"));
+	}
+
+	protected static Object getContent(ModelMap map) {
+		return map.get("content");
+	}
+
+	protected static ModelMap success() {
+		return new ModelMap("success", true);
+	}
+
+	protected static ModelMap success(Object data) {
+		return new ModelMap("success", true).addAttribute("content", data);
+	}
+
+	protected static ModelMap error(String errMsg) {
+		return new ModelMap("error", true).addAttribute("errMsg", errMsg);
+	}
+
+	protected static ModelMap error(Object detail) {
+		return new ModelMap("error", true).addAttribute("errDetail", detail);
+	}
+
+	protected static ModelMap error(String errCode, String errMsg) {
+		return new ModelMap("error", true).addAttribute("errCode", errCode).addAttribute("errMsg", errMsg);
+	}
+
+	/**
+	 * 输出json格式
+	 * 
+	 * @param obj
+	 * @throws IOException
+	 */
+	protected void printJson(Object obj) throws IOException {
+		response.addHeader("Content-Type", "application/json; charset=" + defultCharset);
+		PrintWriter printWriter = response.getWriter();
+		printWriter.append(JSON.toJSONString(obj));
+		printWriter.flush();
+		printWriter.close();
+	}
+
+	/**
+	 * 响应Ajax请求
+	 * 
+	 * @param content
+	 *            响应内容
+	 * @throws IOException
+	 */
+	protected void printJsonP(String callback, Object content) throws IOException {
+		if (!content.getClass().isAssignableFrom(String.class)) {
+			content = JSON.toJSON(content);
+		}
+		response.setContentType("text/html;charset=" + defultCharset);
+		PrintWriter out = response.getWriter();
+		out.print(callback + "(" + content + ")");
+		out.flush();
+	}
+
+	/**
+	 * 输出流
+	 * 
+	 * @param fileName
+	 *            文件名
+	 * @param bytes
+	 * @throws IOException
+	 */
+	protected ResponseEntity<byte[]> outputStream(String fileName, byte[] bytes) {
+		HttpHeaders headers = new HttpHeaders();
+		headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
+		headers.setContentDispositionFormData("attachment", fileName);
+		return new ResponseEntity<byte[]>(bytes, headers, HttpStatus.CREATED);
+	}
+
+	protected PasswordStrength checkPasswordLevel(String password) throws VisibleError {
+		String strongRegex = "^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$";
+		String mediumRegex = "^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$";
+		if (password == null) {
+			throw new VisibleError("密码不能为空");
+		}
+		if (password.matches(strongRegex)) {
+			return PasswordStrength.STRONG;
+		} else if (password.matches(mediumRegex)) {
+			return PasswordStrength.MEDIUM;
+		} else {
+			return PasswordStrength.WEAK;
+		}
+	}
+}

+ 77 - 0
sso-server/src/main/java/com/uas/sso/controller/PersonalRegisterController.java

@@ -0,0 +1,77 @@
+package com.uas.sso.controller;
+
+import com.uas.sso.core.Const;
+import com.uas.sso.core.Type;
+import com.uas.sso.core.PasswordStrength;
+import com.uas.sso.entity.User;
+import com.uas.sso.logging.RegisterBufferedLogger;
+import com.uas.sso.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+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.ResponseBody;
+
+/**
+ * 个人注册controller
+ *
+ * @author uas
+ * @date 2018/1/2
+ */
+@Controller
+@RequestMapping("/sso/personal")
+public class PersonalRegisterController extends BaseController {
+
+    @Autowired
+    private UserService userService;
+
+    private RegisterBufferedLogger registerLogger = new RegisterBufferedLogger();
+
+    @RequestMapping(value = "/register", method = RequestMethod.POST)
+    @ResponseBody
+    public ModelMap register(User user, String appId) {
+        // 获取参数
+        String vipName = user.getVipName();
+        String mobile = user.getMobile();
+        String mobileArea = user.getMobileArea();
+        String password = user.getPassword();
+
+        // 参数空校验
+        if (StringUtils.isEmpty(vipName)) {
+            return error("400", "会员名不能为空");
+        }
+        if (StringUtils.isEmpty(password)) {
+            return error("400", "密码不能为空");
+        }
+        if (StringUtils.isEmpty(mobile)) {
+            return error("400", "手机号不能为空");
+        }
+
+        // 校验手机号
+        if (Const.CONTINENT.equals(mobileArea)) {
+            if (!mobile.matches(Const.REGEXP_MOBILE_CONTINENT)) {
+                return error("400", "请输入正确的手机号格式");
+            }
+        } else if (Const.HONGKONG.equals(mobileArea)) {
+            if (!mobile.matches(Const.REGEXP_MOBILE_HONGKONG)) {
+                return error("400", "请输入正确的手机号格式");
+            }
+        } else {
+            return error("400", "未找到所选地区");
+        }
+
+        // 校验密码
+        if (PasswordStrength.WEAK.equals(checkPasswordLevel(password))) {
+            return error("400", "密码强度过低,请重新输入密码");
+        }
+
+        // 注册
+        user.setFromApp(StringUtils.isEmpty(appId) ? "sso" : appId);
+        userService.register(user);
+        registerLogger.info(Type.REGISTER_PERSONAL.getValue(), 1, "个人注册成功", user, user.getFromApp());
+
+        return success();
+    }
+}

+ 30 - 0
sso-server/src/main/java/com/uas/sso/controller/UserManagerController.java

@@ -0,0 +1,30 @@
+package com.uas.sso.controller;
+
+import com.uas.sso.entity.User;
+import com.uas.sso.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * 用户信息管理controller
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+@Controller
+@RequestMapping("/api/user")
+public class UserManagerController extends BaseController {
+
+    @Autowired
+    private UserService userService;
+
+    @RequestMapping(value = "/checkMobile", method = RequestMethod.GET)
+    @ResponseBody
+    public ModelMap checkMobile(String mobile) {
+        return new ModelMap("hasRegister", userService.mobileHasRegistered(mobile));
+    }
+}

+ 45 - 0
sso-server/src/main/java/com/uas/sso/core/Const.java

@@ -0,0 +1,45 @@
+package com.uas.sso.core;
+
+/**
+ * 常量类
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+public class Const {
+
+    /**
+     * 中国大陆手机号正则
+     */
+    public static final String REGEXP_MOBILE_CONTINENT = "1[0-9]{10}";
+
+    /**
+     * 香港手机号正则
+     */
+    public static final String REGEXP_MOBILE_HONGKONG = "[0-9]{8}";
+
+    /**
+     * 中国大陆
+     */
+    public static final String CONTINENT = "continent";
+
+    /**
+     * 香港
+     */
+    public static final String HONGKONG = "Hongkong";
+
+    /**
+     * 密码加密方式
+     */
+    public static final String ENCRY_FORMAT = "$password{$salt}";
+
+    /**
+     * 密码
+     */
+    public static final String ENCRY_PARAM_PASSWORD = "$password";
+
+    /**
+     * 盐值
+     */
+    public static final String ENCRY_PARAM_SALT = "$salt";
+}

+ 35 - 0
sso-server/src/main/java/com/uas/sso/core/Level.java

@@ -0,0 +1,35 @@
+package com.uas.sso.core;
+
+/**
+ * 操作等级(主要用于日志记录)
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+public enum Level {
+
+    /**
+     * 错误的级别显示是一个严重的失败
+     */
+    ERROR("ERROR"),
+
+    /**
+     * 警告级别显示一个潜在的问题
+     */
+    WARNING("WARNING"),
+
+    /**
+     * 消息的级别显示是消息的消息级别
+     */
+    INFO("INFO");
+
+    private String value;
+
+    Level(String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return this.value;
+    }
+}

+ 35 - 0
sso-server/src/main/java/com/uas/sso/core/PasswordStrength.java

@@ -0,0 +1,35 @@
+package com.uas.sso.core;
+
+/**
+ * 密码强度
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+public enum PasswordStrength {
+
+    /**
+     * 强
+     */
+    STRONG(3),
+
+    /**
+     * 中
+     */
+    MEDIUM(2),
+
+    /**
+     * 弱
+     */
+    WEAK(1);
+
+    private int value;
+
+    PasswordStrength(int value) {
+        this.value = value;
+    }
+
+    public int getValue() {
+        return value;
+    }
+}

+ 38 - 0
sso-server/src/main/java/com/uas/sso/core/Status.java

@@ -0,0 +1,38 @@
+package com.uas.sso.core;
+
+/**
+ * 状态
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+public enum Status {
+
+    NOT_APPLYING(0, "未申请"),
+    TO_BE_CERTIFIED(1, "待认证"),
+    AUTHENTICATED(2, "已认证"),
+    NOT_PASSED(3, "未通过");
+
+    /**
+     * 代码
+     */
+    private final int code;
+
+    /**
+     * 短语描述
+     */
+    private final String phrase;
+
+    Status(int code, String phrase) {
+        this.code = code;
+        this.phrase = phrase;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public String getPhrase() {
+        return phrase;
+    }
+}

+ 55 - 0
sso-server/src/main/java/com/uas/sso/core/Type.java

@@ -0,0 +1,55 @@
+package com.uas.sso.core;
+
+/**
+ * 修改类型(主要用于日志记录)
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+public enum Type {
+
+    /**
+     * 修改类型为手机号
+     */
+    UPDATE_MOBILE("MOBILE"),
+
+    /**
+     * 修改类型为邮箱
+     */
+    UPDATE_EMAIL("EMAIL"),
+
+    /**
+     * 修改类型为密码
+     */
+    UPDATE_PASSWORD("PASSWORD"),
+
+    /**
+     * 修改类型为其他基本信息
+     */
+    UPDATE_DETAIL("DETAIL"),
+
+    /**
+     * 修改类型为注册
+     */
+    UPDATE_REGISTER("REGISTER"),
+
+    /**
+     * 注册类型为个人注册
+     */
+    REGISTER_PERSONAL("PERSONAL"),
+
+    /**
+     * 注册类型为企业注册
+     */
+    REGISTER_USERSPACE("USERSPACE");
+
+    private String value;
+
+    Type(String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return this.value;
+    }
+}

+ 14 - 0
sso-server/src/main/java/com/uas/sso/dao/RegisterLogDao.java

@@ -0,0 +1,14 @@
+package com.uas.sso.dao;
+
+import com.uas.sso.entity.RegisterLog;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+/**
+ * 注册日志dao
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+public interface RegisterLogDao extends JpaRepository<RegisterLog, Long>, JpaSpecificationExecutor<RegisterLog> {
+}

+ 57 - 0
sso-server/src/main/java/com/uas/sso/dao/UserDao.java

@@ -0,0 +1,57 @@
+package com.uas.sso.dao;
+
+import com.uas.sso.entity.User;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+/**
+ * 用户信息dao
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+public interface UserDao extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
+
+    /**
+     * 根据用户uu号查询用户信息
+     * @param userUU 用户uu号
+     * @return 用户信息
+     */
+    User findByUserUU(Long userUU);
+
+    /**
+     * 根据用户手机号查询用户信息
+     * @param mobile 用户手机号
+     * @return 用户信息
+     */
+    User findByMobile(String mobile);
+
+    /**
+     * 根据会员名查找用户信息
+     *
+     * @param vipName 会员名
+     * @return 用户信息集合
+     */
+    @Query("select u from User u where u.vipName=:vipName")
+    List<User> findByVipName(@Param("vipName") String vipName);
+
+    /**
+     * 根据用户手机号和所属区域查询用户信息
+     * @param mobile 用户手机号
+     * @param mobileArea 手机号所属区域()
+     * @return 用户信息
+     */
+    @Query("select u from User u where u.mobile=:mobile and u.mobileArea=:mobileArea")
+    User findByMobileAndMobileArea(@Param("mobile") String mobile, @Param("mobileArea") String mobileArea);
+
+    /**
+     * 查询最大的uu号
+     * @return 数据库中最大的uu号
+     */
+    @Query("select max(u.userUU) from User u")
+    Long findMaxUU();
+}

+ 15 - 0
sso-server/src/main/java/com/uas/sso/dao/UserLogDao.java

@@ -0,0 +1,15 @@
+package com.uas.sso.dao;
+
+import com.uas.sso.entity.UserLog;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+/**
+ * 用户信息修改日志dao
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+public interface UserLogDao extends JpaRepository<UserLog, Long>, JpaSpecificationExecutor<UserLog> {
+
+}

+ 38 - 0
sso-server/src/main/java/com/uas/sso/entity/App.java

@@ -0,0 +1,38 @@
+package com.uas.sso.entity;
+
+import javax.persistence.*;
+
+/**
+ * 应用
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+@Entity
+@Table(name = "sso$app")
+public class App {
+
+    @Id
+    @Column(name = "uid")
+    @GeneratedValue
+    private String uid;
+
+    @Column(name = "description")
+    private String description;
+
+    public String getUid() {
+        return uid;
+    }
+
+    public void setUid(String uid) {
+        this.uid = uid;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+}

+ 17 - 0
sso-server/src/main/java/com/uas/sso/entity/BaseLog.java

@@ -0,0 +1,17 @@
+package com.uas.sso.entity;
+
+import java.io.Serializable;
+
+/**
+ * 日志基类
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+public abstract class BaseLog implements Serializable {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+}

+ 112 - 0
sso-server/src/main/java/com/uas/sso/entity/RegisterLog.java

@@ -0,0 +1,112 @@
+package com.uas.sso.entity;
+
+/**
+ * 注册日志
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+
+import com.alibaba.fastjson.JSON;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name = "sso$register$log")
+public class RegisterLog extends BaseLog {
+
+    /**
+     * 主键
+     */
+    @Id
+    @Column(name = "_id")
+    @SequenceGenerator(name = "sso$register$log_gen", sequenceName = "sso$register$log_seq", allocationSize = 1)
+    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "sso$register$log_gen")
+    private Long id;
+
+    /**
+     * 注册类型
+     */
+    @Column(name = "type")
+    private String type;
+
+    /**
+     * 注册步数
+     */
+    @Column(name = "step")
+    private int step;
+
+    /**
+     * 当前步数描述
+     */
+    @Column(name = "msg")
+    private String msg;
+
+    /**
+     * 当前步数提交信息详情
+     */
+    @Column(name = "msgDetail")
+    private String msgDetail;
+
+    /**
+     * 注册来源
+     */
+    @Column(name = "fromApp")
+    private String fromAppUid;
+
+    public RegisterLog(String type, int step, String msg, Object msgDetail, String fromAppUid) {
+        this.type = type;
+        this.step = step;
+        this.msg = msg;
+        this.msgDetail = JSON.toJSONString(msgDetail);
+        this.fromAppUid = fromAppUid;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public int getStep() {
+        return step;
+    }
+
+    public void setStep(int step) {
+        this.step = step;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public Object getMsgDetail() {
+        return msgDetail;
+    }
+
+    public void setMsgDetail(Object msgDetail) {
+        this.msgDetail = msgDetail.toString();
+    }
+
+    public String getFromAppUid() {
+        return fromAppUid;
+    }
+
+    public void setFromAppUid(String fromAppUid) {
+        this.fromAppUid = fromAppUid;
+    }
+}

+ 372 - 0
sso-server/src/main/java/com/uas/sso/entity/User.java

@@ -0,0 +1,372 @@
+package com.uas.sso.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+/**
+ * 用户信息
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+@Entity
+@Table(name = "sso$user")
+public class User implements Serializable {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * uu号
+     */
+    @Id
+    @Column(name = "userUU")
+    private Long userUU;
+
+    /**
+     * 会员名
+     */
+    @Column(name = "vipName")
+    private String vipName;
+
+    /**
+     * 手机号
+     */
+    @Column(name = "mobile")
+    private String mobile;
+
+    /**
+     * 手机号所属区域(continent or Hongkong)
+     */
+    @Column(name = "mobileArea")
+    private String mobileArea;
+
+    /**
+     * 手机号认证状态
+     */
+    @Column(name = "mobileIsValid")
+    private Short mobileIsValid;
+
+    /**
+     * 用户密码
+     */
+    @Column(name = "_password")
+    private String password;
+
+    /**
+     * 用户erp密码
+     */
+    @Column(name = "erpPassword")
+    private String erpPassword;
+
+    /**
+     * 用户erp密码
+     */
+    @Column(name = "salt")
+    private String salt;
+
+    /**
+     * 用户erp密码
+     */
+    @Column(name = "registerDate")
+    private Timestamp registerDate;
+
+    /**
+     * 用户邮箱
+     */
+    @Column(name = "email")
+    private String email;
+
+    /**
+     * 用户邮箱
+     */
+    @Column(name = "emailIsValid")
+    private Short emailIsValid;
+
+    /**
+     * 用户真实姓名
+     */
+    @Column(name = "realName")
+    private String realName;
+
+    /**
+     * 用户身份证号
+     */
+    @Column(name = "idCard")
+    private String idCard;
+
+    /**
+     * 用户身份认证状态
+     */
+    @Column(name = "identityIsValid")
+    private Short identityIsValid;
+
+    /**
+     * 用户注册应用
+     */
+    @Column(name = "fromApp")
+    private String fromApp;
+
+    /**
+     * 姓
+     */
+    @Column(name = "firstName")
+    private String firstName;
+
+    /**
+     * 名
+     */
+    @Column(name = "lastName")
+    private String lastName;
+
+    /**
+     * 微信号(微信扫码授权或微信客户端授权,不用出现在注册页面,预留)
+     */
+    @Column(name = "wxOpenid")
+    private String wxOpenid;
+
+    /**
+     * qq号(qq扫码或qq客户端授权,不用出现在注册页面,预留)
+     */
+    @Column(name = "qqNumber")
+    private Integer qqNumber;
+
+    /**
+     * 国籍(不用出现在注册页面,预留)
+     */
+    @Column(name = "nationality")
+    private String nationality;
+
+    /**
+     * 籍贯(不用出现在注册页面,预留)
+     */
+    @Column(name = "nativePlace")
+    private String nativePlace;
+
+    /**
+     * 现在所在国家(不用出现在注册页面,预留)
+     */
+    @Column(name = "country")
+    private String country;
+
+    /**
+     * 现在所在省份、州、直辖市、行政区(不用出现在注册页面,预留)
+     */
+    @Column(name = "province")
+    private String province;
+
+    /**
+     * 现在所在城市(不用出现在注册页面,预留)
+     */
+    @Column(name = "city")
+    private String city;
+
+    /**
+     * 账户是否冻结(1、冻结)
+     */
+    @Column(name = "_lock")
+    private Integer lock;
+
+    public Long getUserUU() {
+        return userUU;
+    }
+
+    public void setUserUU(Long userUU) {
+        this.userUU = userUU;
+    }
+
+    public String getVipName() {
+        return vipName;
+    }
+
+    public void setVipName(String vipName) {
+        this.vipName = vipName;
+    }
+
+    public String getMobile() {
+        return mobile;
+    }
+
+    public void setMobile(String mobile) {
+        this.mobile = mobile;
+    }
+
+    public String getMobileArea() {
+        return mobileArea;
+    }
+
+    public void setMobileArea(String mobileArea) {
+        this.mobileArea = mobileArea;
+    }
+
+    public Short getMobileIsValid() {
+        return mobileIsValid;
+    }
+
+    public void setMobileIsValid(Short mobileIsValid) {
+        this.mobileIsValid = mobileIsValid;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getErpPassword() {
+        return erpPassword;
+    }
+
+    public void setErpPassword(String erpPassword) {
+        this.erpPassword = erpPassword;
+    }
+
+    public String getSalt() {
+        return salt;
+    }
+
+    public void setSalt(String salt) {
+        this.salt = salt;
+    }
+
+    public 	Timestamp getRegisterDate() {
+        return registerDate;
+    }
+
+    public void setRegisterDate(Timestamp registerDate) {
+        this.registerDate = registerDate;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public Short getEmailIsValid() {
+        return emailIsValid;
+    }
+
+    public void setEmailIsValid(Short emailIsValid) {
+        this.emailIsValid = emailIsValid;
+    }
+
+    public String getName() {
+        return realName;
+    }
+
+    public void setName(String name) {
+        this.realName = name;
+    }
+
+    public String getIdCard() {
+        return idCard;
+    }
+
+    public void setIdCard(String idCard) {
+        this.idCard = idCard;
+    }
+
+    public Short getIdentityIsValid() {
+        return identityIsValid;
+    }
+
+    public void setIdentityIsValid(Short identityIsValid) {
+        this.identityIsValid = identityIsValid;
+    }
+
+    public String getFromApp() {
+        return fromApp;
+    }
+
+    public void setFromApp(String fromApp) {
+        this.fromApp = fromApp;
+    }
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public String getWxOpenid() {
+        return wxOpenid;
+    }
+
+    public void setWxOpenid(String wxOpenid) {
+        this.wxOpenid = wxOpenid;
+    }
+
+    public Integer getQqNumber() {
+        return qqNumber;
+    }
+
+    public void setQqNumber(Integer qqNumber) {
+        this.qqNumber = qqNumber;
+    }
+
+    public String getNationality() {
+        return nationality;
+    }
+
+    public void setNationality(String nationality) {
+        this.nationality = nationality;
+    }
+
+    public String getNativePlace() {
+        return nativePlace;
+    }
+
+    public void setNativePlace(String nativePlace) {
+        this.nativePlace = nativePlace;
+    }
+
+    public String getCountry() {
+        return country;
+    }
+
+    public void setCountry(String country) {
+        this.country = country;
+    }
+
+    public String getProvince() {
+        return province;
+    }
+
+    public void setProvince(String province) {
+        this.province = province;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public Integer getLock() {
+        return lock;
+    }
+
+    public void setLock(Integer lock) {
+        this.lock = lock;
+    }
+}

+ 148 - 0
sso-server/src/main/java/com/uas/sso/entity/UserLog.java

@@ -0,0 +1,148 @@
+package com.uas.sso.entity;
+
+import com.alibaba.fastjson.JSON;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+/**
+ * 用户信息修改日志
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+@Entity
+@Table(name = "sso$user$log")
+public class UserLog extends BaseLog implements Serializable {
+
+    /**
+     * 主键
+     */
+    @Id
+    @Column(name = "_id")
+    @SequenceGenerator(name="sso$user$log_gen", sequenceName="sso$user$log_seq", allocationSize=1)
+    @GeneratedValue(strategy=GenerationType.IDENTITY, generator="sso$user$log_gen")
+    private Long id;
+
+    /**
+     * 用户uu号
+     */
+    @Column(name = "userUU")
+    private Long userUU;
+
+    /**
+     * 用户
+     */
+    @ManyToOne
+    @JoinColumn(name = "userUU", nullable = false, insertable=false, updatable=false)
+    private User user;
+
+    /**
+     * 修改等级(info or error)
+     */
+    @Column(name = "level", nullable = false)
+    private String level;
+
+    /**
+     * 修改类型(mobile, email, password, detail...)
+     */
+    @Column(name = "type", nullable = false)
+    private String type;
+
+    /**
+     * 修改时间
+     */
+    @Column(name = "time", nullable = false)
+    private Timestamp time;
+
+    /**
+     * 修改后用户信息
+     */
+    @Column(name = "userMsg", nullable = false)
+    private String userMsg;
+
+    /**
+     * 其他信息
+     */
+    @Column(name = "otherMsg")
+    private String otherMsg;
+
+    public UserLog(User user, String level, String type) {
+        this(user, level, type, null);
+    }
+
+    public UserLog(User user, String level, String type, String otherMsg) {
+        this.userUU = user == null ? null : user.getUserUU();
+        this.user = user;
+        this.level = level;
+        this.type = type;
+        this.time = new Timestamp(System.currentTimeMillis());
+        this.userMsg = JSON.toJSONString(user);
+        this.otherMsg = otherMsg;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getUserUU() {
+        return userUU;
+    }
+
+    public void setUserUU(Long userUU) {
+        this.userUU = userUU;
+    }
+
+    public User getUser() {
+        return user;
+    }
+
+    public void setUser(User user) {
+        this.user = user;
+    }
+
+    public String getLevel() {
+        return level;
+    }
+
+    public void setLevel(String level) {
+        this.level = level;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public Timestamp getTime() {
+        return time;
+    }
+
+    public void setTime(Timestamp time) {
+        this.time = time;
+    }
+
+    public String getUserMsg() {
+        return userMsg;
+    }
+
+    public void setUserMsg(String userMsg) {
+        this.userMsg = userMsg;
+    }
+
+    public String getOtherMsg() {
+        return otherMsg;
+    }
+
+    public void setOtherMsg(String otherMsg) {
+        this.otherMsg = otherMsg;
+    }
+}

+ 23 - 0
sso-server/src/main/java/com/uas/sso/exception/VisibleError.java

@@ -0,0 +1,23 @@
+package com.uas.sso.exception;
+
+/**
+ * 可以直接显示给用户的错误信息
+ * 
+ * @author yingp
+ *
+ */
+public class VisibleError extends RuntimeException {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1438034231246046546L;
+
+	public VisibleError() {
+	}
+
+	public VisibleError(String errMsg) {
+		super(errMsg);
+	}
+
+}

+ 32 - 0
sso-server/src/main/java/com/uas/sso/logging/Logger.java

@@ -0,0 +1,32 @@
+package com.uas.sso.logging;
+
+import com.uas.sso.entity.BaseLog;
+import com.uas.sso.service.BaseLogService;
+
+/**
+ *
+ * @author uas
+ * @date 2018/1/3
+ */
+public abstract class Logger<T extends BaseLog> {
+
+    private BaseLogService<T> logService;
+
+    protected Logger() {
+
+    }
+
+    protected Logger(BaseLogService<T> logService) {
+        this.logService = logService;
+    }
+
+    /**
+     * 保存日志
+     * @param logger 日志
+     */
+    protected void log(T logger) {
+        if(this.logService != null) {
+            this.logService.save(logger);
+        }
+    }
+}

+ 25 - 0
sso-server/src/main/java/com/uas/sso/logging/RegisterBufferedLogger.java

@@ -0,0 +1,25 @@
+package com.uas.sso.logging;
+
+import com.uas.sso.core.Level;
+import com.uas.sso.entity.RegisterLog;
+import com.uas.sso.entity.User;
+import com.uas.sso.entity.UserLog;
+import com.uas.sso.service.RegisterLogService;
+import com.uas.sso.service.UserLogService;
+import com.uas.sso.util.ContextUtils;
+
+/**
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+public class RegisterBufferedLogger extends Logger<RegisterLog> {
+
+    public RegisterBufferedLogger() {
+        super(ContextUtils.getBean(RegisterLogService.class));
+    }
+
+    public void info(String type, int step, String msg, Object msgDetail, String fromAppUid) {
+        log(new RegisterLog(type, step, msg, msgDetail, fromAppUid));
+    }
+}

+ 27 - 0
sso-server/src/main/java/com/uas/sso/logging/UserBufferedLogger.java

@@ -0,0 +1,27 @@
+package com.uas.sso.logging;
+
+import com.uas.sso.core.Level;
+import com.uas.sso.entity.User;
+import com.uas.sso.entity.UserLog;
+import com.uas.sso.service.UserLogService;
+import com.uas.sso.util.ContextUtils;
+
+/**
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+public class UserBufferedLogger extends Logger<UserLog> {
+
+    public UserBufferedLogger() {
+        super(ContextUtils.getBean(UserLogService.class));
+    }
+
+    public void error(User user, String type, String errMsg) {
+        log(new UserLog(user, Level.ERROR.getValue(), type, errMsg));
+    }
+
+    public void info(User user, String type) {
+        log(new UserLog(user, Level.INFO.getValue(), type));
+    }
+}

+ 31 - 0
sso-server/src/main/java/com/uas/sso/service/BaseLogService.java

@@ -0,0 +1,31 @@
+package com.uas.sso.service;
+
+import com.uas.sso.entity.BaseLog;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * 日志service基类
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+public interface BaseLogService<T extends BaseLog> {
+
+    /**
+     * 保存日志
+     *
+     * @param logger 日志
+     * @return 保存后日志
+     */
+    T save(T logger);
+
+    /**
+     * 保存日志
+     *
+     * @param loggers 日志集合
+     * @return 保存后日志集合
+     */
+    List<T> save(Iterable<T> loggers);
+}

+ 12 - 0
sso-server/src/main/java/com/uas/sso/service/RegisterLogService.java

@@ -0,0 +1,12 @@
+package com.uas.sso.service;
+
+import com.uas.sso.entity.RegisterLog;
+
+/**
+ * 注册日志
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+public interface RegisterLogService extends BaseLogService<RegisterLog> {
+}

+ 13 - 0
sso-server/src/main/java/com/uas/sso/service/UserLogService.java

@@ -0,0 +1,13 @@
+package com.uas.sso.service;
+
+import com.uas.sso.entity.UserLog;
+
+/**
+ * 用户信息修改日志service
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+public interface UserLogService extends BaseLogService<UserLog> {
+
+}

+ 48 - 0
sso-server/src/main/java/com/uas/sso/service/UserService.java

@@ -0,0 +1,48 @@
+package com.uas.sso.service;
+
+import com.uas.sso.entity.User;
+
+/**
+ * 用户信息service
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+public interface UserService {
+
+    /**
+     * 根据手机号查找用户基本信息
+     *
+     * @param mobile 手机号
+     * @param mobileArea 手机所属地区
+     * @return 查找到用户,未找到为null
+     */
+    User findByMobile(String mobile, String mobileArea);
+
+    /**
+     * 判断手机号是否已经注册
+     *
+     * @param mobile 用户手机号
+     * @return
+     *      true: 已经被注册
+     *      false: 未被注册
+     */
+    boolean mobileHasRegistered(String mobile);
+
+    /**
+     * 注册新用户
+     *
+     * @param user 用户信息
+     */
+    User register(User user);
+
+    /**
+     * 获取密码密文
+     *
+     * @param format 加密方式
+     * @param noEncryPwd 未加密的密码
+     * @param salt 盐值
+     * @return 加密后的密码
+     */
+    String getEncryPassword(String format, String noEncryPwd, String salt);
+}

+ 32 - 0
sso-server/src/main/java/com/uas/sso/service/impl/RegisterLogServiceImpl.java

@@ -0,0 +1,32 @@
+package com.uas.sso.service.impl;
+
+import com.uas.sso.dao.RegisterLogDao;
+import com.uas.sso.entity.RegisterLog;
+import com.uas.sso.service.RegisterLogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 注册日志service实现
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+@Service
+public class RegisterLogServiceImpl implements RegisterLogService {
+
+    @Autowired
+    private RegisterLogDao registerLogDao;
+
+    @Override
+    public RegisterLog save(RegisterLog logger) {
+        return registerLogDao.save(logger);
+    }
+
+    @Override
+    public List<RegisterLog> save(Iterable<RegisterLog> loggers) {
+        return registerLogDao.save(loggers);
+    }
+}

+ 32 - 0
sso-server/src/main/java/com/uas/sso/service/impl/UserLogServiceImpl.java

@@ -0,0 +1,32 @@
+package com.uas.sso.service.impl;
+
+import com.uas.sso.dao.UserLogDao;
+import com.uas.sso.entity.UserLog;
+import com.uas.sso.service.UserLogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 用户日志service实现
+ *
+ * @author wangmh
+ * @date 2018/1/3
+ */
+@Service
+public class UserLogServiceImpl implements UserLogService {
+
+    @Autowired
+    private UserLogDao userLogDao;
+
+    @Override
+    public UserLog save(UserLog userLog) {
+        return userLogDao.save(userLog);
+    }
+
+    @Override
+    public List<UserLog> save(Iterable<UserLog> loggers) {
+        return userLogDao.save(loggers);
+    }
+}

+ 86 - 0
sso-server/src/main/java/com/uas/sso/service/impl/UserServiceImpl.java

@@ -0,0 +1,86 @@
+package com.uas.sso.service.impl;
+
+import com.uas.sso.common.encrypt.MD5;
+import com.uas.sso.core.Const;
+import com.uas.sso.core.Status;
+import com.uas.sso.core.Type;
+import com.uas.sso.dao.UserDao;
+import com.uas.sso.entity.User;
+import com.uas.sso.exception.VisibleError;
+import com.uas.sso.logging.UserBufferedLogger;
+import com.uas.sso.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import com.uas.sso.exception.AccountException;
+
+import java.sql.Timestamp;
+
+/**
+ * 用户service实现类
+ *
+ * @author wangmh
+ * @date 2018/1/2
+ */
+@Service
+public class UserServiceImpl implements UserService {
+
+    @Autowired
+    private UserDao userDao;
+
+    private UserBufferedLogger userLog = new UserBufferedLogger();
+
+    @Override
+    public User findByMobile(String mobile, String mobileArea) {
+        return userDao.findByMobileAndMobileArea(mobile, mobileArea);
+    }
+
+    @Override
+    public boolean mobileHasRegistered(String mobile) {
+        User user = userDao.findByMobile(mobile);
+        if (user == null) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public User register(User user) {
+        // 校验手机号是否被注册
+        if (mobileHasRegistered(user.getMobile())) {
+            throw new VisibleError("该手机号已被注册");
+        }
+
+        // 设置基本属性,手机号默认已认证
+        user.setRegisterDate(new Timestamp(System.currentTimeMillis()));
+        Long uu = userDao.findMaxUU();
+        user.setUserUU(uu == null ? 10000 : (uu + 1));
+        user.setSalt(String.valueOf(user.getUserUU()));
+        user.setMobileIsValid((short) Status.AUTHENTICATED.getCode());
+        user.setEmailIsValid((short) Status.NOT_APPLYING.getCode());
+        user.setIdentityIsValid((short) Status.NOT_APPLYING.getCode());
+        user.setPassword(getEncryPassword(Const.ENCRY_FORMAT, user.getPassword(), user.getSalt()));
+
+        userDao.save(user);
+        userLog.info(user, Type.UPDATE_REGISTER.getValue());
+        return user;
+    }
+
+    @Override
+    public String getEncryPassword(String format, String noEncryPwd, String salt) {
+        if (StringUtils.isEmpty(format)) {
+            return noEncryPwd;
+        }
+        // 超过32认为是已加密过的密文
+        if (noEncryPwd.length() >= 32) {
+            /// 之后添加日志时恢复
+            //logger.error("用户密码加密", String.format("传递过来的密码(%s)必须是未加密的明文", noEncryPwd));
+            throw new AccountException("invalid password");
+        }
+        // $password{$salt}
+        String password = format.replace(Const.ENCRY_PARAM_PASSWORD, noEncryPwd);
+        password = password.replace(Const.ENCRY_PARAM_SALT, salt == null ? "" : salt);
+        return MD5.toMD5(password);
+    }
+}

+ 48 - 0
sso-server/src/main/java/com/uas/sso/web/advice/ExceptionHandlerAdvice.java

@@ -0,0 +1,48 @@
+package com.uas.sso.web.advice;
+
+import com.uas.sso.exception.VisibleError;
+import org.apache.log4j.Logger;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+@ControllerAdvice
+public class ExceptionHandlerAdvice {
+
+	private final static Logger logger = Logger.getLogger(ExceptionHandlerAdvice.class);
+
+	private ModelMap error(String errMsg) {
+		return new ModelMap("error", true).addAttribute("errMsg", errMsg);
+	}
+
+	/**
+	 * 处理运行时抛出异常
+	 * 
+	 * @param ex 运行时异常
+	 * @return 键值对
+	 */
+	@ExceptionHandler(RuntimeException.class)
+	public ResponseEntity<ModelMap> handleRuntimeException(RuntimeException ex) {
+		logger.error("RuntimeException", ex);
+		HttpHeaders headers = new HttpHeaders();
+		headers.add("Content-Type", "application/json; charset=utf-8");
+		return new ResponseEntity<ModelMap>(error("出现异常"), headers, HttpStatus.OK);
+	}
+
+	/**
+	 * 允许用户看见的异常信息,直接传递给客户端
+	 * 
+	 * @param ex 允许用户看见的异常信息
+	 * @return
+	 */
+	@ExceptionHandler(VisibleError.class)
+	public ResponseEntity<ModelMap> handleVisibleError(VisibleError ex) {
+		HttpHeaders headers = new HttpHeaders();
+		headers.add("Content-Type", "application/json; charset=utf-8");
+		return new ResponseEntity<ModelMap>(error(ex.getMessage()), headers, HttpStatus.OK);
+	}
+
+}