diff --git a/doc/pigx.sql b/doc/pigx.sql
index 7f700d263..eeb09a4e5 100644
--- a/doc/pigx.sql
+++ b/doc/pigx.sql
@@ -11,7 +11,7 @@
Target Server Version : 50722
File Encoding : utf-8
- Date: 08/02/2018 22:07:34 PM
+ Date: 08/02/2018 22:34:32 PM
*/
SET NAMES utf8;
@@ -163,7 +163,7 @@ CREATE TABLE `sys_oauth_client_details` (
-- Records of `sys_oauth_client_details`
-- ----------------------------
BEGIN;
-INSERT INTO `sys_oauth_client_details` VALUES ('app', null, 'app', 'server', 'password,refresh_token', null, null, null, null, null, 'true'), ('pig', null, 'pig', 'server', 'password,refresh_token', null, null, null, null, null, 'true'), ('test', null, 'test', 'server', 'password,refresh_token', null, null, null, null, null, 'true');
+INSERT INTO `sys_oauth_client_details` VALUES ('app', null, 'app', 'server', 'password,refresh_token', null, null, null, null, null, 'true'), ('gen', null, 'gen', 'server', 'password,refresh_token', null, null, null, null, null, 'true'), ('pig', null, 'pig', 'server', 'password,refresh_token', null, null, null, null, null, 'true'), ('test', null, 'test', 'server', 'password,refresh_token', null, null, null, null, null, 'true');
COMMIT;
-- ----------------------------
diff --git a/pigx-config/src/main/resources/config/application-dev.yml b/pigx-config/src/main/resources/config/application-dev.yml
index 917bd37dd..d5a55b55e 100644
--- a/pigx-config/src/main/resources/config/application-dev.yml
+++ b/pigx-config/src/main/resources/config/application-dev.yml
@@ -88,4 +88,10 @@ swagger:
- scope: 'server'
description: 'server all'
token-url-list:
- - 'http://localhost:9999/auth/oauth/token'
+ - ${security.oauth2.resource.token-info-uri}
+
+## spring security 配置
+security:
+ oauth2:
+ resource:
+ token-info-uri: http://localhost:9999/auth/oauth/check_token
diff --git a/pigx-config/src/main/resources/config/pigx-codegen-dev.yml b/pigx-config/src/main/resources/config/pigx-codegen-dev.yml
index 19b0b8403..36e4845bb 100644
--- a/pigx-config/src/main/resources/config/pigx-codegen-dev.yml
+++ b/pigx-config/src/main/resources/config/pigx-codegen-dev.yml
@@ -1,3 +1,11 @@
+## spring security 配置
+security:
+ oauth2:
+ client:
+ client-id: gen
+ client-secret: gen
+ scope: server
+
# 数据源配置
spring:
datasource:
diff --git a/pigx-config/src/main/resources/config/pigx-upms-dev.yml b/pigx-config/src/main/resources/config/pigx-upms-dev.yml
index 98a424564..8cb56ab5d 100644
--- a/pigx-config/src/main/resources/config/pigx-upms-dev.yml
+++ b/pigx-config/src/main/resources/config/pigx-upms-dev.yml
@@ -5,8 +5,6 @@ security:
client-id: pig
client-secret: pig
scope: server
- resource:
- token-info-uri: http://localhost:9999/auth/oauth/check_token
# 数据源
spring:
diff --git a/pigx-visual/pigx-codegen/pom.xml b/pigx-visual/pigx-codegen/pom.xml
index 2fae09534..77591ac3a 100755
--- a/pigx-visual/pigx-codegen/pom.xml
+++ b/pigx-visual/pigx-codegen/pom.xml
@@ -45,6 +45,16 @@
pigx-common-core
${pigx.version}
+
+ com.pig4cloud
+ pigx-common-swagger
+ ${pigx.version}
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-security
+
velocity
diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java
index 03c50be7a..6a393292e 100755
--- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java
+++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java
@@ -17,6 +17,7 @@
package com.pig4cloud.pigx.codegen;
+import com.pig4cloud.pigx.common.swagger.annotation.EnablePigxSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
@@ -25,6 +26,7 @@ import org.springframework.cloud.client.SpringCloudApplication;
* @date 2018/07/29
* 代码生成模块
*/
+@EnablePigxSwagger2
@SpringCloudApplication
public class PigxCodeGenApplication {
diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/ResourceServerConfigurer.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/ResourceServerConfigurer.java
new file mode 100644
index 000000000..e1c6cab7d
--- /dev/null
+++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/ResourceServerConfigurer.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2018-2025, lengleng All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the pig4cloud.com developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: lengleng (wangiegie@gmail.com)
+ */
+
+package com.pig4cloud.pigx.codegen.config;
+
+import com.pig4cloud.pigx.common.security.component.PigAccessDeniedHandler;
+import com.pig4cloud.pigx.common.security.component.ResourceAuthExceptionEntryPoint;
+import lombok.AllArgsConstructor;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
+import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
+import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
+
+/**
+ * @author lengleng
+ * @date 2018/6/22
+ */
+@Configuration
+@EnableResourceServer
+@AllArgsConstructor
+@EnableGlobalMethodSecurity(prePostEnabled = true)
+public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
+ private final PigAccessDeniedHandler pigAccessDeniedHandler;
+ private final ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint;
+
+ @Override
+ public void configure(HttpSecurity http) throws Exception {
+ http.authorizeRequests()
+ .antMatchers("/actuator/**", "/v2/api-docs").permitAll()
+ .anyRequest().authenticated()
+ .and().csrf().disable();
+ }
+
+ /**
+ * why add resourceId
+ * https://stackoverflow.com/questions/28703847/how-do-you-set-a-resource-id-for-a-token
+ *
+ * @param resources
+ * @throws Exception
+ */
+ @Override
+ public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
+ resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint)
+ .accessDeniedHandler(pigAccessDeniedHandler);
+ }
+}