Browse Source

sso接口

yingp 7 years ago
parent
commit
b8d549d813

+ 23 - 0
base-servers/account/account-server/src/test/java/com/usoftchina/saas/account/api/AccountCacheTest.java

@@ -0,0 +1,23 @@
+package com.usoftchina.saas.account.api;
+
+import com.usoftchina.saas.account.cache.AccountCache;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * @author yingp
+ * @date 2018/11/23
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class AccountCacheTest {
+
+    @Test
+    public void hdel() {
+        AccountCache.of(43).hdel();
+        System.out.println(AccountCache.of(43).exists());
+    }
+}

+ 18 - 0
base-servers/account/account-server/src/test/java/com/usoftchina/saas/account/service/AccountServiceTest.java

@@ -1,13 +1,19 @@
 package com.usoftchina.saas.account.service;
 
+import com.usoftchina.saas.account.cache.AccountCache;
 import com.usoftchina.saas.account.constant.AccountType;
+import com.usoftchina.saas.account.dto.AccountDTO;
 import com.usoftchina.saas.account.po.Account;
+import com.usoftchina.saas.utils.CollectionUtils;
 import org.junit.*;
 import org.junit.runner.RunWith;
 import org.junit.runners.MethodSorters;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+import java.util.Set;
 //import org.springframework.transaction.annotation.Transactional;
 
 @RunWith(SpringRunner.class)
@@ -54,4 +60,16 @@ public class AccountServiceTest {
         Assert.assertTrue(removed);
     }
 
+    @Test
+    public void testD_clearAccountCacheByRoleId() {
+        long roleId = 25;
+        List<Account> accounts = accountService.findByRoleId(roleId);
+        if (!CollectionUtils.isEmpty(accounts)) {
+            accounts.forEach(account -> accountService.clearCache(account.getId()));
+        }
+        AccountCache.current().keys().forEach(System.out::println);
+
+        AccountCache.of(43).getAccount();
+    }
+
 }

+ 1 - 0
base-servers/auth/pom.xml

@@ -18,6 +18,7 @@
         <module>auth-server</module>
         <module>auth-client</module>
         <module>auth-common</module>
+        <module>sso-api</module>
     </modules>
 
 </project>

+ 32 - 0
base-servers/auth/sso-api/pom.xml

@@ -0,0 +1,32 @@
+<?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">
+    <parent>
+        <artifactId>auth</artifactId>
+        <groupId>com.usoftchina.saas</groupId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>sso-api</artifactId>
+    <description>account center api</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.usoftchina.saas</groupId>
+            <artifactId>core</artifactId>
+        </dependency>
+        <!-- test -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>

+ 51 - 0
base-servers/auth/sso-api/src/main/java/com/usoftchina/sso/api/SsoUserApi.java

@@ -0,0 +1,51 @@
+package com.usoftchina.sso.api;
+
+import com.usoftchina.sso.dto.SsoResult;
+import com.usoftchina.sso.dto.SsoUser;
+import com.usoftchina.sso.dto.SsoUserSpaceList;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * @author yingp
+ * @date 2018/11/23
+ */
+@FeignClient(url = "${sso.base-url}", name = "sso-server", fallback = SsoUserApi.DefaultFallback.class)
+@RequestMapping("/api/user")
+public interface SsoUserApi {
+
+    /**
+     * 手机号查找用户
+     *
+     * @param userUU
+     * @return
+     */
+    @GetMapping("/info")
+    SsoResult<SsoUser> getUserByUu(@RequestParam("userUU") Long userUU);
+
+    /**
+     * 手机号查找绑定企业
+     *
+     * @param mobile
+     * @return
+     */
+    @GetMapping("/getSpace")
+    @Deprecated
+    SsoUserSpaceList getUserSpacesByMobile(@RequestParam("mobile") String mobile);
+
+    @Component
+    class DefaultFallback implements SsoUserApi{
+        @Override
+        public SsoResult<SsoUser> getUserByUu(Long userUU) {
+            return SsoResult.fallback();
+        }
+
+        @Override
+        public SsoUserSpaceList getUserSpacesByMobile(String mobile) {
+            return null;
+        }
+    }
+}

+ 8 - 0
base-servers/auth/sso-api/src/main/java/com/usoftchina/sso/api/SsoUserSpaceApi.java

