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

Update resource server and readme

上级 3af759d1
...@@ -4,7 +4,7 @@ It's a demo project for spring-auth-server. ...@@ -4,7 +4,7 @@ It's a demo project for spring-auth-server.
This project consist of following three sub-projects. This project consist of following three sub-projects.
## spring-auth-server-demo ## auth-server-demo
Auth. server, including identity management. Auth. server, including identity management.
...@@ -39,8 +39,19 @@ Dependencies: ...@@ -39,8 +39,19 @@ Dependencies:
- SQL Server 2019; - SQL Server 2019;
- Spring Auth Server; - 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. Resource server.
...@@ -57,6 +68,7 @@ Dependencies: ...@@ -57,6 +68,7 @@ Dependencies:
- SQL Server 2019; - SQL Server 2019;
- Resource Server; - Resource Server;
## angular-client-demo ## angular-client-demo
An angular client which consume that resources. An angular client which consume that resources.
......
...@@ -35,10 +35,16 @@ ...@@ -35,10 +35,16 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>com.microsoft.sqlserver</groupId>
<artifactId>postgresql</artifactId> <artifactId>mssql-jdbc</artifactId>
<version>11.2.1.jre17</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId> <artifactId>spring-security-test</artifactId>
......
package com.poc.alvachien.resourceserverdemo.config; package com.poc.alvachien.resourceserverdemo.config;
import org.springframework.context.annotation.Bean; 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.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
@EnableWebSecurity @EnableWebSecurity
@Configuration(proxyBeanMethods = false)
public class ResourceServerConfig { public class ResourceServerConfig {
@Bean @Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http http
.authorizeRequests() .securityMatcher("/api/protected/**")
.requestMatchers("/api/protected/**").authenticated() .authorizeHttpRequests()
.requestMatchers("/").permitAll(); .requestMatchers("/api/protected/**").hasAuthority("SCOPE_message.read")
.and()
.oauth2ResourceServer()
.jwt();
return http.build(); return http.build();
} }
} }
...@@ -3,7 +3,6 @@ package com.poc.alvachien.resourceserverdemo.controller; ...@@ -3,7 +3,6 @@ package com.poc.alvachien.resourceserverdemo.controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
@RestController @RestController
......
...@@ -3,14 +3,12 @@ package com.poc.alvachien.resourceserverdemo.controller; ...@@ -3,14 +3,12 @@ package com.poc.alvachien.resourceserverdemo.controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
@RestController @RestController
@RequestMapping("/api/NonProtected") @RequestMapping("/api/Public")
public class NonProtectedController { public class PublicController {
@GetMapping("/sayhi") @GetMapping("/sayhi")
public String 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.
先完成此消息的编辑!
想要评论请 注册