繁体   English   中英

我可以只允许用户使用某些路由而无需使用 spring 引导登录吗?

[英]Can i allow a user only to certain routes without logging in with spring boot?

晚上好。 我现在想知道如何在我的应用程序中配置 spring 引导,以允许用户只能访问我的 web 站点的索引页面和 swagger 文档的页面。 任何其他路由都应重定向到默认的 spring 启动登录页面:我试过这个配置:

@Override
    protected void configure(HttpSecurity http) throws Exception {
    
       http.authorizeRequests().antMatchers(
                        "/",
                        "/swagger-ui.html"
        ).permitAll();
       http.authorizeRequests().antMatchers("/*").permitAll().anyRequest().authenticated().and().formLogin();
     

    }

和这个:

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests(authz -> authz.antMatchers("/*", "swagger-ui.html").permitAll().anyRequest().authenticated()).formLogin();

    }

但他们都没有为我的目的而工作。 谢谢你的回答

我用这个配置解决了

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/*","swagger-ui.html").permitAll();

http.authorizeRequests().antMatchers("/web/**").authenticated().and()
.formLogin();

}

现在我没有经过身份验证的访问权限,只能访问索引页面和 swagger 页面。 其他任何东西都需要身份验证,这正是我想要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM