提交 5c78b9c2 编写于 作者: alvachien's avatar alvachien

Update resource server and readme

上级 3af759d1
......@@ -4,7 +4,7 @@ It's a demo project for spring-auth-server.
This project consist of following three sub-projects.
## spring-auth-server-demo
## auth-server-demo
Auth. server, including identity management.
......@@ -39,8 +39,19 @@ Dependencies:
- SQL Server 2019;
- Spring Auth Server;
## idp-server-demo
## spring-resource-server-demo
Identity server demo.
Dependencies:
- Java 17;
- Spring Boot 3.0;
- Spring Boot JPA;
- Spring Boot Web;
- SQL Server 2019;
- Spring Auth Server;
## resource-server-demo
Resource server.
......@@ -57,6 +68,7 @@ Dependencies:
- SQL Server 2019;
- Resource Server;
## angular-client-demo
An angular client which consume that resources.
......
......@@ -35,10 +35,16 @@
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>11.2.1.jre17</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
......
package com.poc.alvachien.resourceserverdemo.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
@EnableWebSecurity
@Configuration(proxyBeanMethods = false)
public class ResourceServerConfig {
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.requestMatchers("/api/protected/**").authenticated()
.requestMatchers("/").permitAll();
.securityMatcher("/api/protected/**")
.authorizeHttpRequests()
.requestMatchers("/api/protected/**").hasAuthority("SCOPE_message.read")
.and()
.oauth2ResourceServer()
.jwt();
return http.build();
}
}
......@@ -3,7 +3,6 @@ package com.poc.alvachien.resourceserverdemo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
@RestController
......
......@@ -3,14 +3,12 @@ package com.poc.alvachien.resourceserverdemo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
@RestController
@RequestMapping("/api/NonProtected")
public class NonProtectedController {
@RequestMapping("/api/Public")
public class PublicController {
@GetMapping("/sayhi")
public String sayhi() {
return "Say hi from Non-Protected";
return "Say hi from Public";
}
}
server.port:9500
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:9600
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:sqlserver://localhost;encrypt=true;database=authresource;integratedSecurity=true;trustServerCertificate=true
#spring.datasource.username=springuser
#spring.datasource.password=ThePassword
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql: true
server:
port: 8090
logging:
level:
root: INFO
org.springframework.web: INFO
org.springframework.security: INFO
org.springframework.security.oauth2: INFO
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: http://localhost:9000
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册