首页 > 解决方案 > 自定义登录JSP页面 Springboot + SpringSecurity

问题描述

我是springboot的新手,我正在尝试实现自定义登录。它不起作用,它总是出现默认的 spring 安全登录。有什么帮助吗?我一直在寻找解决方案,但找不到适合我的项目的任何东西。请问,有什么想法吗?你可以在这里看到这个项目:

在这里下载

@Configuration
@EnableWebSecurity
public class DemoSecurityConfig extends WebSecurityConfigurerAdapter {

    // add a reference to our security data source

    @Autowired
    @Qualifier("securityDataSource")
    private DataSource securityDataSource;


    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        // use jdbc authentication ... oh yeah!!!       
        auth.jdbcAuthentication().dataSource(securityDataSource);

    }

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

        http.authorizeRequests()
            .antMatchers("/employees/showForm*").hasAnyRole("MANAGER", "ADMIN")
            .antMatchers("/employees/save*").hasAnyRole("MANAGER", "ADMIN")
            .antMatchers("/employees/delete").hasRole("ADMIN")
            .antMatchers("/employees/**").hasRole("EMPLOYEE")
            .antMatchers("/resources/**").permitAll()
            .and()
            .formLogin()
                .loginPage("/fancy-login")
                .loginProcessingUrl("/authenticateTheUser")
                .permitAll()
            .and()
            .logout().permitAll()
            .and()
            .exceptionHandling().accessDeniedPage("/access-denied");

    }

}

谢谢!

标签: springspring-bootspring-mvcspring-security

解决方案


首先尝试这样:

 @Override
  protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/fancy-login.html")
            .permitAll();
  }

把你的fancy-login.html 放到resources/static/fancy-login.html。


推荐阅读