做一个企业权限管理系统时候,项目中springsecurity登陆一直返回到登录页,后台报错,一直找不到原因,求助各位大佬
报错如下 :
2021-05-17 12:40:31,146 64884 [bio-8888-exec-4] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/login'; against '/login.jsp'
2021-05-17 12:40:31,147 64885 [bio-8888-exec-4] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/login'; against '/failer.jsp'
2021-05-17 12:40:31,147 64885 [bio-8888-exec-4] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/login'; against '/css/**'
2021-05-17 12:40:31,147 64885 [bio-8888-exec-4] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/login'; against '/img/**'
2021-05-17 12:40:31,147 64885 [bio-8888-exec-4] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/login'; against '/plugins/**'
2021-05-17 12:40:31,148 64886 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 1 of 12 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2021-05-17 12:40:31,148 64886 [bio-8888-exec-4] DEBUG ssionSecurityContextRepository - HttpSession returned null object for SPRING_SECURITY_CONTEXT
2021-05-17 12:40:31,148 64886 [bio-8888-exec-4] DEBUG ssionSecurityContextRepository - No SecurityContext was available from the HttpSession: org.apache.catalina.session.StandardSessionFacade@2038005e. A new one will be created.
2021-05-17 12:40:31,151 64889 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 2 of 12 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2021-05-17 12:40:31,151 64889 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 3 of 12 in additional filter chain; firing Filter: 'HeaderWriterFilter'
2021-05-17 12:40:31,152 64890 [bio-8888-exec-4] DEBUG eader.writers.HstsHeaderWriter - Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@633bbabe
2021-05-17 12:40:31,152 64890 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 4 of 12 in additional filter chain; firing Filter: 'LogoutFilter'
2021-05-17 12:40:31,152 64890 [bio-8888-exec-4] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/login'; against '/logout.do'
2021-05-17 12:40:31,152 64890 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 5 of 12 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
2021-05-17 12:40:31,152 64890 [bio-8888-exec-4] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/login'; against '/login.do'
2021-05-17 12:40:31,152 64890 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 6 of 12 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
2021-05-17 12:40:31,152 64890 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 7 of 12 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2021-05-17 12:40:31,152 64890 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 8 of 12 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
2021-05-17 12:40:31,154 64892 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 9 of 12 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
2021-05-17 12:40:31,156 64894 [bio-8888-exec-4] DEBUG .AnonymousAuthenticationFilter - Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@121178d0: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffc7f0c: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 63705F654E454E1D8B5823597188DEFC; Granted Authorities: ROLE_ANONYMOUS'
2021-05-17 12:40:31,156 64894 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 10 of 12 in additional filter chain; firing Filter: 'SessionManagementFilter'
2021-05-17 12:40:31,156 64894 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 11 of 12 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
2021-05-17 12:40:31,156 64894 [bio-8888-exec-4] DEBUG .security.web.FilterChainProxy - /login at position 12 of 12 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
2021-05-17 12:40:31,157 64895 [bio-8888-exec-4] DEBUG cept.FilterSecurityInterceptor - Secure object: FilterInvocation: URL: /login; Attributes: [ROLE_USER, ROLE_ADMIN]
2021-05-17 12:40:31,157 64895 [bio-8888-exec-4] DEBUG cept.FilterSecurityInterceptor - Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@121178d0: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffc7f0c: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 63705F654E454E1D8B5823597188DEFC; Granted Authorities: ROLE_ANONYMOUS
2021-05-17 12:40:31,157 64895 [bio-8888-exec-4] DEBUG y.access.vote.AffirmativeBased - Voter: org.springframework.security.access.vote.RoleVoter@1bf95924, returned: -1
2021-05-17 12:40:31,157 64895 [bio-8888-exec-4] DEBUG y.access.vote.AffirmativeBased - Voter: org.springframework.security.access.vote.AuthenticatedVoter@3e965564, returned: 0
2021-05-17 12:40:31,158 64896 [bio-8888-exec-4] DEBUG ort.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sqlSessionFactory'
2021-05-17 12:40:31,160 64898 [bio-8888-exec-4] DEBUG ess.ExceptionTranslationFilter - Access is denied (user is anonymous); redirecting to authentication entry point
org.springframework.security.access.AccessDeniedException: Access is denied
at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:84)
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:233)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:124)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
2021-05-17 12:40:31,178 64916 [bio-8888-exec-4] DEBUG equest.HttpSessionRequestCache - DefaultSavedRequest added to Session: DefaultSavedRequest[http://localhost:8888/manage-web/login]
2021-05-17 12:40:31,179 64917 [bio-8888-exec-4] DEBUG ess.ExceptionTranslationFilter - Calling Authentication entry point.
2021-05-17 12:40:31,180 64918 [bio-8888-exec-4] DEBUG ty.web.DefaultRedirectStrategy - Redirecting to 'http://localhost:8888/manage-web/login.jsp'
2021-05-17 12:40:31,180 64918 [bio-8888-exec-4] DEBUG ssionSecurityContextRepository - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
2021-05-17 12:40:31,182 64920 [bio-8888-exec-4] DEBUG curityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
2021-05-17 12:40:31,191 64929 [bio-8888-exec-5] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/login.jsp'; against '/login.jsp'
2021-05-17 12:40:31,191 64929 [bio-8888-exec-5] DEBUG .security.web.FilterChainProxy - /login.jsp has an empty filter list
2021-05-17 12:40:31,344 65082 [bio-8888-exec-6] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/plugins/bootstrap/css/bootstrap.min.css.map'; against '/login.jsp'
2021-05-17 12:40:31,344 65082 [bio-8888-exec-6] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/plugins/bootstrap/css/bootstrap.min.css.map'; against '/failer.jsp'
2021-05-17 12:40:31,344 65082 [bio-8888-exec-6] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/plugins/bootstrap/css/bootstrap.min.css.map'; against '/css/**'
2021-05-17 12:40:31,344 65082 [bio-8888-exec-6] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/plugins/bootstrap/css/bootstrap.min.css.map'; against '/img/**'
2021-05-17 12:40:31,344 65082 [bio-8888-exec-6] DEBUG .matcher.AntPathRequestMatcher - Checking match of request : '/plugins/bootstrap/css/bootstrap.min.css.map'; against '/plugins/**'
2021-05-17 12:40:31,344 65082 [bio-8888-exec-6] DEBUG .security.web.FilterChainProxy - /plugins/bootstrap/css/bootstrap.min.css.map has an empty filter list
web.xml已经配置:代码如下
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext.xml,classpath*:spring-security.xml</param-value> </context-param>
<!-- springSecurityFilterChain --> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
springsecurity.xml配置如下
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:security="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"> <security:global-method-security pre-post-annotations="enabled" jsr250-annotations="enabled" secured-annotations="enabled"></security:global-method-security> <!-- 配置不拦截的资源 --> <security:http pattern="/login.jsp" security="none"/> <security:http pattern="/failer.jsp" security="none"/> <security:http pattern="/css/**" security="none"/> <security:http pattern="/img/**" security="none"/> <security:http pattern="/plugins/**" security="none"/> <!-- 配置具体的规则 auto-config="true" 不用自己编写登录的页面,框架提供默认登录页面 use-expressions="false" 是否使用SPEL表达式 --> <security:http auto-config="true" use-expressions="false"> <!--默认配置时它应该是一个以逗号分隔的角色列表,请求的用户只需拥有其中的一个角色就能成功访问对应 的URL--> <!-- 配置具体的拦截的规则 pattern="请求路径的规则" access="访问系统的人,必须有ROLE_USER的角色" --> <security:intercept-url pattern="/**" access="ROLE_USER,ROLE_ADMIN"/> <!-- 定义跳转的具体的页面 --> <security:form-login login-page="/login.jsp" login-processing-url="/login.do" default-target-url="/index.jsp" authentication-failure-url="/failer.jsp" authentication-success-forward-url="/pages/main.jsp" /> <!-- 关闭跨域请求 --> <security:csrf disabled="true"/> <!-- 退出 --> <security:logout invalidate-session="true" logout-url="/logout.do" logout-success-url="/login.jsp" /> </security:http> <!-- 切换成数据库中的用户名和密码 --> <security:authentication-manager> <security:authentication-provider user-service-ref="userService"> <!--配置加密的方式--> <security:password-encoder ref="passwordEncoder"/> </security:authentication-provider> </security:authentication-manager> <!-- 配置加密类 --> <bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/> </beans>
登陆时候debug到userService时也不进断点,应该是就没到这一步,一直没找到错误原因,希望各位大佬帮小弟看一下,万分感谢!!!