Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

SalesforceErrorHandler does not properly handle BAD_OAUTH_TOKEN #6

Open
jottley opened this issue Jan 28, 2017 · 0 comments
Open

SalesforceErrorHandler does not properly handle BAD_OAUTH_TOKEN #6

jottley opened this issue Jan 28, 2017 · 0 comments

Comments

@jottley
Copy link

jottley commented Jan 28, 2017

When a token has expired and an attempt is made to use it again, BAD_OAUTH_TOKEN (with an HTTP response of 403 Forbidden) is returned. BAD_OAUTH_TOKEN is the response body and is not in a valid JSON format. The extractErrorDetailsFromResponse method in the SalesforceErrorHandler is expecting the response to be in JSON. We need to add a check in the JsonParseException to interrogate the response body to see if the response is BAD_OAUTH_TOKEN. It should trigger an Invalid Access Token Exception so that the client can attempt to either refresh the token or prompt the user to reauthorize.

2017-01-27 20:57:58,913 ERROR [extensions.webscripts.AbstractRuntime] [http-bio-8080-exec-2] Exception from executeScript - redirecting to status template error: 00270003 Wrapped Exception (with status template): Unable to read salesforce response. org.springframework.extensions.webscripts.WebScriptException: 00270003 Wrapped Exception (with status template): Unable to read salesforce response. at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1138) at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171) at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:512) at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:457) at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:580) at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:649) at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:421) at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:301) at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378) at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209) at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61) 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:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.social.UncategorizedApiException: Unable to read salesforce response. at org.springframework.social.salesforce.api.impl.SalesforceErrorHandler.extractErrorDetailsFromResponse(SalesforceErrorHandler.java:79) at org.springframework.social.salesforce.api.impl.SalesforceErrorHandler.handleError(SalesforceErrorHandler.java:28) at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:566) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:524) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:482) at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:430) at org.springframework.social.salesforce.api.impl.UserOperationsTemplate.getSalesforceUserDetails(UserOperationsTemplate.java:25) at org.springframework.social.salesforce.connect.SalesforceAdapter.setConnectionValues(SalesforceAdapter.java:69) at org.springframework.social.salesforce.connect.SalesforceAdapter.setConnectionValues(SalesforceAdapter.java:20) at org.springframework.social.connect.support.AbstractConnection.setValues(AbstractConnection.java:172) at org.springframework.social.connect.support.AbstractConnection.initKey(AbstractConnection.java:135) at org.springframework.social.connect.support.OAuth2Connection.<init>(OAuth2Connection.java:73) at org.springframework.social.connect.support.OAuth2ConnectionFactory.createConnection(OAuth2ConnectionFactory.java:58) at org.alfresco.integrations.sfdc.services.CanvasServiceImpl.getConnection(CanvasServiceImpl.java:878) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:159) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.alfresco.repo.transaction.RetryingTransactionAdvice$1.execute(RetryingTransactionAdvice.java:64) at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:457) at org.alfresco.repo.transaction.RetryingTransactionAdvice.invoke(RetryingTransactionAdvice.java:67) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy337.getConnection(Unknown Source) at net.ottleys.alfresco.demoamp.SFDCWebScript.executeImpl(SFDCWebScript.java:45) at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64) ... 32 more Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Bad_OAuth_Token': was expecting ('true', 'false' or 'null') at [Source: org.apache.http.conn.EofSensorInputStream@46c2b6f; line: 1, column: 31] at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1524) at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:557) at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._reportInvalidToken(UTF8StreamJsonParser.java:3094) at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2339) at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:817) at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:697) at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3031) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2978) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2158) at org.springframework.social.salesforce.api.impl.SalesforceErrorHandler.extractErrorDetailsFromResponse(SalesforceErrorHandler.java:73) ... 66 more

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant