将请求方法与 Kotlin DSL 匹配以获得 Spring 安全性
Match request method with Kotlin DSL for Spring Security
Spring 安全性提供了 Kotlin DSL 以便于配置。这是来自 Spring Blog 的示例:
override fun configure(http: HttpSecurity?) {
http {
httpBasic {}
authorizeRequests {
authorize("/greetings/**", hasAuthority("ROLE_ADMIN"))
authorize("/**", permitAll)
}
}
}
我只想允许 POST 对特定路径的请求。在 Java 中,您可以:
http
.httpBasic().and()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/greetings").hasRole("ADMIN");
有使用 Kotlin DSL 的示例吗?
问的太早了。看来我在查看源代码后找到了解决方案。
添加以备将来参考:
override fun configure(http: HttpSecurity) {
http {
csrf { disable() }
httpBasic {}
authorizeRequests {
authorize(AntPathRequestMatcher("/greetings", HttpMethod.POST.name), hasRole("ADMIN"))
authorize("/**", denyAll)
}
}
}
Spring 安全性提供了 Kotlin DSL 以便于配置。这是来自 Spring Blog 的示例:
override fun configure(http: HttpSecurity?) {
http {
httpBasic {}
authorizeRequests {
authorize("/greetings/**", hasAuthority("ROLE_ADMIN"))
authorize("/**", permitAll)
}
}
}
我只想允许 POST 对特定路径的请求。在 Java 中,您可以:
http
.httpBasic().and()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/greetings").hasRole("ADMIN");
有使用 Kotlin DSL 的示例吗?
问的太早了。看来我在查看源代码后找到了解决方案。
添加以备将来参考:
override fun configure(http: HttpSecurity) {
http {
csrf { disable() }
httpBasic {}
authorizeRequests {
authorize(AntPathRequestMatcher("/greetings", HttpMethod.POST.name), hasRole("ADMIN"))
authorize("/**", denyAll)
}
}
}