2015-12-05 43 views
0

我正在使用基於servlet的web應用(沒有spring mvc)的基於spring安全java的配置。問題是如何設置一個自定義登錄頁面,因爲春天會生成自己的登錄頁面?春季安全自定義登錄頁面和基於java的配置

這兩個類完成所有需要的工作,沒有任何xml配置。那麼我怎樣才能用這個設置來定義自定義登錄jsp呢?

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    public void configure(AuthenticationManagerBuilder auth) throws Exception { 
     Context ctx = new InitialContext(); 
     DataSource ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/MyLocalDB"); 

     final String findUserQuery = "select username,password,enabled " 
      + "from Employees " + "where username = ?"; 
     final String findRoles = "select username,role " + "from Roles " 
      + "where username = ?"; 
      auth.jdbcAuthentication().dataSource(ds).usersByUsernameQuery(findUserQuery) 
      .authoritiesByUsernameQuery(findRoles); 
    } 

    @Override 
    public void configure(WebSecurity web) throws Exception { 
     web.ignoring().antMatchers("/*.html"); 
    } 

} 

public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer { 

    public SecurityWebApplicationInitializer() { 
     super(SecurityConfig.class); 
    } 
} 

回答

1

Spring Security Reference

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