@@ -0,0 +1,8 @@
+package com.usoftchina.sso.api;
+
+/**
+ * @author yingp
+ * @date 2018/11/23
+ */
+public interface SsoUserSpaceApi {
+}

+ 85 - 0
base-servers/auth/sso-api/src/main/java/com/usoftchina/sso/dto/SsoResult.java

@@ -0,0 +1,85 @@
+package com.usoftchina.sso.dto;
+
+import com.usoftchina.saas.exception.ExceptionCode;
+
+/**
+ * @author yingp
+ * @date 2018/11/23
+ */
+public class SsoResult<T> {
+    private boolean success;
+
+    private boolean error;
+
+    private String errCode;
+
+    private String errMsg;
+
+    private String errDetail;
+
+    private T content;
+
+    public SsoResult() {
+    }
+
+    /**
+     * 异常返回
+     *
+     * @return
+     */
+    public static SsoResult fallback() {
+        SsoResult result = new SsoResult();
+        result.setError(true);
+        result.setErrCode(String.valueOf(ExceptionCode.SYSTEM_BUSY.getCode()));
+        result.setErrMsg(ExceptionCode.SYSTEM_BUSY.getMessage());
+        return result;
+    }
+
+    public boolean isSuccess() {
+        return success;
+    }
+
+    public void setSuccess(boolean success) {
+        this.success = success;
+    }
+
+    public boolean isError() {
+        return error;
+    }
+
+    public void setError(boolean error) {
+        this.error = error;
+    }
+
+    public String getErrMsg() {
+        return errMsg;
+    }
+
+    public void setErrMsg(String errMsg) {
+        this.errMsg = errMsg;
+    }
+
+    public String getErrCode() {
+        return errCode;
+    }
+
+    public void setErrCode(String errCode) {
+        this.errCode = errCode;
+    }
+
+    public String getErrDetail() {
+        return errDetail;
+    }
+
+    public void setErrDetail(String errDetail) {
+        this.errDetail = errDetail;
+    }
+
+    public T getContent() {
+        return content;
+    }
+
+    public void setContent(T content) {
+        this.content = content;
+    }
+}

+ 251 - 0
base-servers/auth/sso-api/src/main/java/com/usoftchina/sso/dto/SsoUser.java

@@ -0,0 +1,251 @@
+package com.usoftchina.sso.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import java.io.Serializable;
+
+/**
+ * @author yingp
+ * @date 2018/11/23
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class SsoUser implements Serializable{
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * uu号
+     */
+    private Long userUU;
+
+    /**
+     * 会员名
+     */
+    private String vipName;
+
+    /**
+     * 手机号
+     */
+    private String mobile;
+
+    /**
+     * 手机号所属区域(continent or Hongkong)
+     */
+    private String mobileArea;
+
+    /**
+     * 手机号认证状态
+     */
+    private Short mobileValidCode;
+
+    /**
+     * 用户密码
+     */
+    private String password;
+
+    /**
+     * 用户erp密码
+     */
+    private String erpPassword;
+
+    /**
+     * 盐值
+     */
+    private String salt;
+
+    /**
+     * 用户邮箱
+     */
+    private String email;
+
+    /**
+     * 用户邮箱认证状态
+     */
+    private Short emailValidCode;
+
+    /**
+     * 身份认证状态
+     */
+    private Short identityValidCode;
+
+    /**
+     * 账户是否冻结(1、冻结)
+     */
+    private Short lock;
+
+    /**
+     * 企业uu号
+     */
+    private Long spaceUU;
+
+    /**
+     * 企业名称
+     */
+    private String spaceName;
+
+    /**
+     * 营业执照号
+     */
+    private String businessCode;
+
+    /**
+     * 企业域名
+     */
+    private String spaceDomain;
+
+    /**
+     * 应用唯一标志
+     */
+    private String appId;
+
+    /**
+     * 上次登录时间
+     */
+    private Long lastLoginTime;
+
+    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 getMobileValidCode() {
+        return mobileValidCode;
+    }
+
+    public void setMobileValidCode(Short mobileValidCode) {
+        this.mobileValidCode = mobileValidCode;
+    }
+
+    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 String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public Short getEmailValidCode() {
+        return emailValidCode;
+    }
+
+    public void setEmailValidCode(Short emailValidCode) {
+        this.emailValidCode = emailValidCode;
+    }
+
+    public Short getIdentityValidCode() {
+        return identityValidCode;
+    }
+
+    public void setIdentityValidCode(Short identityValidCode) {
+        this.identityValidCode = identityValidCode;
+    }
+
+    public Short getLock() {
+        return lock;
+    }
+
+    public void setLock(Short lock) {
+        this.lock = lock;
+    }
+
+    public Long getSpaceUU() {
+        return spaceUU;
+    }
+
+    public void setSpaceUU(Long spaceUU) {
+        this.spaceUU = spaceUU;
+    }
+
+    public String getSpaceName() {
+        return spaceName;
+    }
+
+    public void setSpaceName(String spaceName) {
+        this.spaceName = spaceName;
+    }
+
+    public String getBusinessCode() {
+        return businessCode;
+    }
+
+    public void setBusinessCode(String businessCode) {
+        this.businessCode = businessCode;
+    }
+
+    public String getSpaceDomain() {
+        return spaceDomain;
+    }
+
+    public void setSpaceDomain(String spaceDomain) {
+        this.spaceDomain = spaceDomain;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
+
+    public Long getLastLoginTime() {
+        return lastLoginTime;
+    }
+
+    public void setLastLoginTime(Long lastLoginTime) {
+        this.lastLoginTime = lastLoginTime;
+    }
+}

