Java Configuration and Form Login

    xiaoxiao2021-03-26  37

    protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") 1 .permitAll(); 2 } 1) 指定登录页面 2) 授权所有用户访问登录页面。 formLogin().permitAll() 允许授权所有用户 登录页面: <c:url value="/login" var="loginUrl"/> <form action="${loginUrl}" method="post"> 1 <c:if test="${param.error != null}"> 2 <p> Invalid username and password. </p> </c:if> <c:if test="${param.logout != null}"> 3 <p> You have been logged out. </p> </c:if> <p> <label for="username">Username</label> <input type="text" id="username" name="username"/> 4 </p> <p> <label for="password">Password</label> <input type="password" id="password" name="password"/> 5 </p> <input type="hidden" 6 name="${_csrf.parameterName}" value="${_csrf.token}"/> <button type="submit" class="btn">Log in</button> </form>
    转载请注明原文地址: https://ju.6miu.com/read-650187.html

    最新回复(0)