Skip to content

Commit 16a7cbe

Browse files
adamueleftherias
authored andcommitted
Use named arguments in Kotlin authorization rule
1 parent 401393d commit 16a7cbe

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ abstract class AbstractRequestMatcherDsl {
3737

3838
protected data class PatternAuthorizationRule(val pattern: String,
3939
val patternType: PatternType,
40-
val servletPath: String?,
40+
val servletPath: String? = null,
4141
override val rule: String) : AuthorizationRule(rule)
4242

4343
protected abstract class AuthorizationRule(open val rule: String)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() {
6565
* (i.e. "hasAuthority('ROLE_USER') and hasAuthority('ROLE_SUPER')")
6666
*/
6767
fun authorize(pattern: String, access: String = "authenticated") {
68-
authorizationRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, null, access))
68+
authorizationRules.add(PatternAuthorizationRule(pattern = pattern,
69+
patternType = PATTERN_TYPE,
70+
rule = access))
6971
}
7072

7173
/**
@@ -86,7 +88,10 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() {
8688
* (i.e. "hasAuthority('ROLE_USER') and hasAuthority('ROLE_SUPER')")
8789
*/
8890
fun authorize(pattern: String, servletPath: String, access: String = "authenticated") {
89-
authorizationRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, servletPath, access))
91+
authorizationRules.add(PatternAuthorizationRule(pattern = pattern,
92+
patternType = PATTERN_TYPE,
93+
servletPath = servletPath,
94+
rule = access))
9095
}
9196

9297
/**

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() {
7272
* (i.e. "REQUIRES_SECURE_CHANNEL")
7373
*/
7474
fun secure(pattern: String, attribute: String = "REQUIRES_SECURE_CHANNEL") {
75-
channelSecurityRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, null, attribute))
75+
channelSecurityRules.add(PatternAuthorizationRule(pattern = pattern,
76+
patternType = PATTERN_TYPE,
77+
rule = attribute))
7678
}
7779

7880
/**
@@ -93,7 +95,10 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() {
9395
* (i.e. "REQUIRES_SECURE_CHANNEL")
9496
*/
9597
fun secure(pattern: String, servletPath: String, attribute: String = "REQUIRES_SECURE_CHANNEL") {
96-
channelSecurityRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, servletPath, attribute))
98+
channelSecurityRules.add(PatternAuthorizationRule(pattern = pattern,
99+
patternType = PATTERN_TYPE,
100+
servletPath = servletPath,
101+
rule = attribute))
97102
}
98103

99104
/**

0 commit comments

Comments
 (0)