From 70ce26cc90cfec5dbdb56a3f727829007040f626 Mon Sep 17 00:00:00 2001
From: ManongJu <469863752@qq.com>
Date: Mon, 14 May 2018 17:34:08 +0800
Subject: [PATCH] commit
---
.../skeleton/common/vo/RoleVo.java | 22 ++++++++++
mss-gateway/pom.xml | 8 ++--
.../skeleton/gateway/GatewayApplication.java | 2 +
.../gateway/config/SecurityConfig.java | 4 +-
.../gateway/filter/PreRequestFilter.java | 3 ++
.../src/main/resources/application.yml | 42 +++++++++++--------
.../mss-resource}/.gitignore | 0
.../mss-resource}/pom.xml | 6 +--
.../resource/ResourceApplication.java | 0
.../resource/config/ResourceServerConfig.java | 4 --
.../resource/config/Swagger2Config.java | 0
.../resource/controller/UserController.java | 0
.../src/main/resources/application.yml | 31 ++++++++++++++
.../resource/ResourceApplicationTests.java | 0
.../upms/service/impl/UserServiceImpl.java | 31 ++++++++++++++
.../auth/config/ResourceServerConfig.java | 4 --
pom.xml | 7 +++-
17 files changed, 128 insertions(+), 36 deletions(-)
create mode 100644 mss-common/src/main/java/com/microservice/skeleton/common/vo/RoleVo.java
rename {mss-resource => mss-modules/mss-resource}/.gitignore (100%)
rename {mss-resource => mss-modules/mss-resource}/pom.xml (92%)
rename {mss-resource => mss-modules/mss-resource}/src/main/java/com/microservice/skeleton/resource/ResourceApplication.java (100%)
rename {mss-resource => mss-modules/mss-resource}/src/main/java/com/microservice/skeleton/resource/config/ResourceServerConfig.java (78%)
rename {mss-resource => mss-modules/mss-resource}/src/main/java/com/microservice/skeleton/resource/config/Swagger2Config.java (100%)
rename {mss-resource => mss-modules/mss-resource}/src/main/java/com/microservice/skeleton/resource/controller/UserController.java (100%)
create mode 100644 mss-modules/mss-resource/src/main/resources/application.yml
rename {mss-resource => mss-modules/mss-resource}/src/test/java/com/microservice/skeleton/resource/ResourceApplicationTests.java (100%)
create mode 100644 mss-modules/mss-upms/src/main/java/com/microservice/skeleton/upms/service/impl/UserServiceImpl.java
diff --git a/mss-common/src/main/java/com/microservice/skeleton/common/vo/RoleVo.java b/mss-common/src/main/java/com/microservice/skeleton/common/vo/RoleVo.java
new file mode 100644
index 0000000..8de6f2d
--- /dev/null
+++ b/mss-common/src/main/java/com/microservice/skeleton/common/vo/RoleVo.java
@@ -0,0 +1,22 @@
+package com.microservice.skeleton.common.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * Created with IntelliJ IDEA.
+ * Description:
+ * User: Mr.Yangxiufeng
+ * Date: 2018-05-10
+ * Time: 21:03
+ */
+@Data
+public class RoleVo implements Serializable {
+ private static final long serialVersionUID = 2179037393108205286L;
+ private Integer roleId;
+
+ private String name;
+
+ private String value;
+}
diff --git a/mss-gateway/pom.xml b/mss-gateway/pom.xml
index f82811c..3154dc7 100644
--- a/mss-gateway/pom.xml
+++ b/mss-gateway/pom.xml
@@ -42,10 +42,10 @@
org.springframework.cloud
spring-cloud-starter-feign
-
- org.springframework.boot
- spring-boot-starter-actuator
-
+
+
+
+
io.springfox
springfox-swagger2
diff --git a/mss-gateway/src/main/java/com/microservice/skeleton/gateway/GatewayApplication.java b/mss-gateway/src/main/java/com/microservice/skeleton/gateway/GatewayApplication.java
index a7b9173..71986ac 100644
--- a/mss-gateway/src/main/java/com/microservice/skeleton/gateway/GatewayApplication.java
+++ b/mss-gateway/src/main/java/com/microservice/skeleton/gateway/GatewayApplication.java
@@ -4,10 +4,12 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
+@EnableGlobalMethodSecurity(prePostEnabled = true)
public class GatewayApplication {
public static void main(String[] args) {
diff --git a/mss-gateway/src/main/java/com/microservice/skeleton/gateway/config/SecurityConfig.java b/mss-gateway/src/main/java/com/microservice/skeleton/gateway/config/SecurityConfig.java
index 3e23a9b..4541e79 100644
--- a/mss-gateway/src/main/java/com/microservice/skeleton/gateway/config/SecurityConfig.java
+++ b/mss-gateway/src/main/java/com/microservice/skeleton/gateway/config/SecurityConfig.java
@@ -4,6 +4,7 @@ import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
/**
* Created by Mr.Yangxiufeng on 2017/12/29.
@@ -11,7 +12,8 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
-@EnableOAuth2Sso
+//@EnableOAuth2Sso
+//@EnableResourceServer
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
diff --git a/mss-gateway/src/main/java/com/microservice/skeleton/gateway/filter/PreRequestFilter.java b/mss-gateway/src/main/java/com/microservice/skeleton/gateway/filter/PreRequestFilter.java
index 02b741d..83fc801 100644
--- a/mss-gateway/src/main/java/com/microservice/skeleton/gateway/filter/PreRequestFilter.java
+++ b/mss-gateway/src/main/java/com/microservice/skeleton/gateway/filter/PreRequestFilter.java
@@ -4,6 +4,8 @@ import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
@@ -38,6 +40,7 @@ public class PreRequestFilter extends ZuulFilter {
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
LOG.info("send {} request to {}",request.getMethod(),request.getRequestURL().toString());
return null;
}
diff --git a/mss-gateway/src/main/resources/application.yml b/mss-gateway/src/main/resources/application.yml
index 360a563..753b63f 100644
--- a/mss-gateway/src/main/resources/application.yml
+++ b/mss-gateway/src/main/resources/application.yml
@@ -17,14 +17,14 @@ eureka:
service-url:
defaultZone: http://mss-eureka1:9010/eureka/,http://mss-eureka2:9011/eureka/
###actuator监控点 start####
-endpoints:
- health:
- sensitive: false
- enabled: true
+#endpoints:
+# health:
+# sensitive: false
+# enabled: true
##默认情况下很多端点是不允许访问的,会返回401:Unauthorized
-management:
- security:
- enabled: false
+#management:
+# security:
+# enabled: false
###actuator监控点 end####
###如下Oauth2.0配置参考##
@@ -42,17 +42,23 @@ zuul:
strip-prefix: true
sensitiveHeaders:
serviceId: auth2.0-center
-security:
- basic:
- enabled: false
- oauth2:
- client:
- ##网关的地址
- access-token-uri: http://localhost:9030/uaa/oauth/token
- user-authorization-uri: http://localhost:9030/uaa/oauth/authorize
- resource:
- user-info-uri: http://localhost:9030/uaa/user
- prefer-token-info: false
+#security:
+# basic:
+# enabled: false
+# oauth2:
+# client:
+# ##网关的地址
+# access-token-uri: http://localhost:9030/uaa/oauth/token
+# user-authorization-uri: http://localhost:9030/uaa/oauth/authorize
+# resource:
+# user-info-uri: http://localhost:9060/user
+# prefer-token-info: false
+#security:
+# oauth2:
+# resource:
+# id: resource
+# user-info-uri: http://localhost:9060/user
+# prefer-token-info: false
##############end#####################
####超时配置####
ribbon:
diff --git a/mss-resource/.gitignore b/mss-modules/mss-resource/.gitignore
similarity index 100%
rename from mss-resource/.gitignore
rename to mss-modules/mss-resource/.gitignore
diff --git a/mss-resource/pom.xml b/mss-modules/mss-resource/pom.xml
similarity index 92%
rename from mss-resource/pom.xml
rename to mss-modules/mss-resource/pom.xml
index 5624ab4..48f6726 100644
--- a/mss-resource/pom.xml
+++ b/mss-modules/mss-resource/pom.xml
@@ -3,15 +3,15 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.microservice.skeleton
- Micro-Service-Skeleton-Parent
+ com.microservice.skeleton.modules
+ Micro-Service-Skeleton-modules
0.0.1-SNAPSHOT
Micro-Service-Skeleton-Resource
0.0.1-SNAPSHOT
jar
- resource
+ mss-resource
Demo project for Spring Boot
diff --git a/mss-resource/src/main/java/com/microservice/skeleton/resource/ResourceApplication.java b/mss-modules/mss-resource/src/main/java/com/microservice/skeleton/resource/ResourceApplication.java
similarity index 100%
rename from mss-resource/src/main/java/com/microservice/skeleton/resource/ResourceApplication.java
rename to mss-modules/mss-resource/src/main/java/com/microservice/skeleton/resource/ResourceApplication.java
diff --git a/mss-resource/src/main/java/com/microservice/skeleton/resource/config/ResourceServerConfig.java b/mss-modules/mss-resource/src/main/java/com/microservice/skeleton/resource/config/ResourceServerConfig.java
similarity index 78%
rename from mss-resource/src/main/java/com/microservice/skeleton/resource/config/ResourceServerConfig.java
rename to mss-modules/mss-resource/src/main/java/com/microservice/skeleton/resource/config/ResourceServerConfig.java
index d9061a2..38799dc 100644
--- a/mss-resource/src/main/java/com/microservice/skeleton/resource/config/ResourceServerConfig.java
+++ b/mss-modules/mss-resource/src/main/java/com/microservice/skeleton/resource/config/ResourceServerConfig.java
@@ -1,6 +1,5 @@
package com.microservice.skeleton.resource.config;
-import org.springframework.boot.autoconfigure.security.Http401AuthenticationEntryPoint;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
@@ -18,9 +17,6 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
public void configure(HttpSecurity http) throws Exception {
http.
csrf().disable()
- .exceptionHandling()
- .authenticationEntryPoint(new Http401AuthenticationEntryPoint("Bearer realm=\"webrealm\""))
- .and()
.authorizeRequests()
.mvcMatchers("/v2/api-docs").permitAll()
.anyRequest().authenticated()
diff --git a/mss-resource/src/main/java/com/microservice/skeleton/resource/config/Swagger2Config.java b/mss-modules/mss-resource/src/main/java/com/microservice/skeleton/resource/config/Swagger2Config.java
similarity index 100%
rename from mss-resource/src/main/java/com/microservice/skeleton/resource/config/Swagger2Config.java
rename to mss-modules/mss-resource/src/main/java/com/microservice/skeleton/resource/config/Swagger2Config.java
diff --git a/mss-resource/src/main/java/com/microservice/skeleton/resource/controller/UserController.java b/mss-modules/mss-resource/src/main/java/com/microservice/skeleton/resource/controller/UserController.java
similarity index 100%
rename from mss-resource/src/main/java/com/microservice/skeleton/resource/controller/UserController.java
rename to mss-modules/mss-resource/src/main/java/com/microservice/skeleton/resource/controller/UserController.java
diff --git a/mss-modules/mss-resource/src/main/resources/application.yml b/mss-modules/mss-resource/src/main/resources/application.yml
new file mode 100644
index 0000000..f973ef4
--- /dev/null
+++ b/mss-modules/mss-resource/src/main/resources/application.yml
@@ -0,0 +1,31 @@
+server:
+ port: 9023
+spring:
+ application:
+ name: resource
+ zipkin:
+ base-url: http://localhost:9050
+eureka:
+ instance:
+ prefer-ip-address: true
+ instance-id: ${spring.cloud.client.ipAddress}:${server.port}
+ ##续约更新时间间隔设置5秒,m默认30s
+ lease-renewal-interval-in-seconds: 5
+ ##续约到期时间10秒,默认是90秒
+ lease-expiration-duration-in-seconds: 10
+ client:
+ service-url:
+ defaultZone: http://mss-eureka1:9010/eureka/,http://mss-eureka2:9011/eureka/
+endpoints:
+ health:
+ sensitive: false
+ enabled: true
+management:
+ security:
+ enabled: false
+security:
+ oauth2:
+ resource:
+ id: resource
+ user-info-uri: http://localhost:9030/uaa/user
+ prefer-token-info: false
\ No newline at end of file
diff --git a/mss-resource/src/test/java/com/microservice/skeleton/resource/ResourceApplicationTests.java b/mss-modules/mss-resource/src/test/java/com/microservice/skeleton/resource/ResourceApplicationTests.java
similarity index 100%
rename from mss-resource/src/test/java/com/microservice/skeleton/resource/ResourceApplicationTests.java
rename to mss-modules/mss-resource/src/test/java/com/microservice/skeleton/resource/ResourceApplicationTests.java
diff --git a/mss-modules/mss-upms/src/main/java/com/microservice/skeleton/upms/service/impl/UserServiceImpl.java b/mss-modules/mss-upms/src/main/java/com/microservice/skeleton/upms/service/impl/UserServiceImpl.java
new file mode 100644
index 0000000..505be6c
--- /dev/null
+++ b/mss-modules/mss-upms/src/main/java/com/microservice/skeleton/upms/service/impl/UserServiceImpl.java
@@ -0,0 +1,31 @@
+package com.microservice.skeleton.upms.service.impl;
+
+import com.microservice.skeleton.upms.entity.RcUser;
+import com.microservice.skeleton.upms.mapper.RcUserMapper;
+import com.microservice.skeleton.upms.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import tk.mybatis.mapper.entity.Example;
+import tk.mybatis.mapper.util.Sqls;
+
+/**
+ * Created with IntelliJ IDEA.
+ * Description:
+ * User: Mr.Yangxiufeng
+ * Date: 2018-05-10
+ * Time: 19:57
+ */
+@Service
+public class UserServiceImpl implements UserService {
+
+ @Autowired
+ private RcUserMapper userMapper;
+
+ @Override
+ public RcUser findByUsername(String username) {
+ Example example = Example.builder(RcUser.class)
+ .where(Sqls.custom().andEqualTo("username",username))
+ .build();
+ return userMapper.selectOneByExample(example);
+ }
+}
diff --git a/mss-oauth/src/main/java/com/microservice/skeleton/auth/config/ResourceServerConfig.java b/mss-oauth/src/main/java/com/microservice/skeleton/auth/config/ResourceServerConfig.java
index 08da64b..f5122eb 100644
--- a/mss-oauth/src/main/java/com/microservice/skeleton/auth/config/ResourceServerConfig.java
+++ b/mss-oauth/src/main/java/com/microservice/skeleton/auth/config/ResourceServerConfig.java
@@ -1,6 +1,5 @@
package com.microservice.skeleton.auth.config;
-import org.springframework.boot.autoconfigure.security.Http401AuthenticationEntryPoint;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
@@ -19,9 +18,6 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter{
public void configure(HttpSecurity http) throws Exception {
http.
csrf().disable()
- .exceptionHandling()
- .authenticationEntryPoint(new Http401AuthenticationEntryPoint("Bearer realm=\"webrealm\""))
- .and()
.authorizeRequests().anyRequest().authenticated()
.and()
.httpBasic();
diff --git a/pom.xml b/pom.xml
index 1537389..28a898c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,18 +19,21 @@
1.1.6
2.8.0
1.16.20
+ 2.2.0
+ 2.0.2
org.springframework.boot
spring-boot-starter-parent
- 1.5.9.RELEASE
+ 1.5.12.RELEASE
+ mss-common
mss-eureka
mss-oauth
mss-gateway
mss-monitor
- mss-resource
+ mss-modules
--
GitLab