[英]How to configure spring-security with annotations (no xml)?
我想在完全配置有Spring注釋的應用程序中使spring-security完整,不存在xml。 在純Java代碼中,以下內容將如何顯示?
<http auto-config="true">
<intercept-url pattern="/*" access="ROLE_ANONYMOUS"/>
</http>
我找不到帶注解的任何有關spring-security的文檔。 到目前為止還不支持嗎? 如果沒有,如何將security.xml集成到基於注釋的配置類中?
@Configuration
public AppConfig {
}
這很容易。 做這樣的事情,重要的只是擴展WebSecurityConfigurerAdapter
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/*").hasRole("ROLE_ANONYMOUS")
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.