2017-03-05 82 views
0

我使用Spring Initializr,使用嵌入式Tomcat + Thymeleaf模板引擎生成了一個Spring Boot web應用程序,並將其作爲可執行JAR文件打包。使用Thymeleaf + Spring Security integration

技術:

春季啓動1.4.2.RELEASE,春天4.3.4.RELEASE,Thymeleaf 2.1.5.RELEASE,Tomcat的嵌入8.5.6時,Maven 3,Java的8

這是我的安全配置類:

@Configuration 
@PropertySource("classpath:/com/tdk/iot/config/app-${APP-KEY}.properties") 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Value("${securityConfig.formLogin.loginPage}") 
    private String loginPage; 

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

     http 
      .formLogin() 
       .loginPage(loginPage) 
       .defaultSuccessUrl("/books/list") 
       .permitAll() 
       .and() 
      .exceptionHandling() 
       .accessDeniedPage("/denied") 
       .and() 
      .authorizeRequests() 
       .antMatchers("/mockup/**").permitAll() 
       .antMatchers("/dinners/**").permitAll() 
       .antMatchers("/welcome/**").authenticated() 
       .and() 
      .logout() 
       .permitAll() 
       .logoutSuccessUrl("/index.html"); 
    } 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
     auth 
      .inMemoryAuthentication() 
       .passwordEncoder(new StandardPasswordEncoder()) 
       .withUser("test1").password("test1").roles("ADMIN").and() 
       .withUser("test2").password("test2").roles("USER").and() 
       .withUser("test3").password("test3").roles("SUPERADMIN"); 
    } 




    @Bean 
    public static PropertySourcesPlaceholderConfigurer propertyDefaultConfig() { 
     return new PropertySourcesPlaceholderConfigurer(); 
    } 
} 

,這是我的登錄模板

<!DOCTYPE HTML> 
<html xmlns:th="http://www.thymeleaf.org"> 
<head> 
... 
</head> 
    <div class="wrap"> 
     <div class="login"> 
      <div class="logo"><img src="../../../images_pebloc/login.png" width="224" height="71" /></div> 

       <form th:action="@{/login.html}" method="post"> 
       <p th:if="${loginError}" class="error">Wrong user or password</p> 
        <div class="input_label"><i class="fa fa-user"></i><input type="text" name="user" placeholder="User" /></div> 
        <div class="input_label"><i class="fa fa-key"></i><input type="password" name="pass" placeholder="Password" /></div> 

       </form> 

       <input type="submit" value="LOGIN" /> 
      <div class="forget"> 
       <a href="#">Do you forgot your password?</a><br/> 
       <br/> 
       <span>tdk</span> 
      </div> 

     </div> 
    </div> 

但是當我點擊沒有任何反應,在控制檯沒有HTML錯誤,沒有javascript錯誤,沒有表單錯誤,沒有提交,無論我把表格放在哪裏

回答

1

您的提交按鈕不在form標記內。將它移動到</form>的內部,這會觸發您的操作。