以下是我要为Play应用配置安全配置文件的方式 - auth.securityProfiles
中的每个条目都包含Operation => Roles
对:
auth {
securityProfiles {
myOperation1 = "author, auditor"
myOperation2 = "admin"
myOperationN = "auditor, default"
}
}
如何阅读auth.securityProfiles
部分中的所有条目以生成Map
这样的内容?
val securityProfiles = Map(
"myOperation1" -> "author, auditor",
"myOperation2" -> "admin",
"myOperationN" -> "auditor, default"
)
感谢。
答案 0 :(得分:0)
这是我的解决方案......我刚刚修改了这样的配置......
auth {
securityProfiles = [
{
operation = "myOperation1"
roles = ["author", "auditor"]
}
{
operation = "myOperation2"
roles = ["admin"]
}
{
operation = "myOperationN"
roles = ["auditor", "default"]
}
]
}
...然后使用以下代码片段阅读它:
import scala.collection.mutable.Map
var securityProfiles = Map[String, List[String]]().withDefaultValue(List.empty)
configuration.getConfigList("auth.securityProfiles").map { _.toList.map { config =>
config.getString("operation").map { op =>
securityProfiles += (op -> config.getStringList("roles").map(_.toList).getOrElse(List.empty))
}
}}
我希望有所帮助。