Spring Security JSR250设置

我已经开始学习Spring Security,并希望使用方法级别的安全性。

我有简单的控制器

@Controller
public class AppController {

    @GetMapping("/")
    @PermitAll
    public String welcomePage() {
        return "index";
    }

    @GetMapping("/user")
    @RolesAllowed({Role.USER,Role.ADMIN})
    public String userPage() {
        return "user";
    }
}

安全配置:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(jsr250Enabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    protected void configure(HttpSecurity http) throws Exception {      
        http        
        .formLogin().permitAll()
        .and()
        .anonymous()        
        .and()
        .authorizeRequests().anyRequest().authenticated();      
    }

    @Override
    public void configure(AuthenticationmanagerBuilder builder)
            throws Exception {
        builder.inmemoryAuthentication()
               .withUser("user").password("user").roles("USER")
               .and()
               .withUser("admin").password("admin").roles("ADMIN");
    }
}

问题索引页需要使用此配置登录,但我设置了@PermitAll。

您能帮忙吗

wearekill000 回答:Spring Security JSR250设置

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3144039.html

大家都在问