当前位置:网站首页>Chapter 18 request matcher serverwebexchangematcher of oauth2loginauthenticationwebfilter
Chapter 18 request matcher serverwebexchangematcher of oauth2loginauthenticationwebfilter
2022-07-25 03:37:00 【buffeer】
In the last article, we analyzed OAuth2LoginAuthentiationWebFilter The successful matching request path will be intercepted . Which request paths will be blocked 、 How to customize the request path to be intercepted . These two questions will be the theme of today .
initialization ServerWebExchageMatcher
stay ServerHttpSecurity The inner class of a class OAuth2LoginSpec Of configure() In the way ,OAuth2LoginAuthenticationWebFilter Initialize the ServerWebExchangeMather. If we don't specify ServerWebExchangeMather, Create the default ; Otherwise use the specified . The creation process is probably shown in the following source code .
protected void configure(ServerHttpSecurity http) {
// Omit other configuration
AuthenticationWebFilter authenticationFilter = new OAuth2LoginAuthenticationWebFilter(manager, authorizedClientRepository);
authenticationFilter.setRequiresAuthenticationMatcher(this.getAuthenticationMatcher());
}
private ServerWebExchangeMatcher getAuthenticationMatcher() {
// If you do not specify your own configuration , Use the default
if (this.authenticationMatcher == null) {
this.authenticationMatcher = this.createAttemptAuthenticationRequestMatcher();
}
return this.authenticationMatcher;
}
private ServerWebExchangeMatcher createAttemptAuthenticationRequestMatcher() {
return new PathPatternParserServerWebExchangeMatcher("/login/oauth2/code/{registrationId}");
}
From the source , We can observe that the default intercepted request path is :/login/oauth2/code/{registrationId}
PathPatterParserServerWebExchangeMatcher
The function of matching the request path is determined by PathPatterParserServerWebExchangeMatcher To achieve . It will intercept the request path , And extract the parameters of the request path . for example , The request path is /login/oauth2/code/google Parameters will be extracted google, And put in Map in . The core source code is shown below .
public Mono<MatchResult> matches(ServerWebExchange exchange) {
ServerHttpRequest request = exchange.getRequest();
PathContainer path = request.getPath().pathWithinApplication();
// The request method is different from the configuration method , The match is not successful
if (this.method != null && !this.method.equals(request.getMethod())) {
return MatchResult.notMatch().doOnNext((result) -> {
if (logger.isDebugEnabled()) {
logger.debug("Request '" + request.getMethod() + " " + path + "' doesn't match '" + this.method + " " + this.pattern.getPatternString() + "'");
}
});
} else {
boolean match = this.pattern.matches(path);
if (!match) {
return MatchResult.notMatch().doOnNext((result) -> {
if (logger.isDebugEnabled()) {
logger.debug("Request '" + request.getMethod() + " " + path + "' doesn't match '" + this.method + " " + this.pattern.getPatternString() + "'");
}
});
} else {
// Extract request parameters
Map<String, String> pathVariables = this.pattern.matchAndExtract(path).getUriVariables();
Map<String, Object> variables = new HashMap(pathVariables);
if (logger.isDebugEnabled()) {
logger.debug("Checking match of request : '" + path + "'; against '" + this.pattern.getPatternString() + "'");
}
// Return the result of successful matching , And put the extracted parameters into the results .
return MatchResult.match(variables);
}
}
}
Custom interception path
If you don't want to intercept the request, the default path is /login/oauth2/code/{registrationId} Request , We can configure . The configuration is as follows .
@Configuration
@EnableWebFluxSecurity
@Slf4j
public class SecurityConfig {
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
return http
.csrf().disable()
.oauth2Login(oauth2Login -> oauth2Login
.authenticationMatcher(new PathPatternParserServerWebExchangeMatcher(
"/oauth2/code/{registrationId}"))
)
.build();
}
}
边栏推荐
- Task02 | EDA initial experience
- Pytorch deep learning practice lesson 8 importing data
- Openlayers ol ext: Transform object, rotate, stretch, zoom in
- Operations in shell
- Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
- Secondary vocational network security skills competition P100 web penetration test
- Moveit2 - 6. Planning scene monitor
- Why does the legend of superstar (Jay Chou) not constitute pyramid selling? What is the difference between distribution and pyramid selling?
- LeetCode. 302 weekly games___ 03_ 6121. Query the number smaller than k after cutting the number____ sort
- Algorithmic interview questions
猜你喜欢

Common methods of array

What should testers do if they encounter a bug that is difficult to reproduce?

Imeta | ggclusternet microbial network analysis and visualization nanny level tutorial

MySQL select query part 2

How to use two queues to simulate the implementation of a stack

C language_ Structure introduction

VMware installation

From input URL to page presentation

How to use two stacks to simulate the implementation of a queue

Question D: pruning shrubs
随机推荐
What is technical support| Daily anecdotes
应急响应全栈
[brother hero July training] day 19: binary tree
Force deduction problem 238. product of arrays other than itself
Flink1.15 source code reading - Flink annotations
基于SSH婴幼儿产品销售系统
Why does the legend of superstar (Jay Chou) not constitute pyramid selling? What is the difference between distribution and pyramid selling?
Test question f: statistical submatrix
Day 9 (capture traffic and routing strategy)
Wechat applet authorized login (including obtaining basic information and binding mobile number)
How is the virtual DOM different from the actual DOM?
Take a database statement note: when the field is empty, assign the default value to the result
ECMAScript new features
Chrome process architecture
"Introduction to interface testing" punch in to learn day04: how to abstract the procedural test script into a test framework?
Skywalking distributed link tracking, related graphics, DLJD, cat
Handwriting promise
Deep learning method of building a model from zero
Merge sort / quick sort
C. Mark and His Unfinished Essay