+ 191 - 0
base-servers/auth/sso-api/src/main/java/com/usoftchina/sso/dto/SsoUserSpace.java

@@ -0,0 +1,191 @@
+package com.usoftchina.sso.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import java.io.Serializable;
+
+/**
+ * @author yingp
+ * @date 2018/11/23
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class SsoUserSpace implements Serializable{
+    /**
+     * 企业uu号
+     */
+    private Long spaceUU;
+
+    /**
+     * 企业名称
+     */
+    private String spaceName;
+
+    /**
+     * 法定代表人
+     */
+    private String corporation;
+
+    /**
+     * 注册日期
+     */
+    private Long registerDate;
+
+    /**
+     * 管理员
+     */
+    private SsoUser admin;
+
+    /**
+     * 营业执照号
+     */
+    private String businessCode;
+
+    /**
+     * 营业执照
+     */
+    private String businessCodeImage;
+
+    /**
+     * 注册地址
+     */
+    private String regAddress;
+
+    /**
+     * 企业信息认证状态
+     */
+    private Short validCode;
+
+    /**
+     * logo图片
+     */
+    private String logoImage;
+
+    /**
+     * 企业联系电话
+     */
+    private String telephone;
+
+    /**
+     * 行业
+     */
+    private String profession;
+
+    /**
+     * 经营范围标签,逗号分隔
+     */
+    private String tags;
+
+    private String accessSecret;
+
+    public Long getSpaceUU() {
+        return spaceUU;
+    }
+
+    public void setSpaceUU(Long spaceUU) {
+        this.spaceUU = spaceUU;
+    }
+
+    public String getSpaceName() {
+        return spaceName;
+    }
+
+    public void setSpaceName(String spaceName) {
+        this.spaceName = spaceName;
+    }
+
+    public String getCorporation() {
+        return corporation;
+    }
+
+    public void setCorporation(String corporation) {
+        this.corporation = corporation;
+    }
+
+    public Long getRegisterDate() {
+        return registerDate;
+    }
+
+    public void setRegisterDate(Long registerDate) {
+        this.registerDate = registerDate;
+    }
+
+    public SsoUser getAdmin() {
+        return admin;
+    }
+
+    public void setAdmin(SsoUser admin) {
+        this.admin = admin;
+    }
+
+    public String getBusinessCode() {
+        return businessCode;
+    }
+
+    public void setBusinessCode(String businessCode) {
+        this.businessCode = businessCode;
+    }
+
+    public String getBusinessCodeImage() {
+        return businessCodeImage;
+    }
+
+    public void setBusinessCodeImage(String businessCodeImage) {
+        this.businessCodeImage = businessCodeImage;
+    }
+
+    public String getRegAddress() {
+        return regAddress;
+    }
+
+    public void setRegAddress(String regAddress) {
+        this.regAddress = regAddress;
+    }
+
+    public Short getValidCode() {
+        return validCode;
+    }
+
+    public void setValidCode(Short validCode) {
+        this.validCode = validCode;
+    }
+
+    public String getLogoImage() {
+        return logoImage;
+    }
+
+    public void setLogoImage(String logoImage) {
+        this.logoImage = logoImage;
+    }
+
+    public String getTelephone() {
+        return telephone;
+    }
+
+    public void setTelephone(String telephone) {
+        this.telephone = telephone;
+    }
+
+    public String getProfession() {
+        return profession;
+    }
+
+    public void setProfession(String profession) {
+        this.profession = profession;
+    }
+
+    public String getTags() {
+        return tags;
+    }
+
+    public void setTags(String tags) {
+        this.tags = tags;
+    }
+
+    public String getAccessSecret() {
+        return accessSecret;
+    }
+
+    public void setAccessSecret(String accessSecret) {
+        this.accessSecret = accessSecret;
+    }
+}

