|
31 | 31 | import org.wso2.carbon.apimgt.gateway.handlers.Utils;
|
32 | 32 | import org.wso2.carbon.apimgt.gateway.handlers.security.APISecurityConstants;
|
33 | 33 | import org.wso2.carbon.apimgt.gateway.handlers.security.APISecurityException;
|
| 34 | +import org.wso2.carbon.apimgt.gateway.internal.ServiceReferenceHolder; |
| 35 | +import org.wso2.carbon.apimgt.gateway.mediators.oauth.client.TokenResponse; |
34 | 36 | import org.wso2.carbon.apimgt.gateway.mediators.oauth.conf.OAuthEndpoint;
|
| 37 | +import org.wso2.carbon.apimgt.gateway.utils.redis.RedisCacheUtils; |
35 | 38 |
|
36 | 39 | /**
|
37 | 40 | * OAuthResponseMediator to handle error responses from OAuth 2.0 protected backends
|
@@ -59,7 +62,15 @@ public boolean mediate(MessageContext messageContext) {
|
59 | 62 | Object oauthEndpointObject = messageContext.getProperty(APIMgtGatewayConstants.OAUTH_ENDPOINT_INSTANCE);
|
60 | 63 | if (oauthEndpointObject instanceof OAuthEndpoint) {
|
61 | 64 | try {
|
62 |
| - OAuthTokenGenerator.generateToken((OAuthEndpoint) oauthEndpointObject, null); |
| 65 | + OAuthEndpoint oAuthEndpoint = (OAuthEndpoint) oauthEndpointObject; |
| 66 | + if (ServiceReferenceHolder.getInstance().isRedisEnabled()) { |
| 67 | + new RedisCacheUtils(ServiceReferenceHolder.getInstance().getRedisPool()) |
| 68 | + .deleteKey(oAuthEndpoint.getId()); |
| 69 | + } else { |
| 70 | + TokenCache.getInstance().getTokenMap().put(oAuthEndpoint.getId(), null); |
| 71 | + } |
| 72 | + |
| 73 | + OAuthTokenGenerator.generateToken(oAuthEndpoint, null); |
63 | 74 | log.error("OAuth 2.0 access token has been rejected by the backend...");
|
64 | 75 | handleFailure(APISecurityConstants.OAUTH_TEMPORARY_SERVER_ERROR, messageContext,
|
65 | 76 | APISecurityConstants.OAUTH_TEMPORARY_SERVER_ERROR_MESSAGE, "Please try again");
|
|
0 commit comments