首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Thymeleaf + Spring安全集成

Thymeleaf + Spring安全集成
EN

Stack Overflow用户
提问于 2017-03-06 02:42:30
回答 1查看 319关注 0票数 0

我已经使用Spring Initializr生成了一个Spring Boot web应用程序,使用嵌入式Tomcat + Thymeleaf模板引擎,并打包为一个可执行的JAR文件。

使用的技术:

Spring Boot 1.4.2.RELEASE,Spring 4.3.4.RELEASE,Thymeleaf 2.1.5.RELEASE,Tomcat Embed 8.5.6,Maven 3,Java 8

这是我的安全配置类:

代码语言:javascript
复制
@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();
    }
}

这是我的登录模板

代码语言:javascript
复制
<!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错误,没有表单错误,没有提交,无论我放在表单中的哪个位置

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-06 03:06:37

提交按钮不在form标记内。将它移动到</form>内部,这应该会触发您的操作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42612416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档