+ 20 - 0
base-servers/auth/sso-api/src/main/java/com/usoftchina/sso/dto/SsoUserSpaceList.java

@@ -0,0 +1,20 @@
+package com.usoftchina.sso.dto;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author yingp
+ * @date 2018/11/23
+ */
+public class SsoUserSpaceList implements Serializable{
+    private List<SsoUserSpace> spaces;
+
+    public List<SsoUserSpace> getSpaces() {
+        return spaces;
+    }
+
+    public void setSpaces(List<SsoUserSpace> spaces) {
+        this.spaces = spaces;
+    }
+}

+ 18 - 0
base-servers/auth/sso-api/src/test/java/com/usoftchina/sso/test/SsoTest.java

@@ -0,0 +1,18 @@
+package com.usoftchina.sso.test;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+/**
+ * @author yingp
+ * @date 2018/11/23
+ */
+@SpringBootApplication(scanBasePackages = "com.usoftchina")
+@EnableFeignClients("com.usoftchina.sso")
+public class SsoTest {
+
+    public static void main(String[] args) {
+        SpringApplication.run(SsoTest.class, args);
+    }
+}

+ 47 - 0
base-servers/auth/sso-api/src/test/java/com/usoftchina/sso/test/SsoUserApiTest.java

@@ -0,0 +1,47 @@
+package com.usoftchina.sso.test;
+
+import com.usoftchina.saas.utils.CollectionUtils;
+import com.usoftchina.sso.api.SsoUserApi;
+import com.usoftchina.sso.dto.SsoResult;
+import com.usoftchina.sso.dto.SsoUser;
+import com.usoftchina.sso.dto.SsoUserSpaceList;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * @author yingp
+ * @date 2018/11/23
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class SsoUserApiTest {
+
+    @Autowired
+    private SsoUserApi ssoUserApi;
+
+    final static long userUU = 200040149;
+
+    final static String mobile = "13798490565";
+
+    @Test
+    public void testA_getUserByUu() {
+        SsoResult<SsoUser> result = ssoUserApi.getUserByUu(userUU);
+        if (result.isSuccess()) {
+            System.out.println(result.getContent().getVipName());
+        }
+    }
+
+    @Test
+    public void testB_getUserSpacesByMobile() {
+        SsoUserSpaceList list = ssoUserApi.getUserSpacesByMobile(mobile);
+        if (null != list && !CollectionUtils.isEmpty(list.getSpaces())) {
+            list.getSpaces().forEach(space -> System.out.println(space.getSpaceName()));
+        }
+    }
+}

+ 3 - 0
base-servers/auth/sso-api/src/test/resources/application.yml

@@ -0,0 +1,3 @@
+sso:
+  base-url: http://192.168.253.12:32323
+#  base-url: https://sso.ubtob.com

+ 7 - 0
framework/core/src/main/java/com/usoftchina/saas/cache/RedisHashCache.java

@@ -4,6 +4,7 @@ import org.springframework.data.redis.core.BoundHashOperations;
 import org.springframework.data.redis.core.RedisTemplate;
 
 import java.util.Optional;
+import java.util.Set;
 import java.util.function.Supplier;
 
 /**
@@ -27,6 +28,10 @@ public abstract class RedisHashCache<K, F, V> extends BaseRedisCache<K, V> {
         return super.getRedisTemplate().boundHashOps(key());
     }
 
+    public Set<F> keys() {
+        return this.getBoundHashOperations().keys();
+    }
+
     /**
      * 获取
      *
@@ -89,4 +94,6 @@ public abstract class RedisHashCache<K, F, V> extends BaseRedisCache<K, V> {
     public void hdel() {
         this.getBoundHashOperations().delete(this.field());
     }
+
+
 }