Skip to content

Commit

Permalink
fix($starter): correct configuration properties 2
Browse files Browse the repository at this point in the history
Description:
Failed to bind properties under 'maf.configuration' to com.jmsoftware.maf.springcloudstarter.property.MafConfigurationProperties:
Reason: java.lang.IllegalStateException: No setter found for property: ignored-url
  • Loading branch information
johnnymillergh committed Apr 13, 2022
1 parent 2208e18 commit 8820316
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import javax.validation.constraints.NotEmpty
@Configuration
@ConfigurationProperties(prefix = PermissionConfiguration.PREFIX)
class PermissionConfiguration(
val ignoredServiceIds: @NotEmpty Set<String>
@NotEmpty var ignoredServiceIds: Set<String>
) {
companion object {
const val PREFIX = "maf.configuration.permission"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AccessLogFilter(
) {
// Ignore URL
for (ignoredUrl in mafConfigurationProperties.flattenIgnoredUrls()) {
if (antPathMatcher.match(ignoredUrl!!, request.requestURI)) {
if (antPathMatcher.match(ignoredUrl, request.requestURI)) {
filterChain.doFilter(request, response)
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jmsoftware.maf.springcloudstarter.property

import cn.hutool.core.util.ObjectUtil
import com.jmsoftware.maf.common.util.logger
import com.jmsoftware.maf.springcloudstarter.property.MafConfigurationProperties.IgnoredUrl.Constant.Companion.URL_REGEXP
import org.springframework.boot.context.properties.ConfigurationProperties
Expand All @@ -19,6 +18,7 @@ import javax.validation.constraints.Pattern
* @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/13/22 2:07 PM
**/
@Validated
@Suppress("unused")
@ConfigurationProperties(prefix = MafConfigurationProperties.PREFIX)
class MafConfigurationProperties {
companion object {
Expand All @@ -32,7 +32,7 @@ class MafConfigurationProperties {
* **ATTENTION**: The value of role name of superuser must be equal to the value that is persistent in database.
**/
@NotBlank
val superUserRole: String = "admin"
var superUserRole: String = "admin"

/**
* The role name of guest user (guest) who has restrictions to access any system&#39;s resources. Assigning
Expand All @@ -41,60 +41,56 @@ class MafConfigurationProperties {
* **ATTENTION**: The value of role of guest user must be equal to the value that is persistent in database.
**/
@NotBlank
val guestUserRole: String = "guest"
var guestUserRole: String = "guest"

/**
* Ignore URLs, used by web access log filter and web security.
**/
@Valid
val ignoredUrl: IgnoredUrl? = null
lateinit var ignoredUrl: IgnoredUrl

/**
* Web security feature switch. Default is true.
* true - disable web security; false - enable web security.
**/
val webSecurityEnabled: Boolean = true
var webSecurityEnabled: Boolean = true

/**
* Web request log switch. Default is true.
*
* true - disable web request log; false - enable web request log.
**/
val webRequestLogEnabled: Boolean = true
var webRequestLogEnabled: Boolean = true

/**
* Included package for http api scan, could be base package
**/
@NotBlank
val includedPackageForHttpApiScan: String = ""
lateinit var includedPackageForHttpApiScan: String

@PostConstruct
private fun postConstruct() {
log.warn("Initial bean: `${this.javaClass.simpleName}`")
}

/**
* Flatten ignored urls string [ ].
*
* @return the string [ ]
**/
fun flattenIgnoredUrls(): Array<String?> {
if (ObjectUtil.isNull(ignoredUrl)) {
return arrayOfNulls(0)
}
val flattenIgnoredUrls = mutableListOf<String>()
ignoredUrl?.let {
flattenIgnoredUrls.addAll(it.get)
flattenIgnoredUrls.addAll(it.post)
flattenIgnoredUrls.addAll(it.delete)
flattenIgnoredUrls.addAll(it.put)
flattenIgnoredUrls.addAll(it.head)
flattenIgnoredUrls.addAll(it.patch)
flattenIgnoredUrls.addAll(it.options)
flattenIgnoredUrls.addAll(it.trace)
flattenIgnoredUrls.addAll(it.pattern)
fun flattenIgnoredUrls(): List<String> {
return mutableListOf<String>().let {
it.addAll(ignoredUrl.get)
it.addAll(ignoredUrl.post)
it.addAll(ignoredUrl.delete)
it.addAll(ignoredUrl.put)
it.addAll(ignoredUrl.head)
it.addAll(ignoredUrl.patch)
it.addAll(ignoredUrl.options)
it.addAll(ignoredUrl.trace)
it.addAll(ignoredUrl.pattern)
it
}
return flattenIgnoredUrls.toTypedArray()
}

@PostConstruct
private fun postConstruct() {
log.warn("Initial bean: `${this.javaClass.simpleName}`")
}

/**
Expand Down

0 comments on commit 8820316

Please sign in to comment.