Spring boot security引发错误,状态为999“无消息”

问题描述 投票:2回答:1

我正在Intellij中使用Spring-boot,Spring-security,Hibernate,MySQL,JSP,JSTL,AspectJ编写租车网络应用程序。我使用JDBC身份验证登录用户。问题是:如果我是第一次登录,则会收到状态为999的错误,键入None,并显示消息:Message not available,第二次日志记录正常通过。

我已经阅读到可能是Spring Security在WebSecurity配置中找不到声明的文件夹。我尝试了许多蚂蚁匹配器,最后我只留下了/css/**/js/**,因为在我的页面上都可以正确地读取它们,但是结果是相同的-错误状态999。

是问题的根源吗?谁能指出我做错了吗?

SecurityConfiguration.class

package com.doszke.CarRent.web;

import com.doszke.CarRent.reflect.annotations.AccessLevel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

import javax.sql.DataSource;

@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    private DataSource dataSource;

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @Value("${carrent.queries.users-query}")
    private String usersQuery;

    @Value("${carrent.queries.roles-query}")
    private String rolesQuery;


    @Override
    protected void configure(AuthenticationManagerBuilder auth)
            throws Exception {
        auth.
                jdbcAuthentication()
                .usersByUsernameQuery(usersQuery)
                .authoritiesByUsernameQuery(rolesQuery)
                .dataSource(dataSource)
                .passwordEncoder(bCryptPasswordEncoder);
    }

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

        http
                    .authorizeRequests()
                        .antMatchers("/").permitAll()
                        .antMatchers("/resources/**").permitAll()
                        .antMatchers("/login").permitAll()
                        .antMatchers("/register").permitAll()
                        .antMatchers("/registerSuccess").permitAll()
                        .antMatchers("/home/**").hasAuthority(AccessLevel.USER).anyRequest().authenticated()
                        .antMatchers("/admin/**").hasAuthority(AccessLevel.ADMIN).anyRequest()
                        .authenticated()
                .and()
                    .csrf()
                        .disable()
                .formLogin()
                    .loginPage("/login")
                    .failureUrl("/login?error=true")
                    .defaultSuccessUrl("/home")
                    .usernameParameter("login")
                    .passwordParameter("password")
                .and()
                    .logout()
                        .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                        .logoutSuccessUrl("/")
                .and()
                    .exceptionHandling()
                        .accessDeniedPage("/access-denied");
    }

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


}

我的资源和Web应用程序树:

enter image description here

我正在Intellij中使用Spring-boot,Spring-security,Hibernate,MySQL,JSP,JSTL,AspectJ编写租车网络应用程序。我使用JDBC身份验证登录用户。问题是:如果我登录第一个...

spring-boot spring-security http-error
1个回答
0
投票

我有同样的情况。

© www.soinside.com 2019 - 2024. All rights reserved.