use of org.wso2.carbon.apimgt.gateway.inbound.InboundMessageContext in project carbon-apimgt by wso2.
the class InboundWebsocketProcessorUtil method findMatchingVerb.
/**
* Finds matching VerbInfoDTO for the subscription operation.
*
* @param operation subscription operation name
* @param inboundMessageContext InboundMessageContext
* @return VerbInfoDTO
*/
public static VerbInfoDTO findMatchingVerb(String operation, InboundMessageContext inboundMessageContext) {
String resourceCacheKey;
VerbInfoDTO verbInfoDTO = null;
if (inboundMessageContext.getResourcesMap() != null) {
ResourceInfoDTO resourceInfoDTO = inboundMessageContext.getResourcesMap().get(operation);
Set<VerbInfoDTO> verbDTOList = resourceInfoDTO.getHttpVerbs();
for (VerbInfoDTO verb : verbDTOList) {
if (verb.getHttpVerb().equals(GraphQLConstants.SubscriptionConstants.HTTP_METHOD_NAME)) {
if (isResourcePathMatching(operation, resourceInfoDTO)) {
verbInfoDTO = verb;
resourceCacheKey = APIUtil.getResourceInfoDTOCacheKey(inboundMessageContext.getApiContext(), inboundMessageContext.getVersion(), operation, GraphQLConstants.SubscriptionConstants.HTTP_METHOD_NAME);
verb.setRequestKey(resourceCacheKey);
break;
}
}
}
}
return verbInfoDTO;
}
use of org.wso2.carbon.apimgt.gateway.inbound.InboundMessageContext in project carbon-apimgt by wso2.
the class HandshakeProcessor method processHandshake.
/**
* This method process websocket handshake and perform authentication using the inbound message context.
* For successful authentications, it sets the resource map of the invoking API to the context.
*
* @param inboundMessageContext InboundMessageContext
* @return InboundProcessorResponseDTO with handshake processing response
*/
public InboundProcessorResponseDTO processHandshake(InboundMessageContext inboundMessageContext) {
if (log.isDebugEnabled()) {
log.debug("Processing handshake message for inbound websocket context: " + inboundMessageContext.getApiContext());
}
InboundProcessorResponseDTO inboundProcessorResponseDTO = new InboundProcessorResponseDTO();
boolean isOAuthHeaderValid;
try {
isOAuthHeaderValid = InboundWebsocketProcessorUtil.isAuthenticated(inboundMessageContext);
} catch (APIManagementException e) {
log.error(WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_GENERAL_MESSAGE, e);
return InboundWebsocketProcessorUtil.getHandshakeErrorDTO(WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_ERROR, WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_GENERAL_MESSAGE);
} catch (APISecurityException e) {
log.error(e);
return InboundWebsocketProcessorUtil.getHandshakeErrorDTO(WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_ERROR, e.getMessage());
}
if (isOAuthHeaderValid) {
if (log.isDebugEnabled()) {
log.debug("Handshake authentication success for inbound websocket context: " + inboundMessageContext.getApiContext() + " Setting ResourceInfoDTOs of elected API " + "to inbound message context");
}
setResourcesMapToContext(inboundMessageContext);
} else {
log.error("Authentication failed for " + inboundMessageContext.getApiContext());
return InboundWebsocketProcessorUtil.getHandshakeErrorDTO(WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_ERROR, WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_INVALID_CREDENTIALS_MESSAGE);
}
return inboundProcessorResponseDTO;
}
use of org.wso2.carbon.apimgt.gateway.inbound.InboundMessageContext in project carbon-apimgt by wso2.
the class HandshakeProcessor method setResourcesMapToContext.
/**
* Set the resource map with VerbInfoDTOs to the context using URL mappings from the InboundMessageContext.
*
* @param inboundMessageContext InboundMessageContext
*/
private void setResourcesMapToContext(InboundMessageContext inboundMessageContext) {
List<URLMapping> urlMappings = inboundMessageContext.getElectedAPI().getResources();
Map<String, ResourceInfoDTO> resourcesMap = inboundMessageContext.getResourcesMap();
ResourceInfoDTO resourceInfoDTO;
VerbInfoDTO verbInfoDTO;
for (URLMapping urlMapping : urlMappings) {
resourceInfoDTO = resourcesMap.get(urlMapping.getUrlPattern());
if (resourceInfoDTO == null) {
resourceInfoDTO = new ResourceInfoDTO();
resourceInfoDTO.setUrlPattern(urlMapping.getUrlPattern());
resourceInfoDTO.setHttpVerbs(new LinkedHashSet<>());
resourcesMap.put(urlMapping.getUrlPattern(), resourceInfoDTO);
}
verbInfoDTO = new VerbInfoDTO();
verbInfoDTO.setHttpVerb(urlMapping.getHttpMethod());
verbInfoDTO.setAuthType(urlMapping.getAuthScheme());
verbInfoDTO.setThrottling(urlMapping.getThrottlingPolicy());
resourceInfoDTO.getHttpVerbs().add(verbInfoDTO);
}
}
use of org.wso2.carbon.apimgt.gateway.inbound.InboundMessageContext in project carbon-apimgt by wso2.
the class InboundWebSocketProcessor method getMessageContext.
/**
* Get synapse message context from tenant domain.
*
* @param inboundMessageContext InboundMessageContext
* @return MessageContext
* @throws AxisFault if an error occurs getting context
* @throws URISyntaxException if an error occurs getting transport scheme
*/
private MessageContext getMessageContext(InboundMessageContext inboundMessageContext) throws AxisFault, URISyntaxException {
String tenantDomain = inboundMessageContext.getTenantDomain();
MessageContext synCtx = WebsocketUtil.getSynapseMessageContext(tenantDomain);
org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
msgCtx.setIncomingTransportName(new URI(inboundMessageContext.getFullRequestPath()).getScheme());
msgCtx.setProperty(Constants.Configuration.TRANSPORT_IN_URL, inboundMessageContext.getFullRequestPath());
// Sets axis2 message context in InboundMessageContext for later use
inboundMessageContext.setAxis2MessageContext(msgCtx);
return synCtx;
}
use of org.wso2.carbon.apimgt.gateway.inbound.InboundMessageContext in project carbon-apimgt by wso2.
the class InboundWebSocketProcessor method handleRequest.
/**
* This method process websocket request messages (publish messages) and
* hand over the processing to relevant request intercepting processor for authentication, scope validation,
* throttling etc.
*
* @param msg Websocket request message frame
* @param inboundMessageContext InboundMessageContext
* @return InboundProcessorResponseDTO with handshake processing response
*/
public InboundProcessorResponseDTO handleRequest(WebSocketFrame msg, InboundMessageContext inboundMessageContext) {
RequestProcessor requestProcessor;
String msgText = null;
if (APIConstants.GRAPHQL_API.equals(inboundMessageContext.getElectedAPI().getApiType()) && msg instanceof TextWebSocketFrame) {
requestProcessor = new GraphQLRequestProcessor();
msgText = ((TextWebSocketFrame) msg).text();
} else {
requestProcessor = new RequestProcessor();
}
return requestProcessor.handleRequest(msg.content().capacity(), msgText, inboundMessageContext);
}
Aggregations