SpringBoot 2.1.5.RELEASE-Thymeleaf-登录页面

时间:2019-05-22 13:14:51

标签: html spring spring-boot spring-security thymeleaf

我有一个基本的SpringBoot 2.1.5.RELEASE应用程序。使用Spring Initializer,JPA,嵌入式Tomcat,Thymeleaf模板引擎并将其打包为可执行JAR文件。

我有一个Thymeleaf模板,可以通过登录正常工作

 <form id="loginForm" th:action="@{/login}" method="post">

            <div class="input_label"><i class="fa fa-user"></i><input type="text" id="usernameId"   name="username" th:attr="placeholder=#{login.user.placeholder}"  /></div>
            <div class="input_label"><i class="fa fa-key"></i><input type="text" name="password" placeholder="Password"  /></div>

            <input type="submit" value="LOGIN" />

</form>

我要替换另一个:

<form id="loginForm" th:action="@{/login}" method="post">
              <div class="form-group">
                <div class="input-group">
                  <div class="input-group-prepend"><i class="icon s7-user"></i></div>
                  <input class="form-control" id="username" name="username" type="text" th:attr="placeholder=#{login.user.placeholder}" autocomplete="off" />                  
                </div>
              </div>
              <div class="form-group">
                <div class="input-group">
                  <div class="input-group-prepend"><i class="icon s7-lock"></i></div>
                  <input class="form-control" id="password" name="password" type="password" placeholder="Password">
                </div>
              </div>
              <div class="form-group login-submit">
                <a class="btn btn-lg btn-primary btn-block" th:href="@{/login}" data-dismiss="modal">Login</a>
              </div>                
              <div class="form-group row login-tools">
                <div class="col-sm-6 login-remember">
                  <label class="custom-control custom-checkbox mt-2">
                    <input class="custom-control-input" type="checkbox"><span class="custom-control-label">Remember me</span>
                  </label>
                </div>
                <div class="col-sm-6 pt-2 text-sm-right login-forgot-password"><a href="pages-forgot-password.html">Forgot Password?</a></div>
              </div>
            </form>

但是,即使似乎可以通过身份验证,也可以在控制台上找到

2019-05-22 15:09  [http-nio-2233-exec-8] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor.authenticateIfRequired(348) - Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@afd2c118: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@ffff4c9c: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: DD587EDE4D70B2AC1D1609FD3553FB31; Granted Authorities: ROLE_ANONYMOUS
2019-05-22 15:09  [http-nio-2233-exec-8] DEBUG o.s.s.access.vote.AffirmativeBased.decide(66) - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@976c509, returned: 1
2019-05-22 15:09  [http-nio-2233-exec-8] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor.beforeInvocation(243) - Authorization successful
2019-05-22 15:09  [http-nio-2233-exec-8] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor.beforeInvocation(256) - RunAsManager did not change Authentication object

应用程序不会重定向到我在配置文件中设置的页面

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


        http
                .authorizeRequests()
                .antMatchers(publicMatchers()).permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage("/login").defaultSuccessUrl("/bonanza/all")
                .failureUrl("/login?error").permitAll()
                .and()
                .logout().permitAll();
    }

1 个答案:

答案 0 :(得分:1)

如评论中所述,您需要可以提交表单的内容。就像您提供的第一个示例中的输入一样。

控制台输出正在欺骗,您已通过“匿名”身份验证。