Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kou | zhao
micro-service-skeleton
提交
c8d0db66
M
micro-service-skeleton
项目概览
kou | zhao
/
micro-service-skeleton
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
micro-service-skeleton
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c8d0db66
编写于
12月 29, 2017
作者:
M
ManongJu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SSO
上级
4227b85a
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
189 addition
and
4 deletion
+189
-4
auth-center/src/main/java/com/microservice/skeleton/auth/AuthCenterApplication.java
...com/microservice/skeleton/auth/AuthCenterApplication.java
+2
-2
auth-center/src/main/java/com/microservice/skeleton/auth/config/ResourceServerConfig.java
...croservice/skeleton/auth/config/ResourceServerConfig.java
+29
-0
auth-center/src/main/java/com/microservice/skeleton/auth/controller/UserController.java
...microservice/skeleton/auth/controller/UserController.java
+20
-0
gateway/pom.xml
gateway/pom.xml
+9
-0
gateway/src/main/java/com/microservice/skeleton/gateway/config/SecurityConfig.java
.../microservice/skeleton/gateway/config/SecurityConfig.java
+21
-0
gateway/src/main/resources/application.yml
gateway/src/main/resources/application.yml
+23
-1
resource/pom.xml
resource/pom.xml
+4
-1
resource/src/main/java/com/microservice/skeleton/resource/ResourceApplication.java
...m/microservice/skeleton/resource/ResourceApplication.java
+2
-0
resource/src/main/java/com/microservice/skeleton/resource/config/ResourceServerConfig.java
...ervice/skeleton/resource/config/ResourceServerConfig.java
+28
-0
resource/src/main/java/com/microservice/skeleton/resource/controller/UserController.java
...oservice/skeleton/resource/controller/UserController.java
+19
-0
resource/src/main/resources/application.properties
resource/src/main/resources/application.properties
+0
-0
resource/src/main/resources/application.yml
resource/src/main/resources/application.yml
+32
-0
未找到文件。
auth-center/src/main/java/com/microservice/skeleton/auth/AuthCenterApplication.java
浏览文件 @
c8d0db66
...
@@ -3,10 +3,10 @@ package com.microservice.skeleton.auth;
...
@@ -3,10 +3,10 @@ package com.microservice.skeleton.auth;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.Enable
Authorization
Server
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.Enable
Resource
Server
;
@SpringBootApplication
@SpringBootApplication
//
@EnableDiscoveryClient
@EnableDiscoveryClient
public
class
AuthCenterApplication
{
public
class
AuthCenterApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
auth-center/src/main/java/com/microservice/skeleton/auth/config/ResourceServerConfig.java
0 → 100644
浏览文件 @
c8d0db66
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
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter
;
/**
* <p>参看:https://github.com/spring-guides/tut-spring-security-and-angular-js/blob/master/oauth2-vanilla/README.adoc</p>
* Created by Mr.Yangxiufeng on 2017/12/29.
* Time:10:46
* ProjectName:Mirco-Service-Skeleton
*/
//@Configuration
//@EnableResourceServer
public
class
ResourceServerConfig
extends
ResourceServerConfigurerAdapter
{
@Override
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
csrf
().
disable
()
.
exceptionHandling
()
.
authenticationEntryPoint
(
new
Http401AuthenticationEntryPoint
(
"Bearer realm=\"webrealm\""
))
.
and
()
.
authorizeRequests
().
anyRequest
().
authenticated
()
.
and
()
.
httpBasic
();
}
}
auth-center/src/main/java/com/microservice/skeleton/auth/controller/UserController.java
0 → 100644
浏览文件 @
c8d0db66
package
com.microservice.skeleton.auth.controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.security.Principal
;
/**
* <p>必须要有,做验证</p>
* Created by Mr.Yangxiufeng on 2017/12/29.
* Time:10:43
* ProjectName:Mirco-Service-Skeleton
*/
@RestController
public
class
UserController
{
@RequestMapping
(
"/user"
)
public
Principal
user
(
Principal
user
)
{
return
user
;
}
}
gateway/pom.xml
浏览文件 @
c8d0db66
...
@@ -34,6 +34,15 @@
...
@@ -34,6 +34,15 @@
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-security
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-oauth2
</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
gateway/src/main/java/com/microservice/skeleton/gateway/config/SecurityConfig.java
0 → 100644
浏览文件 @
c8d0db66
package
com.microservice.skeleton.gateway.config
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
/**
* Created by Mr.Yangxiufeng on 2017/12/29.
* Time:10:08
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
@EnableOAuth2Sso
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
csrf
().
disable
();
}
}
gateway/src/main/resources/application.yml
浏览文件 @
c8d0db66
...
@@ -25,4 +25,26 @@ management:
...
@@ -25,4 +25,26 @@ management:
enabled
:
false
enabled
:
false
###actuator监控点 end####
###actuator监控点 end####
##ZipKin
###如下配置参考##
###https://stackoverflow.com/questions/30327269/spring-oauth-authorization-server-behind-spring-cloud-zuul-proxy##
###https://github.com/spring-guides/tut-spring-security-and-angular-js/blob/master/oauth2-vanilla/README.adoc##
###http://wiselyman.iteye.com/blog/2379419##
#######
zuul
:
routes
:
uaa
:
path
:
/uaa/**
strip-prefix
:
true
sensitiveHeaders
:
serviceId
:
auth2.0-center
security
:
basic
:
enabled
:
false
oauth2
:
client
:
access-token-uri
:
http://10.10.8.2:9030/uaa/oauth/token
##网关的地址
user-authorization-uri
:
http://10.10.8.2:9030/uaa/oauth/token
resource
:
user-info-uri
:
http://10.10.8.2:9030/uaa/user
prefer-token-info
:
false
##############end#####################
\ No newline at end of file
resource/pom.xml
浏览文件 @
c8d0db66
...
@@ -27,7 +27,10 @@
...
@@ -27,7 +27,10 @@
<groupId>
org.springframework.cloud
</groupId>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-security
</artifactId>
<artifactId>
spring-cloud-starter-security
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
...
...
resource/src/main/java/com/microservice/skeleton/resource/ResourceApplication.java
浏览文件 @
c8d0db66
...
@@ -4,9 +4,11 @@ import org.springframework.boot.SpringApplication;
...
@@ -4,9 +4,11 @@ import org.springframework.boot.SpringApplication;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
@SpringBootApplication
@SpringBootApplication
@EnableDiscoveryClient
@EnableDiscoveryClient
@EnableGlobalMethodSecurity
(
prePostEnabled
=
true
)
public
class
ResourceApplication
{
public
class
ResourceApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
resource/src/main/java/com/microservice/skeleton/resource/config/ResourceServerConfig.java
0 → 100644
浏览文件 @
c8d0db66
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
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter
;
/**
* Created by Mr.Yangxiufeng on 2017/12/29.
* Time:9:41
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
@EnableResourceServer
public
class
ResourceServerConfig
extends
ResourceServerConfigurerAdapter
{
@Override
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
csrf
().
disable
()
.
exceptionHandling
()
.
authenticationEntryPoint
(
new
Http401AuthenticationEntryPoint
(
"Bearer realm=\"webrealm\""
))
.
and
()
.
authorizeRequests
().
anyRequest
().
authenticated
()
.
and
()
.
httpBasic
();
}
}
resource/src/main/java/com/microservice/skeleton/resource/controller/UserController.java
0 → 100644
浏览文件 @
c8d0db66
package
com.microservice.skeleton.resource.controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* Created by Mr.Yangxiufeng on 2017/12/29.
* Time:9:23
* ProjectName:Mirco-Service-Skeleton
*/
@RestController
public
class
UserController
{
@GetMapping
(
value
=
"getUser"
)
public
String
getUser
(){
return
"hello"
;
}
}
resource/src/main/resources/application.properties
已删除
100644 → 0
浏览文件 @
4227b85a
resource/src/main/resources/application.yml
0 → 100644
浏览文件 @
c8d0db66
server
:
port
:
9023
spring
:
application
:
name
:
resource
zipkin
:
base-url
:
http://10.10.8.2:9050
eureka
:
instance
:
prefer-ip-address
:
true
#使用IP注册
instance-id
:
${spring.cloud.client.ipAddress}:${server.port}
lease-renewal-interval-in-seconds
:
5
##为了能够快速删除
lease-expiration-duration-in-seconds
:
10
##为了能够快速删除
client
:
service-url
:
defaultZone
:
http://register1:9010/eureka/,http://register2:9011/eureka/
###actuator监控点 start####
endpoints
:
health
:
sensitive
:
false
enabled
:
true
##默认情况下很多端点是不允许访问的,会返回401:Unauthorized
management
:
security
:
enabled
:
false
###actuator监控点 end####
security
:
oauth2
:
resource
:
id
:
resource
user-info-uri
:
http://10.10.8.2:9030/uaa/user
prefer-token-info
:
false
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录