春天4安静

时间:2016-03-31 04:10:14

标签: spring spring-security

我刚刚尝试过Spring 4安全性。我使用以下方法映射安全端点:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .csrf().disable()
        .authorizeRequests()
            .antMatchers(HttpMethod.GET, "/hello/*").hasRole("ADMIN")
            .antMatchers(HttpMethod.GET, "/hello/**").hasRole("ADMIN")
        .and()
        .httpBasic()
        .and()
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}

我突然意识到,如果我有很多端点,那么.antMatchers结构会变得很麻烦。

只是想知道是否有一种可能更“易于管理”的替代方法 - 我想这有点主观?

1 个答案:

答案 0 :(得分:1)

我建议有一种方法来添加蚂蚁匹配器。可以是角色映射路径的Map,并将地图输入该方法以添加匹配器。