springsecurity登录出现Full authentication is required to access this resource的问题解决

最近项目中出现了一个很奇怪的问题,使用/oauth/token登录的时候,第一次登录必然会出现Full authentication is required to access this resource错误,然后再一次登录就没有事了.

出现这个问题的原因有很多,网上的解决方案也都各不相同,针对的地方不一样.实际上出现这个的问题有很多,这里介绍一种调试的办法.
首先将登录对应的项目的日志改为debug,然后重现问题,这时springsecurity会将整个登录过程的日志打印在控制台
例如:

2019/09/12-11:10:06.470 DEBUG [http-nio-8003-Acceptor-0] org.apache.juli.logging.DirectJDKLog:173>>Counting up[http-nio-8003-Acceptor-0] latch=1
2019/09/12-11:10:06.474 DEBUG [http-nio-8003-Acceptor-0] org.apache.juli.logging.DirectJDKLog:173>>Counting up[http-nio-8003-Acceptor-0] latch=2
2019/09/12-11:10:06.474 DEBUG [http-nio-8003-exec-7] org.apache.juli.logging.DirectJDKLog:173>>Processing socket [org.apache.tomcat.util.net.NioChannel@53ce5f83:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52486]] with status [OPEN_READ]
2019/09/12-11:10:06.474 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Processing socket [org.apache.tomcat.util.net.NioChannel@6c78059b:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52487]] with status [OPEN_READ]
2019/09/12-11:10:06.475 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Found processor [null] for socket [org.apache.tomcat.util.net.NioChannel@6c78059b:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52487]]
2019/09/12-11:10:06.475 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Popped processor [org.apache.coyote.http11.Http11Processor@2f788cfb] from cache
2019/09/12-11:10:06.475 DEBUG [http-nio-8003-exec-7] org.apache.juli.logging.DirectJDKLog:173>>Found processor [null] for socket [org.apache.tomcat.util.net.NioChannel@53ce5f83:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52486]]
2019/09/12-11:10:06.475 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2289d5fc:org.apache.tomcat.util.net.NioChannel@6c78059b:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52487]], Read from buffer: [0]
2019/09/12-11:10:06.475 DEBUG [http-nio-8003-exec-7] org.apache.juli.logging.DirectJDKLog:173>>Popped processor [org.apache.coyote.http11.Http11Processor@5218199f] from cache
2019/09/12-11:10:06.475 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2289d5fc:org.apache.tomcat.util.net.NioChannel@6c78059b:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52487]], Read direct from socket: [489]
2019/09/12-11:10:06.475 DEBUG [http-nio-8003-exec-7] org.apache.juli.logging.DirectJDKLog:173>>Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@34d7b7be:org.apache.tomcat.util.net.NioChannel@53ce5f83:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52486]], Read from buffer: [0]
2019/09/12-11:10:06.475 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Received [POST /oauth/token?username=你的登录名&password=密码&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write HTTP/1.1
Authorization: Basic 我隐藏了
User-Agent: PostmanRuntime/7.15.0
Accept: */*
Cache-Control: no-cache
Postman-Token: ec3517e2-eb82-4a6f-84c6-437d4be3b7be
Host: localhost:8003
cookie: JSESSIONID=9995EEB7394172DF7CA0F69F88A1F03C
accept-encoding: gzip, deflate
content-length: 0
Connection: keep-alive

]
2019/09/12-11:10:06.475 DEBUG [http-nio-8003-exec-7] org.apache.juli.logging.DirectJDKLog:175>>Error parsing HTTP request header
java.io.EOFException: null
	at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1208)
	at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1142)
	at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:729)
	at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:352)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:294)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
2019/09/12-11:10:06.476 DEBUG [http-nio-8003-exec-7] org.apache.juli.logging.DirectJDKLog:173>>Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@34d7b7be:org.apache.tomcat.util.net.NioChannel@53ce5f83:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52486]], Status in: [OPEN_READ], State out: [CLOSED]
2019/09/12-11:10:06.476 DEBUG [http-nio-8003-exec-7] org.apache.juli.logging.DirectJDKLog:173>>Pushed Processor [org.apache.coyote.http11.Http11Processor@5218199f]
2019/09/12-11:10:06.477 DEBUG [http-nio-8003-exec-7] org.apache.juli.logging.DirectJDKLog:173>>Counting down[http-nio-8003-exec-7] latch=2
2019/09/12-11:10:06.477 DEBUG [http-nio-8003-exec-7] org.apache.juli.logging.DirectJDKLog:173>>Socket: [org.apache.tomcat.util.net.NioChannel@53ce5f83:java.nio.channels.SocketChannel[closed]] closed
2019/09/12-11:10:06.477 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Cookies: Parsing b[]: JSESSIONID=9995EEB7394172DF7CA0F69F88A1F03C
2019/09/12-11:10:06.478 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>> Requested cookie session id is 9995EEB7394172DF7CA0F69F88A1F03C
2019/09/12-11:10:06.478 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Security checking request POST /oauth/token
2019/09/12-11:10:06.478 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>  No applicable constraints defined
2019/09/12-11:10:06.478 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>> Not subject to any constraint
2019/09/12-11:10:06.478 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/oauth/token']
2019/09/12-11:10:06.478 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/oauth/token'; against '/oauth/token'
2019/09/12-11:10:06.478 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:68>>matched
2019/09/12-11:10:06.478 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/oauth/token?username=登录名&password=密码&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 1 of 11 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2019/09/12-11:10:06.479 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/oauth/token?username=XXX&password=XXX&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 2 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2019/09/12-11:10:06.479 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/oauth/token?username=XXX&password=XXX&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 3 of 11 in additional filter chain; firing Filter: 'HeaderWriterFilter'
2019/09/12-11:10:06.479 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/oauth/token?username=XXX&password=XXX&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 4 of 11 in additional filter chain; firing Filter: 'LogoutFilter'
2019/09/12-11:10:06.479 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/logout', GET]
2019/09/12-11:10:06.479 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:156>>Request 'POST /oauth/token' doesn't match 'GET /logout'
2019/09/12-11:10:06.479 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/logout', POST]
2019/09/12-11:10:06.479 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/oauth/token'; against '/logout'
2019/09/12-11:10:06.479 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/logout', PUT]
2019/09/12-11:10:06.479 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:156>>Request 'POST /oauth/token' doesn't match 'PUT /logout'
2019/09/12-11:10:06.480 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/logout', DELETE]
2019/09/12-11:10:06.480 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:156>>Request 'POST /oauth/token' doesn't match 'DELETE /logout'
2019/09/12-11:10:06.480 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:72>>No matches found
2019/09/12-11:10:06.480 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/oauth/token?username=XXX&password=XXX&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 5 of 11 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
2019/09/12-11:10:06.480 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.authentication.www.BasicAuthenticationFilter:170>>Basic Authentication Authorization header found for user 'jtl'
2019/09/12-11:10:06.480 DEBUG [http-nio-8003-exec-4] org.springframework.security.authentication.ProviderManager:169>>Authentication attempt using org.springframework.security.authentication.dao.DaoAuthenticationProvider
2019/09/12-11:10:06.480 DEBUG [http-nio-8003-exec-4] org.springframework.jdbc.core.JdbcTemplate:667>>Executing prepared SQL query
2019/09/12-11:10:06.481 DEBUG [http-nio-8003-exec-4] org.springframework.jdbc.core.JdbcTemplate:609>>Executing prepared SQL statement [select client_id, client_secret, resource_ids, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove from oauth_client_details where client_id = ?]
2019/09/12-11:10:06.481 DEBUG [http-nio-8003-exec-4] org.springframework.jdbc.datasource.DataSourceUtils:114>>Fetching JDBC Connection from DataSource
2019/09/12-11:10:06.483 DEBUG [http-nio-8003-exec-4] org.springframework.jdbc.datasource.DataSourceUtils:340>>Returning JDBC Connection to DataSource
2019/09/12-11:10:06.483 DEBUG [http-nio-8003-exec-4] org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator:284>>Unable to translate SQLException with Error code '0', will now try the fallback translator
2019/09/12-11:10:06.483 DEBUG [http-nio-8003-exec-4] org.springframework.security.authentication.DefaultAuthenticationEventPublisher:129>>No event was found for the exception org.springframework.security.authentication.InternalAuthenticationServiceException
2019/09/12-11:10:06.483 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.authentication.www.BasicAuthenticationFilter:198>>Authentication request for failed: org.springframework.security.authentication.InternalAuthenticationServiceException: PreparedStatementCallback; SQL [select client_id, client_secret, resource_ids, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove from oauth_client_details where client_id = ?]; Communications link failure

The last packet successfully received from the server was 1,280,804 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet successfully received from the server was 1,280,804 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.
2019/09/12-11:10:06.484 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint:78>>Trying to match using RequestHeaderRequestMatcher [expectedHeaderName=X-Requested-With, expectedHeaderValue=XMLHttpRequest]
2019/09/12-11:10:06.484 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint:91>>No match found. Using default entry point org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint@63be0551
2019/09/12-11:10:06.484 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.header.writers.HstsHeaderWriter:129>>Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@28121b92
2019/09/12-11:10:06.484 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.context.SecurityContextPersistenceFilter:119>>SecurityContextHolder now cleared, as request processing completed
2019/09/12-11:10:06.484 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Processing ErrorPage[errorCode=0, location=/error]
2019/09/12-11:10:06.485 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/oauth/token']
2019/09/12-11:10:06.485 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/oauth/token'
2019/09/12-11:10:06.485 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/oauth/token_key']
2019/09/12-11:10:06.485 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/oauth/token_key'
2019/09/12-11:10:06.486 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/oauth/check_token']
2019/09/12-11:10:06.486 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/oauth/check_token'
2019/09/12-11:10:06.486 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:72>>No matches found
2019/09/12-11:10:06.486 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=XXX&password=XXX&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 1 of 11 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2019/09/12-11:10:06.486 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=XXX&password=XXX&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 2 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2019/09/12-11:10:06.486 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=XXX&password=XXX&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 3 of 11 in additional filter chain; firing Filter: 'HeaderWriterFilter'
2019/09/12-11:10:06.486 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=XXX&password=XXX&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 4 of 11 in additional filter chain; firing Filter: 'LogoutFilter'
2019/09/12-11:10:06.486 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/logout', GET]
2019/09/12-11:10:06.486 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:156>>Request 'POST /error' doesn't match 'GET /logout'
2019/09/12-11:10:06.487 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/logout', POST]
2019/09/12-11:10:06.487 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/logout'
2019/09/12-11:10:06.487 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/logout', PUT]
2019/09/12-11:10:06.487 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:156>>Request 'POST /error' doesn't match 'PUT /logout'
2019/09/12-11:10:06.487 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:65>>Trying to match using Ant [pattern='/logout', DELETE]
2019/09/12-11:10:06.487 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:156>>Request 'POST /error' doesn't match 'DELETE /logout'
2019/09/12-11:10:06.487 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.OrRequestMatcher:72>>No matches found
2019/09/12-11:10:06.487 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=XXX&password=XXXrandomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 5 of 11 in additional filter chain; firing Filter: 'OAuth2AuthenticationProcessingFilter'
2019/09/12-11:10:06.488 DEBUG [http-nio-8003-exec-4] org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor:54>>Token not found in headers. Trying request parameters.
2019/09/12-11:10:06.488 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Set encoding to UTF-8
2019/09/12-11:10:06.488 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Decoding query null UTF-8
2019/09/12-11:10:06.488 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Start processing with input [username=XXX&password=XXX&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write]
2019/09/12-11:10:06.488 DEBUG [http-nio-8003-exec-4] org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor:57>>Token not found in request parameters.  Not an OAuth2 request.
2019/09/12-11:10:06.488 DEBUG [http-nio-8003-exec-4] org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter:141>>No token in request, will continue chain.
2019/09/12-11:10:06.488 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=18838232636&password=XXX&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 6 of 11 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=18838232636&password=uDsuOT4tGh5rzCnEXzVj6Q%3D%3D&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 7 of 11 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=18838232636&password=uDsuOT4tGh5rzCnEXzVj6Q%3D%3D&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 8 of 11 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.authentication.AnonymousAuthenticationFilter:100>>Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@e72695f8: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS'
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=18838232636&password=uDsuOT4tGh5rzCnEXzVj6Q%3D%3D&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 9 of 11 in additional filter chain; firing Filter: 'SessionManagementFilter'
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.session.SessionManagementFilter:124>>Requested session ID 9995EEB7394172DF7CA0F69F88A1F03C is invalid.
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=18838232636&password=uDsuOT4tGh5rzCnEXzVj6Q%3D%3D&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 10 of 11 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.FilterChainProxy$VirtualFilterChain:328>>/error?username=18838232636&password=uDsuOT4tGh5rzCnEXzVj6Q%3D%3D&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write at position 11 of 11 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/code'
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/getVerifyImage'
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/verifyPoint'
2019/09/12-11:10:06.489 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/addSysOry'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/code-text'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/addSysUser'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/check-phone'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/phoneCode'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/checkCode'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/type'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/getPhoneCode'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/swagger-ui.html'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/favicon.ico'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/webjars/springfox-swagger-ui/**/*.*'
2019/09/12-11:10:06.490 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/swagger-resources/configuration/*'
2019/09/12-11:10:06.491 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/swagger-resources'
2019/09/12-11:10:06.491 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/checkPhoneAndCode'
2019/09/12-11:10:06.491 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.util.matcher.AntPathRequestMatcher:176>>Checking match of request : '/error'; against '/v2/*'
2019/09/12-11:10:06.491 DEBUG [http-nio-8003-exec-4] org.springframework.security.access.intercept.AbstractSecurityInterceptor:219>>Secure object: FilterInvocation: URL: /error?username=18838232636&password=uDsuOT4tGh5rzCnEXzVj6Q%3D%3D&randomStr=9326123123123123131&code=23nw&grant_type=password&loginType=1&scope=read+write; Attributes: [#oauth2.throwOnError(authenticated)]
2019/09/12-11:10:06.491 DEBUG [http-nio-8003-exec-4] org.springframework.security.access.intercept.AbstractSecurityInterceptor:348>>Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@e72695f8: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS
2019/09/12-11:10:06.492 DEBUG [http-nio-8003-exec-4] org.springframework.security.access.vote.AffirmativeBased:66>>Voter: org.springframework.security.web.access.expression.WebExpressionVoter@7cfc83c8, returned: -1
2019/09/12-11:10:14.170 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.access.ExceptionTranslationFilter:181>>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.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.doFilter(OAuth2AuthenticationProcessingFilter.java:176)
	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.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
	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.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
	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:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
	at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:394)
	at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:253)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:175)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
2019/09/12-11:10:14.171 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.access.ExceptionTranslationFilter:212>>Calling Authentication entry point.
2019/09/12-11:10:14.173 DEBUG [http-nio-8003-exec-4] org.springframework.security.oauth2.provider.error.DefaultOAuth2ExceptionRenderer:101>>Written [error="unauthorized", error_description="Full authentication is required to access this resource"] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2b7a10ea]
2019/09/12-11:10:14.174 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.context.SecurityContextPersistenceFilter:119>>SecurityContextHolder now cleared, as request processing completed
2019/09/12-11:10:14.174 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>> Disabling the response for further output
2019/09/12-11:10:14.175 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2289d5fc:org.apache.tomcat.util.net.NioChannel@6c78059b:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52487]], Read from buffer: [0]
2019/09/12-11:10:14.175 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2289d5fc:org.apache.tomcat.util.net.NioChannel@6c78059b:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52487]], Read direct from socket: [0]
2019/09/12-11:10:14.176 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@2289d5fc:org.apache.tomcat.util.net.NioChannel@6c78059b:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8003 remote=/0:0:0:0:0:0:0:1:52487]], Status in: [OPEN_READ], State out: [OPEN]
2019/09/12-11:10:14.176 DEBUG [http-nio-8003-exec-4] org.apache.juli.logging.DirectJDKLog:173>>Pushed Processor [org.apache.coyote.http11.Http11Processor@2f788cfb]

经过仔细查看,最终确定了 问题的根源在于

2019/09/12-11:10:06.483 DEBUG [http-nio-8003-exec-4] org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator:284>>Unable to translate SQLException with Error code '0', will now try the fallback translator
2019/09/12-11:10:06.483 DEBUG [http-nio-8003-exec-4] org.springframework.security.authentication.DefaultAuthenticationEventPublisher:129>>No event was found for the exception org.springframework.security.authentication.InternalAuthenticationServiceException
2019/09/12-11:10:06.483 DEBUG [http-nio-8003-exec-4] org.springframework.security.web.authentication.www.BasicAuthenticationFilter:198>>Authentication request for failed: org.springframework.security.authentication.InternalAuthenticationServiceException: PreparedStatementCallback; SQL [select client_id, client_secret, resource_ids, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove from oauth_client_details where client_id = ?]; Communications link failure

The last packet successfully received from the server was 1,280,804 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet successfully received from the server was 1,280,804 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.

Communications link failure,数据库连接有问题,然后针对性的去处理这个问题,最终确定了是因为Mysql的wait_timeout设置的时间过短,造成登录时查询数据库访问被拒绝,修改后问题解决

发布了17 篇原创文章 · 获赞 1 · 访问量 3149

猜你喜欢

转载自blog.csdn.net/chouyiqiong5655/article/details/100771923