首页 文章

使用Spring Security时,无法使用@SpringUI(/ login)重定向到LoginUI

提问于
浏览
0

我有一个项目,我已经将Vaadin与Spring Boot集成在一起 . 我使用的依赖之一是spring-boot-starter-security .

当我调用url http://localhost:8080/appXYZ/时,它会将我重定向到http://localhost:8080/appXYZ/login . 我'm expecting it to go to my LoginUI class with has the annotation @SpringUI( 94781 ). It does not, I' m重定向到其他具有用户名/密码形式的页面 .

pom.xml:https://gist.github.com/anonymous/4cc27b3d9e59f67839bf Application.java(启动Spring Boot应用程序):https://gist.github.com/anonymous/6748b81d26b486dc617c LoginUI(我要去的地方):https://gist.github.com/anonymous/a98f5099d5daa27fb391

2 回答

  • 0

    刚做了一个快速实验,我评论了所有Spring Security的东西 . 当我尝试使用url http://localhost:8080/appXYZ/login时,我确实进入了LoginUI页面 . 只需解决Spring Security的问题 . 但@SpringUI("/login")重定向正在运行 .

  • 0

    您还需要覆盖 MySecurityConfigurer 中的 configure(HttpSecurity http) 方法,并指定Spring的登录页面,以便在用户未经过身份验证并尝试访问例如 /authorized 路径时重定向到该路径,同时允许所有用户访问 /login 和其他相邻资源(/ VAADIN,/ UIDL等) .

    以下代码片段是从我对your other question的回答中提取的,因为它们密切相关:


    我将 ApplicationSecurity.configure(HttpSecurity http) 方法改为 http.csrf().disable().authorizeRequests().anyRequest().permitAll(); 并且我能够进入第二个屏幕 . 现在这可能不是我收集的那么安全,但它应该给你一个起点 .

    注意:您可能已经知道这一点,但如果您不这样做,它可以节省您一些时间,我也很高兴分享这一点,因为我花了一段时间才弄明白 . 根据您设置应用安全性的方式,您可能最终将该方法更改为如下所示 .

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().
                exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")).accessDeniedPage("/accessDenied")
                .and().authorizeRequests()
                .antMatchers("/VAADIN/**", "/PUSH/**", "/UIDL/**","/login", "/login/**", "/error/**", "/accessDenied/**").permitAll()
                .antMatchers("/authorized", "/**").fullyAuthenticated();
    }
    

相关问题