Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
springboot-demo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leona
W
web
backend
springboot-demo
Commits
90d7223f
Commit
90d7223f
authored
Jul 01, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
41f60556
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
5 deletions
+63
-5
auth-server/pom.xml
auth-server/pom.xml
+8
-2
resource-server/pom.xml
resource-server/pom.xml
+8
-3
resource-server/src/main/java/com/duanledexianxianxian/demo/config/OAuth2ServerConfig.java
.../duanledexianxianxian/demo/config/OAuth2ServerConfig.java
+47
-0
No files found.
auth-server/pom.xml
View file @
90d7223f
...
...
@@ -19,8 +19,14 @@
</dependency>
<!-- 不是starter,手动配置 -->
<dependency>
<groupId>
org.springframework.security.oauth
</groupId>
<artifactId>
spring-security-oauth2
</artifactId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-oauth2-resource-server
</artifactId>
<version>
2.1.3.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-oauth2-client
</artifactId>
<version>
2.1.3.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
resource-server/pom.xml
View file @
90d7223f
...
...
@@ -9,7 +9,7 @@
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
demo
</artifactId>
<artifactId>
resource-server
</artifactId>
<dependencies>
<!-- 注意是starter,自动配置 -->
...
...
@@ -18,9 +18,14 @@
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
<!-- 不是starter,手动配置 -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>
org.springframework.security.oauth
</groupId>
<artifactId>
spring-security-oauth2
</artifactId>
<groupId>
org.springframework.security.oauth.boot
</groupId>
<artifactId>
spring-security-oauth2-autoconfigure
</artifactId>
<version>
2.1.3.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
resource-server/src/main/java/com/duanledexianxianxian/demo/config/OAuth2ServerConfig.java
0 → 100644
View file @
90d7223f
package
com.duanledexianxianxian.demo.config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.http.SessionCreationPolicy
;
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 duanledexianxianxian
* @date 2020/6/30 22:28
* @since 1.0.0
*/
@Configuration
public
class
OAuth2ServerConfig
{
private
static
final
String
DEMO_RESOURCE_ID
=
"order"
;
@Configuration
@EnableResourceServer
protected
static
class
ResourceServerConfiguration
extends
ResourceServerConfigurerAdapter
{
@Override
public
void
configure
(
ResourceServerSecurityConfigurer
resources
)
{
resources
.
resourceId
(
DEMO_RESOURCE_ID
).
stateless
(
true
);
}
@Override
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
// @formatter:off
http
// Since we want the protected resources to be accessible in the UI as well we need
// session creation to be allowed (it's disabled by default in 2.0.6)
.
sessionManagement
().
sessionCreationPolicy
(
SessionCreationPolicy
.
IF_REQUIRED
)
.
and
()
.
requestMatchers
().
anyRequest
()
.
and
()
.
anonymous
()
.
and
()
.
authorizeRequests
()
// .antMatchers("/product/**").access("#oauth2.hasScope('select') and hasRole('ROLE_USER')")
.
antMatchers
(
"/order/**"
).
authenticated
();
//配置order访问控制,必须认证过后才可以访问
// @formatter:on
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment