Use named arguments in Kotlin authorization rule

This commit is contained in:
Adam Millerchip 2020-04-09 10:57:20 +09:00 committed by Eleftheria Stein-Kousathana
parent 401393d756
commit 16a7cbee4b
3 changed files with 15 additions and 5 deletions

View File

@ -37,7 +37,7 @@ abstract class AbstractRequestMatcherDsl {
protected data class PatternAuthorizationRule(val pattern: String,
val patternType: PatternType,
val servletPath: String?,
val servletPath: String? = null,
override val rule: String) : AuthorizationRule(rule)
protected abstract class AuthorizationRule(open val rule: String)

View File

@ -65,7 +65,9 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() {
* (i.e. "hasAuthority('ROLE_USER') and hasAuthority('ROLE_SUPER')")
*/
fun authorize(pattern: String, access: String = "authenticated") {
authorizationRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, null, access))
authorizationRules.add(PatternAuthorizationRule(pattern = pattern,
patternType = PATTERN_TYPE,
rule = access))
}
/**
@ -86,7 +88,10 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() {
* (i.e. "hasAuthority('ROLE_USER') and hasAuthority('ROLE_SUPER')")
*/
fun authorize(pattern: String, servletPath: String, access: String = "authenticated") {
authorizationRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, servletPath, access))
authorizationRules.add(PatternAuthorizationRule(pattern = pattern,
patternType = PATTERN_TYPE,
servletPath = servletPath,
rule = access))
}
/**

View File

@ -72,7 +72,9 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() {
* (i.e. "REQUIRES_SECURE_CHANNEL")
*/
fun secure(pattern: String, attribute: String = "REQUIRES_SECURE_CHANNEL") {
channelSecurityRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, null, attribute))
channelSecurityRules.add(PatternAuthorizationRule(pattern = pattern,
patternType = PATTERN_TYPE,
rule = attribute))
}
/**
@ -93,7 +95,10 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() {
* (i.e. "REQUIRES_SECURE_CHANNEL")
*/
fun secure(pattern: String, servletPath: String, attribute: String = "REQUIRES_SECURE_CHANNEL") {
channelSecurityRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, servletPath, attribute))
channelSecurityRules.add(PatternAuthorizationRule(pattern = pattern,
patternType = PATTERN_TYPE,
servletPath = servletPath,
rule = attribute))
}
/**