浏览代码

Extract pattern type in request matcher DSL

Adam Millerchip 5 年之前
父节点
当前提交
401393d756

+ 3 - 10
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))
     }
 
     /**

+ 3 - 10
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<ChannelProcessor>? = 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))
     }
 
     /**