首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring安全第一次登录失败,第二次登录成功

spring安全第一次登录失败,第二次登录成功
EN

Stack Overflow用户
提问于 2016-12-14 13:37:48
回答 5查看 3.4K关注 0票数 2

我有个问题,当我第一次登录的时候

{“时间戳”:1481719982036,“状态”:999,“错误”:“无”,“消息”:“无消息可用”},但如果清除缓存,则为ok.And。这是主要代码:

代码语言:javascript
复制
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private DataSource dataSource;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.jdbcAuthentication().dataSource(dataSource)
                .usersByUsernameQuery("select username,password,TRUE from authority where username = ?")
                .authoritiesByUsernameQuery("select username,role from authority where username = ?")
                .passwordEncoder(passwordEncoder());

    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/login/**").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage("/login").permitAll()
                .loginProcessingUrl("/login/check").permitAll()
                .defaultSuccessUrl("/index").failureUrl("/login?failed=true")
                .permitAll()
                .and()
                .logout().logoutSuccessUrl("/login").logoutUrl("/login?logout")
                .and().csrf().disable();
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/static/**", "/js/**", "/css/**", "/img/**", "/json/**");
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

}

我也不知道发生了什么。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2016-12-14 16:11:14

检查是否有下列所有文件夹

代码语言:javascript
复制
"/static/**", "/js/**", "/css/**", "/img/**", "/json/**"

例外

代码语言:javascript
复制
{"timestamp":1481719982036,"status":999,"error":"None","message":"No message available"}

当文件夹不存在但排除在外时引发。

票数 5
EN

Stack Overflow用户

发布于 2018-10-11 07:15:13

也有同样的问题。将此添加到application.properties解决了这个问题

代码语言:javascript
复制
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
票数 1
EN

Stack Overflow用户

发布于 2019-07-24 12:13:04

一个类似的场景“第一次登录失败,第二次登录成功,但是有一个例外”的春天安全发生在我身上。不知道是不是和你的案子一样。在我的例子中,我发现原则对象是空的。我的案子也用Zuul

我发现在我的自定义失败登录处理程序。我重定向到我的本地主机。

.failureHandler(customAuthenticationFailureHandler())

我已经改变了

response.sendRedirect("localhost"+“/登录/失败/”);

response.sendRedirect("Zuul-localhost"+ "/login/fail/“);

我的问题解决了。

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

https://stackoverflow.com/questions/41144028

复制
相关文章

相似问题

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