Skip to content

Commit ab96f1e

Browse files
Merge pull request #13068 from HeshanSudarshana/master-is-opaque-token-websocket-issue
Make the REST API flow and WebSocket flow consistent for IS 7 client credentials opaque tokens
2 parents 759671b + e825357 commit ab96f1e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/WebsocketUtil.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.axis2.context.OperationContext;
2424
import org.apache.axis2.context.ServiceContext;
2525
import org.apache.axis2.description.InOutAxisOperation;
26+
import org.apache.commons.lang3.StringUtils;
2627
import org.apache.http.HttpHeaders;
2728
import org.apache.synapse.MessageContext;
2829
import org.apache.synapse.core.axis2.MessageContextCreatorForAxis2;
@@ -264,13 +265,19 @@ public static InboundProcessorResponseDTO validateDenyPolicies(InboundMessageCon
264265
String appLevelBlockingKey = "";
265266
String subscriptionLevelBlockingKey = "";
266267

268+
String authorizedUser = infoDTO.getEndUserName();
269+
//Check if the tenant domain is appended with authorizedUser and append if it is not there
270+
if (!StringUtils.contains(authorizedUser, apiTenantDomain)) {
271+
authorizedUser = authorizedUser + "@" + apiTenantDomain;
272+
}
273+
267274
if (ServiceReferenceHolder.getInstance().getThrottleDataHolder().isBlockingConditionsPresent()) {
268275
appLevelBlockingKey = infoDTO.getSubscriber() + ":" + infoDTO.getApplicationName();
269276
subscriptionLevelBlockingKey = apiContext + ":" + apiVersion + ":" + infoDTO.getSubscriber() + ":"
270277
+ infoDTO.getApplicationName() + ":" + infoDTO.getType();
271278
isBlockedRequest = ServiceReferenceHolder.getInstance().getThrottleDataHolder()
272-
.isRequestBlocked(apiContext, appLevelBlockingKey, infoDTO.getEndUserName(), clientIp,
273-
apiTenantDomain, subscriptionLevelBlockingKey);
279+
.isRequestBlocked(apiContext, appLevelBlockingKey, authorizedUser, clientIp, apiTenantDomain,
280+
subscriptionLevelBlockingKey);
274281
}
275282

276283
if (isBlockedRequest) {

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/inbound/websocket/Authentication/OAuthAuthenticator.java

+4
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ public InboundProcessorResponseDTO authenticate(InboundMessageContext inboundMes
194194
if (info == null || !info.isAuthorized()) {
195195
info.setAuthorized(false);
196196
}
197+
// set anonymous user if the username is null
198+
if (info.getEndUserName() == null) {
199+
info.setEndUserName(APIConstants.END_USER_ANONYMOUS);
200+
}
197201
if (WebsocketUtil.isGatewayTokenCacheEnabled()) {
198202
cacheKey = WebsocketUtil.getAccessTokenCacheKey(apiKey,
199203
inboundMessageContext.getApiContext(), inboundMessageContext.getMatchingResource());

0 commit comments

Comments
 (0)