Spring security added prefix “ROLE_” to all roles name?

前端 未结 5 1527
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 12:00

I have this code in my Web Security Config:

 @Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests         


        
5条回答
  •  眼角桃花
    2020-12-01 12:52

    As @olyanren sad, you can use hasAuthority() method in Spring 4 instead of hasRole(). I am adding JavaConfig example:

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        .authorizeRequests()
        .antMatchers("/api/**")
        .access("hasAuthority('ADMIN')")
        .and()
        .httpBasic().and().csrf().disable();
    }
    

提交回复
热议问题