首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring安全4自定义登录页面

spring安全4自定义登录页面
EN

Stack Overflow用户
提问于 2015-07-24 08:19:28
回答 1查看 2.7K关注 0票数 2

我想在Security中创建自定义的纯html/js登录页面。我使用Spring 1.2.5. defined定义了一个应用程序和配置:

代码语言:javascript
复制
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

@Configuration
@EnableWebSecurity
@EnableWebMvcSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser("a").password("a").roles("USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
       http
            .csrf().disable() // DISABLED CSRF protection to make it easier !
            .authorizeRequests()
            .antMatchers("/", "/login.html").permit
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login.html")
            .permitAll()
            .and()
            .logout()
            .permitAll()
            .logoutUrl("/logout")
            .logoutSuccessUrl("/");
    }

    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
}

我的登录页面看起来是这样的(从默认页面复制!)

代码语言:javascript
复制
<html><head><title>Login Page</title></head><body onload='document.f.username.focus();'>
<h3>Login with Username and Password</h3><form name='f' action='/login' method='POST'>
<table>
<tr><td>User:</td><td><input type='text' name='username' value=''></td></tr>
<tr><td>Password:</td><td><input type='password' name='password'/></td></tr>
<tr><td colspan='2'><input name="submit" type="submit" value="Login"/></td>    </tr>
</table>
</form></body></html>

但我仍然有: AUTHORIZATION_FAILURE

是否可以创建pute html登录页面(没有jsp、胸腺瘤等)?我的代码做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2015-07-24 09:28:14

您将登录页面配置为/login.html (使用loginPage("/login.html"))。这还将更改您需要将凭据发送到登录的位置。这些文件指出:

如果将"/authenticate“传递给此方法loginPage(String),则将更新默认值,如下所示:

  • /authenticate GET -登录表单
  • /authenticate后处理凭据,如果有效则对用户进行身份验证。
  • /authenticate?error GET -在这里重定向失败的身份验证尝试
  • /authenticate?logout在成功注销后重定向到这里

为了使登录有效,您需要让login.html将凭据发布到/login.html,而不是/login

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

https://stackoverflow.com/questions/31605510

复制
相关文章

相似问题

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