-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes gh-13562
- Loading branch information
Showing
17 changed files
with
2,190 additions
and
76 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...ork/security/config/annotation/web/configurers/AbstractRequestMatcherBuilderRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2002-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.config.annotation.web.configurers; | ||
|
||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry; | ||
import org.springframework.security.web.util.matcher.RequestMatcher; | ||
|
||
abstract class AbstractRequestMatcherBuilderRegistry<C> extends AbstractRequestMatcherRegistry<C> { | ||
|
||
private final RequestMatcherBuilder builder; | ||
|
||
AbstractRequestMatcherBuilderRegistry(ApplicationContext context) { | ||
this(context, RequestMatcherBuilders.createDefault(context)); | ||
} | ||
|
||
AbstractRequestMatcherBuilderRegistry(ApplicationContext context, RequestMatcherBuilder builder) { | ||
setApplicationContext(context); | ||
this.builder = builder; | ||
} | ||
|
||
@Override | ||
public final C requestMatchers(String... patterns) { | ||
return requestMatchers(null, patterns); | ||
} | ||
|
||
@Override | ||
public final C requestMatchers(HttpMethod method, String... patterns) { | ||
return requestMatchers(this.builder.matchers(method, patterns).toArray(RequestMatcher[]::new)); | ||
} | ||
|
||
@Override | ||
public final C requestMatchers(HttpMethod method) { | ||
return requestMatchers(method, "/**"); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...ingframework/security/config/annotation/web/configurers/AntPathRequestMatcherBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2002-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.config.annotation.web.configurers; | ||
|
||
import org.springframework.http.HttpMethod; | ||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher; | ||
|
||
final class AntPathRequestMatcherBuilder implements RequestMatcherBuilder { | ||
|
||
private final String servletPath; | ||
|
||
private AntPathRequestMatcherBuilder(String servletPath) { | ||
this.servletPath = servletPath; | ||
} | ||
|
||
static AntPathRequestMatcherBuilder absolute() { | ||
return new AntPathRequestMatcherBuilder(null); | ||
} | ||
|
||
static AntPathRequestMatcherBuilder relativeTo(String path) { | ||
return new AntPathRequestMatcherBuilder(path); | ||
} | ||
|
||
@Override | ||
public AntPathRequestMatcher matcher(String pattern) { | ||
return matcher((String) null, pattern); | ||
} | ||
|
||
@Override | ||
public AntPathRequestMatcher matcher(HttpMethod method, String pattern) { | ||
return matcher((method != null) ? method.name() : null, pattern); | ||
} | ||
|
||
private AntPathRequestMatcher matcher(String method, String pattern) { | ||
return new AntPathRequestMatcher(prependServletPath(pattern), method); | ||
} | ||
|
||
private String prependServletPath(String pattern) { | ||
if (this.servletPath == null) { | ||
return pattern; | ||
} | ||
return this.servletPath + pattern; | ||
} | ||
|
||
} |
Oops, something went wrong.