Skip to content

Commit 401393d

Browse files
adamueleftherias
authored andcommitted
Extract pattern type in request matcher DSL
1 parent 60d4d5b commit 401393d

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

config/src/main/kotlin/org/springframework/security/config/web/servlet/AuthorizeRequestsDsl.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() {
3535
private val MVC_PRESENT = ClassUtils.isPresent(
3636
HANDLER_MAPPING_INTROSPECTOR,
3737
AuthorizeRequestsDsl::class.java.classLoader)
38+
private val PATTERN_TYPE = if (MVC_PRESENT) PatternType.MVC else PatternType.ANT
3839

3940
/**
4041
* Adds a request authorization rule.
@@ -64,11 +65,7 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() {
6465
* (i.e. "hasAuthority('ROLE_USER') and hasAuthority('ROLE_SUPER')")
6566
*/
6667
fun authorize(pattern: String, access: String = "authenticated") {
67-
if (MVC_PRESENT) {
68-
authorizationRules.add(PatternAuthorizationRule(pattern, PatternType.MVC, null, access))
69-
} else {
70-
authorizationRules.add(PatternAuthorizationRule(pattern, PatternType.ANT, null, access))
71-
}
68+
authorizationRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, null, access))
7269
}
7370

7471
/**
@@ -89,11 +86,7 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() {
8986
* (i.e. "hasAuthority('ROLE_USER') and hasAuthority('ROLE_SUPER')")
9087
*/
9188
fun authorize(pattern: String, servletPath: String, access: String = "authenticated") {
92-
if (MVC_PRESENT) {
93-
authorizationRules.add(PatternAuthorizationRule(pattern, PatternType.MVC, servletPath, access))
94-
} else {
95-
authorizationRules.add(PatternAuthorizationRule(pattern, PatternType.ANT, servletPath, access))
96-
}
89+
authorizationRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, servletPath, access))
9790
}
9891

9992
/**

config/src/main/kotlin/org/springframework/security/config/web/servlet/RequiresChannelDsl.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() {
4040
private val MVC_PRESENT = ClassUtils.isPresent(
4141
HANDLER_MAPPING_INTROSPECTOR,
4242
RequiresChannelDsl::class.java.classLoader)
43+
private val PATTERN_TYPE = if (MVC_PRESENT) PatternType.MVC else PatternType.ANT
4344

4445
var channelProcessors: List<ChannelProcessor>? = null
4546

@@ -71,11 +72,7 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() {
7172
* (i.e. "REQUIRES_SECURE_CHANNEL")
7273
*/
7374
fun secure(pattern: String, attribute: String = "REQUIRES_SECURE_CHANNEL") {
74-
if (MVC_PRESENT) {
75-
channelSecurityRules.add(PatternAuthorizationRule(pattern, PatternType.MVC, null, attribute))
76-
} else {
77-
channelSecurityRules.add(PatternAuthorizationRule(pattern, PatternType.ANT, null, attribute))
78-
}
75+
channelSecurityRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, null, attribute))
7976
}
8077

8178
/**
@@ -96,11 +93,7 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() {
9693
* (i.e. "REQUIRES_SECURE_CHANNEL")
9794
*/
9895
fun secure(pattern: String, servletPath: String, attribute: String = "REQUIRES_SECURE_CHANNEL") {
99-
if (MVC_PRESENT) {
100-
channelSecurityRules.add(PatternAuthorizationRule(pattern, PatternType.MVC, servletPath, attribute))
101-
} else {
102-
channelSecurityRules.add(PatternAuthorizationRule(pattern, PatternType.ANT, servletPath, attribute))
103-
}
96+
channelSecurityRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, servletPath, attribute))
10497
}
10598

10699
/**

0 commit comments

Comments
 (0)