martin 3 anos atrás
pai
commit
faf60a2d32

+ 2 - 0
simulation-gateway/src/main/java/com/css/simulation/gateway/SimulationGatewayApplication.java

@@ -2,8 +2,10 @@ package com.css.simulation.gateway;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 
 @SpringBootApplication
+@EnableDiscoveryClient
 public class SimulationGatewayApplication {
 
     public static void main(String[] args) {

+ 7 - 17
simulation-gateway/src/main/resources/bootstrap.yml

@@ -1,6 +1,5 @@
-#* -------------------------------- 服务器端口 --------------------------------
 server:
-  port: 8888
+  port: 6001
 
 spring:
   application:
@@ -13,18 +12,9 @@ spring:
     #* -------------------------------- 注册中心 --------------------------------
     nacos:
       discovery:
-        server-addr: localhost:8841                     # 将配置中心注册进注册中心
-      config: # ${prefix}- ${spring.profiles.active}.${file-extension}
-        server-addr: localhost:8841                     # 从注册中心的微服务列表读取配置
-        namespace: 40cc3b1a-33b1-488a-98dc-4ae0570992ee # 配置命名空间 id,命名空间一般为项目名
-        file-extension: yaml                            # 读取 yaml 类型的文件
-    #* -------------------------------- gateway 网关 --------------------------------
-    gateway:
-      discovery:
-        locator:
-          enabled: true                 # 开启从注册中心动态创建路由的功能,利用微服务名进行路由
-      routes:
-        - id: route_project_auth                      # 权限认证路由
-          uri: lb://scheduler        # 匹配后提供服务的路由地址,lb 代表负载均衡
-          predicates:
-            - Path=/login          # 断言,路径相匹配的进行路由,其他条件见官网。
+        server-addr: 10.15.12.70:8848
+        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
+      config:
+        server-addr: 10.15.12.70:8848
+        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
+        file-extension: yaml

+ 15 - 3
simulation-oauth-client/src/main/java/com/css/simulation/oauth/client/controller/SingleSignOnController.java → simulation-oauth-client/src/main/java/com/css/simulation/oauth/client/controller/SignController.java

@@ -20,8 +20,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import javax.annotation.Resource;
 
 @Controller
-@RequestMapping("/sso")
-public class SingleSignOnController {
+@RequestMapping("/sign")
+public class SignController {
 
     @Resource
     private UserMapper userMapper;
@@ -33,7 +33,19 @@ public class SingleSignOnController {
     private OauthParameter oauthParameter;
 
     /**
-     * http://localhost:7001/simulation/sso/entry?ticket=1001
+     * http://localhost:6001/simulation/oauth/client/sign/hello
+     * http://localhost:7001/simulation/oauth/client/sign/hello
+     */
+    @RequestMapping("/hello")
+    @ResponseBody
+    public String hello() {
+        return "hello gateway!";
+    }
+
+
+    /**
+     * http://localhost:6001/simulation/oauth/client/entry?ticket=1001
+     * http://localhost:7001/simulation/oauth/client/entry?ticket=1001
      */
     @RequestMapping("/entry")
     public String entry(@RequestParam("ticket") String ticket) {

+ 0 - 15
simulation-oauth-client/src/main/java/com/css/simulation/oauth/client/controller/SignInController.java

@@ -1,15 +0,0 @@
-package com.css.simulation.oauth.client.controller;
-
-import api.common.pojo.common.ResponseBodyVO;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-public class SignInController {
-
-
-    @RequestMapping("/signIn")
-    public ResponseBodyVO<String> signIn(){
-        return null;
-    }
-}

+ 0 - 138
simulation-oauth-client/src/main/java/com/css/simulation/oauth/client/controller/TestSingleSignOnController.java

@@ -1,138 +0,0 @@
-package com.css.simulation.oauth.client.controller;
-
-import api.common.pojo.common.ResponseBodyVO;
-import api.common.pojo.common.SimulationTokenVO;
-import api.common.pojo.po.UserPO;
-import api.common.util.EncryptUtil;
-import api.common.util.HttpUtil;
-import api.common.util.JsonUtil;
-import com.css.simulation.oauth.client.configuration.oauth.OauthParameter;
-import com.css.simulation.oauth.client.mapper.UserMapper;
-import lombok.SneakyThrows;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.springframework.boot.configurationprocessor.json.JSONObject;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import javax.annotation.Resource;
-
-@Controller
-@RequestMapping("/test")
-public class TestSingleSignOnController {
-
-    @Resource
-    private UserMapper userMapper;
-    @Resource
-    private CloseableHttpClient closeableHttpClient;
-    @Resource
-    private RequestConfig requestConfig;
-    @Resource
-    private OauthParameter oauthParameter;
-
-    /**
-     * http://localhost:7001/simulation/test/entry?ticket=1001
-     */
-    @RequestMapping("/entry")
-    public String entry(@RequestParam("ticket") String ticket) {
-        System.out.println(oauthParameter);
-        String zoogooyAuthorizeUrl = oauthParameter.getZoogooyAuthorizeUri() +
-                "?appid=" + oauthParameter.getZoogooyAppid() +
-                "&redirect_uri=" + oauthParameter.getZoogooyRedirectUri() +
-                "&ticket=" + ticket +
-                "&response_type=code" +
-                "&scope=snsapi_userinfo";
-        return "redirect:" +zoogooyAuthorizeUrl;
-    }
-
-    /**
-     * 登录接口首页,将 code 返回给前端
-     *
-     * @return token 信息
-     */
-    @RequestMapping("/home")
-    @SneakyThrows
-    @ResponseBody
-    public ResponseBodyVO<SimulationTokenVO> home(@RequestParam("code") String code, @RequestParam("ticket") String ticket) {
-        //1 根据统一凭条 code 获取统一平台 access_token
-        /*
-        响应体
-        {
-          "access_token":"{ACCESS_TOKEN}",
-          "expires_in_sec":30,
-          "openid":"{OPENID}",
-          "scope":"{SCOPE}",
-          "appid":"{APPID}"
-        }
-         */
-        JSONObject zoogooyToken = HttpUtil.post(closeableHttpClient, requestConfig,
-                oauthParameter.getZoogooyTokenUri() + "?appid=" + oauthParameter.getZoogooyAppid() +
-                        "&secret=" + oauthParameter.getZoogooyAppSecret() +
-                        "&code=" + code +
-                        "&grant_type=authorization_code",
-                null, null);
-        String accessToken = zoogooyToken.optString("access_token");
-        String openid = zoogooyToken.optString("openid");
-        System.out.println("------- 统一平台令牌信息为:" + zoogooyToken);
-
-        //2 根据统一平台 access_token、openid、ticket 获取统一平台用户信息
-        /*
-        {
-          "openid":"{OPENID}",
-          "nickname": "{NICKNAME}",
-          "photoId":"2016091919310100025281cb87dcbdc74a09be41",
-          "role":["ROLE1" "ROLE2"],
-          "unionid": "{UNIONID}"
-        }
-         */
-        String zoogooyUserUrl = oauthParameter.getZoogooyUserUri() +
-                "?access_token=" + accessToken +
-                "&openid=" + openid +
-                "&ticket=" + ticket;
-        JSONObject userInfo = HttpUtil.post(closeableHttpClient, requestConfig, zoogooyUserUrl, null, null);
-
-        String unionid = userInfo.optString("unionid");
-        String nickname = userInfo.optString("nickname");
-        System.out.println("------- 统一平台用户信息为:" + userInfo);
-
-        //3 使用 union_id 查询数据库,是否已在仿真平台存在该用户
-        String username;
-        String password;
-        UserPO oldUser = userMapper.selectByIdIgnoreDelete(unionid);
-        System.out.println(oldUser);
-        if (oldUser == null) {   //3-1 仿真平台不存在用户,直接创建新的
-            password = EncryptUtil.getLowerMD5(oauthParameter.getSimulationDefaultPassword());
-            UserPO newUser = new UserPO();
-            newUser.setId(unionid);
-            username = openid;  // 将 openid 作为登录名
-            newUser.setUsername(username);
-            newUser.setNickname(nickname);
-            newUser.setPassword(password);
-            userMapper.insert(newUser);
-        } else {
-            if ("1".equals(oldUser.getIsDeleted())) { //3-2 仿真平台存在删除状态用户,改为未删除
-                userMapper.updateIsDeleted(unionid, "0");
-            }
-            //3-3 仿真平台用户存在未删除用户,放行
-            username = oldUser.getUsername();
-            password = oldUser.getPassword();
-        }
-
-
-        //4 根据仿真平台用户名密码颁发仿真平台 token,返回给前端
-        String simulationTokenUrl = oauthParameter.getSimulationTokenUri() +
-                "?grant_type=password" +
-                "&client_id=" + oauthParameter.getSimulationClientId() +
-                "&client_secret=" + oauthParameter.getSimulationClientSecret() +
-                "&username=" + username +
-                "&password=" + password;
-        SimulationTokenVO simulationToken = JsonUtil.jsonObjectToBean(HttpUtil.post(closeableHttpClient, requestConfig, simulationTokenUrl, null, null), SimulationTokenVO.class);
-        System.out.println("------- 仿真平台令牌信息为:"+simulationToken);
-
-
-        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, "请求成功!", simulationToken);
-    }
-
-}

+ 12 - 8
simulation-oauth-client/src/main/resources/bootstrap.yaml

@@ -1,17 +1,21 @@
+server:
+  port: 7001
+  servlet:
+    context-path: /simulation/oauth/client
+
 spring:
   application:
     name: simulation-oauth-client
   #* -------------------------------- 环境配置 --------------------------------
   profiles:
-    active: windowstest
+    active: dev
   #* -------------------------------- 微服务配置 --------------------------------
   cloud:
     nacos:
       discovery:
-        server-addr: 10.15.12.70:8848                     # 将配置中心注册进注册中心
-      config:                                           # ${prefix}- ${spring.profiles.active}.${file-extension}
-        server-addr: 10.15.12.70:8848                     # 从注册中心的微服务列表读取配置
-        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d # 配置命名空间 id,命名空间一般为项目名
-        file-extension: yaml                            # 读取 yaml 类型的文件
-
-
+        server-addr: 10.15.12.70:8848
+        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
+      config:
+        server-addr: 10.15.12.70:8848
+        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
+        file-extension: yaml

+ 7 - 1
simulation-oauth-server/src/main/java/com/css/simulation/oauth/server/cofiguration/oauth/OauthAuthorizationServerConfiguration.java

@@ -79,7 +79,13 @@ public class OauthAuthorizationServerConfiguration extends AuthorizationServerCo
                 .tokenStore(tokenStore)   // 令牌存储
                 .tokenServices(authorizationServerTokenServices)    // 令牌管理服务
                 .exceptionTranslator(defaultWebResponseExceptionTranslator)
-                .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST);
+                .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST)
+                .pathMapping("/oauth/authorize", "/authorize")   // 自定义端点路径
+                .pathMapping("/oauth/token", "/token")
+                .pathMapping("/oauth/confirm_access", "/confirm_access")
+                .pathMapping("/oauth/error", "/error")
+                .pathMapping("/oauth/check_token", "/check_token")
+                .pathMapping("/oauth/token_key", "/token_key");
     }
 
     /**

+ 12 - 6
simulation-oauth-server/src/main/resources/bootstrap.yaml

@@ -1,15 +1,21 @@
+server:
+  port: 7002
+  servlet:
+    context-path: /simulation/oauth/server
+
 spring:
   application:
     name: simulation-oauth-server
   #* -------------------------------- 环境配置 --------------------------------
   profiles:
-    active: windowstest
+    active: dev
   #* -------------------------------- 微服务配置 --------------------------------
   cloud:
     nacos:
       discovery:
-        server-addr: 10.15.12.70:8848                     # 将配置中心注册进注册中心
-      config:                                           # ${prefix}- ${spring.profiles.active}.${file-extension}
-        server-addr: 10.15.12.70:8848                     # 从注册中心的微服务列表读取配置
-        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d # 配置命名空间 id,命名空间一般为项目名
-        file-extension: yaml                            # 读取 yaml 类型的文件
+        server-addr: 10.15.12.70:8848
+        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
+      config:
+        server-addr: 10.15.12.70:8848
+        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
+        file-extension: yaml

+ 8 - 6
simulation-resource-scheduler/src/main/resources/bootstrap.yml

@@ -1,9 +1,11 @@
 server:
   port: 8001
+  servlet:
+    context-path: /simulation/resource/scheduler
 
 spring:
   application:
-    name: project-service-a
+    name: simulation-resource-scheduler
   #* -------------------------------- 环境配置 --------------------------------
   profiles:
     active: dev
@@ -11,11 +13,11 @@ spring:
   cloud:
     nacos:
       discovery:
-        server-addr: localhost:8841                     # 将配置中心注册进注册中心
-      config:                                           # ${prefix}- ${spring.profiles.active}.${file-extension}
-        server-addr: localhost:8841                     # 从注册中心的微服务列表读取配置
-        namespace: 40cc3b1a-33b1-488a-98dc-4ae0570992ee # 配置命名空间 id,命名空间一般为项目名
-        file-extension: yaml                            # 读取 yaml 类型的文件
+        server-addr: localhost:8841
+      config:
+        server-addr: localhost:8841
+        namespace: 3698bfc2-a612-487a-b2a2-aaad16cd9d9d
+        file-extension: yaml
   #* -------------------------------- 数据源配置 --------------------------------
   datasource:   # server-3_182.92.242.20_root_BMsATnte8uxs6Fr9
     type: com.alibaba.druid.pool.DruidDataSource