From 401393d7562c505987a6efcbbb410e7d80d602b8 Mon Sep 17 00:00:00 2001 From: Adam Millerchip Date: Thu, 9 Apr 2020 10:53:00 +0900 Subject: [PATCH] Extract pattern type in request matcher DSL --- .../config/web/servlet/AuthorizeRequestsDsl.kt | 13 +++---------- .../config/web/servlet/RequiresChannelDsl.kt | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/config/src/main/kotlin/org/springframework/security/config/web/servlet/AuthorizeRequestsDsl.kt b/config/src/main/kotlin/org/springframework/security/config/web/servlet/AuthorizeRequestsDsl.kt index 5734c2caf6..53a0a0136c 100644 --- a/config/src/main/kotlin/org/springframework/security/config/web/servlet/AuthorizeRequestsDsl.kt +++ b/config/src/main/kotlin/org/springframework/security/config/web/servlet/AuthorizeRequestsDsl.kt @@ -35,6 +35,7 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() { private val MVC_PRESENT = ClassUtils.isPresent( HANDLER_MAPPING_INTROSPECTOR, AuthorizeRequestsDsl::class.java.classLoader) + private val PATTERN_TYPE = if (MVC_PRESENT) PatternType.MVC else PatternType.ANT /** * Adds a request authorization rule. @@ -64,11 +65,7 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() { * (i.e. "hasAuthority('ROLE_USER') and hasAuthority('ROLE_SUPER')") */ fun authorize(pattern: String, access: String = "authenticated") { - if (MVC_PRESENT) { - authorizationRules.add(PatternAuthorizationRule(pattern, PatternType.MVC, null, access)) - } else { - authorizationRules.add(PatternAuthorizationRule(pattern, PatternType.ANT, null, access)) - } + authorizationRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, null, access)) } /** @@ -89,11 +86,7 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() { * (i.e. "hasAuthority('ROLE_USER') and hasAuthority('ROLE_SUPER')") */ fun authorize(pattern: String, servletPath: String, access: String = "authenticated") { - if (MVC_PRESENT) { - authorizationRules.add(PatternAuthorizationRule(pattern, PatternType.MVC, servletPath, access)) - } else { - authorizationRules.add(PatternAuthorizationRule(pattern, PatternType.ANT, servletPath, access)) - } + authorizationRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, servletPath, access)) } /** diff --git a/config/src/main/kotlin/org/springframework/security/config/web/servlet/RequiresChannelDsl.kt b/config/src/main/kotlin/org/springframework/security/config/web/servlet/RequiresChannelDsl.kt index 2febca5e67..e9fae414d0 100644 --- a/config/src/main/kotlin/org/springframework/security/config/web/servlet/RequiresChannelDsl.kt +++ b/config/src/main/kotlin/org/springframework/security/config/web/servlet/RequiresChannelDsl.kt @@ -40,6 +40,7 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() { private val MVC_PRESENT = ClassUtils.isPresent( HANDLER_MAPPING_INTROSPECTOR, RequiresChannelDsl::class.java.classLoader) + private val PATTERN_TYPE = if (MVC_PRESENT) PatternType.MVC else PatternType.ANT var channelProcessors: List? = null @@ -71,11 +72,7 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() { * (i.e. "REQUIRES_SECURE_CHANNEL") */ fun secure(pattern: String, attribute: String = "REQUIRES_SECURE_CHANNEL") { - if (MVC_PRESENT) { - channelSecurityRules.add(PatternAuthorizationRule(pattern, PatternType.MVC, null, attribute)) - } else { - channelSecurityRules.add(PatternAuthorizationRule(pattern, PatternType.ANT, null, attribute)) - } + channelSecurityRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, null, attribute)) } /** @@ -96,11 +93,7 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() { * (i.e. "REQUIRES_SECURE_CHANNEL") */ fun secure(pattern: String, servletPath: String, attribute: String = "REQUIRES_SECURE_CHANNEL") { - if (MVC_PRESENT) { - channelSecurityRules.add(PatternAuthorizationRule(pattern, PatternType.MVC, servletPath, attribute)) - } else { - channelSecurityRules.add(PatternAuthorizationRule(pattern, PatternType.ANT, servletPath, attribute)) - } + channelSecurityRules.add(PatternAuthorizationRule(pattern, PATTERN_TYPE, servletPath, attribute)) } /**