Spring SecurityConfig无法正常工作

时间:2016-12-07 09:40:13

标签: spring spring-mvc spring-boot spring-security

我已经玩了一段时间,但它似乎没有连接到我的项目。

这是我上次编辑时的文件。我已经允许所有,所以我可以测试,看看这个文件是否正常工作。当我没有包含任何身份验证时,我仍然会收到401错误。

知道我缺少什么吗?

package org.springframework.security.samples.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;

@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().permitAll();
    }
}

修改

启动应用程序时,这是安全性调试日志

2016-12-07 23:24:48.673 DEBUG 15640 --- [           main] eGlobalAuthenticationAutowiredConfigurer : Eagerly initializing {org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration=org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration$$EnhancerBySpringCGLIB$$60c02dff@68fc9167}    
2016-12-07 23:24:48.827 DEBUG 15640 --- [           main] edFilterInvocationSecurityMetadataSource : Adding web access control expression 'hasAnyRole('ROLE_USER')', for org.springframework.security.web.util.matcher.AnyRequestMatcher@1
2016-12-07 23:24:48.834 DEBUG 15640 --- [           main] o.s.s.w.a.i.FilterSecurityInterceptor    : Validated configuration attributes
2016-12-07 23:24:48.835 DEBUG 15640 --- [           main] o.s.s.w.a.i.FilterSecurityInterceptor    : Validated configuration attributes

以下是我进行其余呼叫时的安全调试日志

2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/css/**'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/js/**'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/images/**'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/webjars/**'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/**/favicon.ico'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/error'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/**']
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request '/users' matched by universal pattern '/**'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m matched
[2m2016-12-07 23:29:19.115[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 1 of 11 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
[2m2016-12-07 23:29:19.116[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 2 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
[2m2016-12-07 23:29:19.118[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 3 of 11 in additional filter chain; firing Filter: 'HeaderWriterFilter'
[2m2016-12-07 23:29:19.119[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 4 of 11 in additional filter chain; firing Filter: 'LogoutFilter'
[2m2016-12-07 23:29:19.119[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/logout', GET]
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request 'POST /users' doesn't match 'GET /logout
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/logout', POST]
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/logout'
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/logout', PUT]
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request 'POST /users' doesn't match 'PUT /logout
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/logout', DELETE]
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request 'POST /users' doesn't match 'DELETE /logout
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m No matches found
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 5 of 11 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 6 of 11 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 7 of 11 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
[2m2016-12-07 23:29:19.121[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 8 of 11 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
[2m2016-12-07 23:29:19.123[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.a.AnonymousAuthenticationFilter [0;39m [2m:[0;39m Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@9055e4a6: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS'
[2m2016-12-07 23:29:19.123[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 9 of 11 in additional filter chain; firing Filter: 'SessionManagementFilter'
[2m2016-12-07 23:29:19.123[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 10 of 11 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
[2m2016-12-07 23:29:19.123[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy       [0;39m [2m:[0;39m /users at position 11 of 11 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
[2m2016-12-07 23:29:19.124[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.a.i.FilterSecurityInterceptor   [0;39m [2m:[0;39m Secure object: FilterInvocation: URL: /users; Attributes: [hasAnyRole('ROLE_USER')]
[2m2016-12-07 23:29:19.124[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.a.i.FilterSecurityInterceptor   [0;39m [2m:[0;39m Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@9055e4a6: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS
[2m2016-12-07 23:29:19.128[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.access.vote.AffirmativeBased      [0;39m [2m:[0;39m Voter: org.springframework.security.web.access.expression.WebExpressionVoter@6175291d, returned: -1
[2m2016-12-07 23:29:19.134[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.a.ExceptionTranslationFilter    [0;39m [2m:[0;39m 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) ~[spring-security-core-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:233) ~[spring-security-core-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:124) ~[spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115) ~[spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:121) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_112]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_112]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_112]

[2m2016-12-07 23:29:19.135[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.a.ExceptionTranslationFilter    [0;39m [2m:[0;39m Calling Authentication entry point.
[2m2016-12-07 23:29:19.135[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.header.writers.HstsHeaderWriter [0;39m [2m:[0;39m Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@5e6187fd
[2m2016-12-07 23:29:19.135[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36ms.s.w.c.SecurityContextPersistenceFilter[0;39m [2m:[0;39m SecurityContextHolder now cleared, as request processing completed

3 个答案:

答案 0 :(得分:0)

可能我错过了什么。我不知道你为什么使用@EnableWebMvcSecurity使用Spring Boot,它已被弃用,但这不是重点。

如果您正在使用Spring Boot并希望创建一个允许每次通话的安全配置,您可以这样做:

@EnableWebSecurity
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().permitAll();
    }
}

答案 1 :(得分:0)

您没有禁用默认安全配置,因此Spring Boot使用默认安全配置,请参阅Spring Boot Reference Guide

  

默认安全配置在SecurityAutoConfiguration和从那里导入的类中实现(SpringBootWebSecurityConfiguration用于Web安全性,AuthenticationManagerConfiguration用于身份验证配置,这也与非Web应用程序相关) 。要完全关闭默认Web应用程序安全配置,您可以添加@EnableWebSecurity的bean(这不会禁用身份验证管理器配置或执行器的安全性)。要自定义它,通常使用类型为WebSecurityConfigurerAdapter的外部属性和bean(例如,添加基于表单的登录)。要同时关闭身份验证管理器配置,您可以添加AuthenticationManager类型的bean,或者通过将AuthenticationManagerBuilder自动装入@Configuration类中的某个方法来配置全局AuthenticationManager。 Spring Boot示例中有几个安全的应用程序可以帮助您开始使用常见的用例。

     

您在Web应用程序中开箱即用的基本功能包括:

     
      
  • 具有内存存储和单个用户的AuthenticationManager bean(有关用户属性,请参阅SecurityProperties.User)。
  •   
  • 常见静态资源位置(/css/**/js/**/images/**/webjars/****/favicon.ico)的忽略(不安全)路径。
  •   
  • 所有其他端点的HTTP基本安全性。
  •   
  • 发布到Spring ApplicationEventPublisher的安全事件(成功和失败的身份验证和拒绝访问)。
  •   
  • 默认情况下,Spring Security提供的常见低级功能(HSTS,XSS,CSRF,缓存)已启用。
  •   
     

以上所有内容都可以使用外部属性(security.*)打开或关闭或修改。要覆盖访问规则而不更改任何其他自动配置的功能,请添加@Bean WebSecurityConfigurerAdapter类型@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)并配置它以满足您的需求。

另见spring-boot-sample-web-secure

@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().fullyAuthenticated().and().formLogin()
                .loginPage("/login").failureUrl("/login?error").permitAll().and()
                .logout().permitAll();
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser("admin").password("admin")
                .roles("ADMIN", "USER").and().withUser("user").password("user")
                .roles("USER");
    }
}

答案 2 :(得分:0)

尽量忽略它:

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