Ember: Content Security Policy violation - Issue while fetching data through REST service - ember.js

I am not getting data from Rest Get service url in ember(I am getting data when I hit service via browser and Rest client). When I checked the console, I found that it is listed as blocked-uri. How can I remove that from the blocked-uri list.
{
"csp-report": {
"blocked-uri": "http://192.168.1.66:8080/hubx/employees",
"document-uri": "http://localhost:4200/data-grid",
"original-policy": "default-src 'none'; script-src http://localhost:4200 'unsafe-eval' 'unsafe-inline' http://localhost:49152 http://0.0.0.0:49152; font-src http://localhost:4200; connect-src http://localhost:4200 ws://localhost:49152 ws://0.0.0.0:49152 http://localhost:4200; img-src http://localhost:4200; style-src http://localhost:4200; media-src http://localhost:4200; report-uri http://localhost:4200/csp-report",
"referrer": "",
"violated-directive": "connect-src http://localhost:4200 ws://localhost:49152 ws://0.0.0.0:49152 http://localhost:4200"
}
}

I have remove the url from blocked-uri by adding the url to connect-src.
contentSecurityPolicy: {
'connect-src': "'self' http://localhost:4200 http://192.168.1.66:8080 ",
}
But that was not the issue for me. Issue was due to Cross-Origin Resource Sharing and it is fixed by adding the filters in web.xml of tomact server.
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,DELETE,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control- Request-Method,Access-Control-Request-Headers,Authorization</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.preflight.maxage</param-name>
<param-value>10</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Related

Sample Pickup dispatch web app giving CORS issue when making backend api calls in WSO2 IS 5.10

I'm testing the pickup dispatch sample web app for WSO2 Identity Server 5.10
https://is.docs.wso2.com/en/5.9.0/learn/configuring-access-delegation-with-oauth2/
Everything is set up as mentioned in the documentation. When clicking 'Add' the request cannot be completed because it is being blocked dues to CORS policy.
Access to XMLHttpRequest at 'http://localhost:39090/bookings' from origin 'http://localhost.com:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I have added the following
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
To the files
CARBON_HOME\repository\deployment\server\webapps\oauth2\WEB-INF\web.xml
TOMCAT_HOME\webapps\pickup-dispatch\WEB-INF\web.xml
as mentioned in this post http://hasanthipurnima.blogspot.com/2016/05/applying-cors-filter-to-wso2-identity.html
But still, I'm getting the error. Here is the request header
UPDATE:
Here is the error log that is recorded when the CORS issue arises
G:\wso2>java -jar backend-service.jar -introspectionEnabled true
2020-06-09 11:43:24 INFO BookingService:47 - Service properties loaded successfully.
2020-06-09 11:43:24 INFO BookingService:84 - Setting trust store path to : C:\Users\tvenna\AppData\Local\Temp\wso2carbon.jks3555396828881642435
2020-06-09 11:43:24 INFO BookingService:109 - Starting backend service.
2020-06-09 11:43:24 INFO BookingService:110 - Configurations :
2020-06-09 11:43:24 INFO BookingService:113 - port: 39090
2020-06-09 11:43:24 INFO BookingService:113 - introspectionEndpoint: https://localhost:9443/oauth2/introspect
2020-06-09 11:43:24 INFO BookingService:113 - introspectionEnabled: true
2020-06-09 11:43:24 INFO MicroservicesRunner:309 - Microservices server started in 267ms
2020-06-09 11:43:24 INFO ServerConnectorBootstrap$HTTPServerConnector:207 - HTTP(S) Interface starting on host 0.0.0.0 and port 39090
2020-06-09 11:43:46 INFO BookingService:66 - OPTIONS /bookings
2020-06-09 11:43:46 INFO BookingService:80 - GET /bookings
2020-06-09 11:43:46 ERROR IntrospectionHandler:107 - Error while calling token introspection endpoint
java.io.IOException: Server returned HTTP response code: 403 for URL: https://localhost:9443/oauth2/introspect
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at org.wso2.sample.identity.backend.IntrospectionHandler.getIntrospectionResponse(IntrospectionHandler.java:95)
at org.wso2.sample.identity.backend.IntrospectionHandler.isAuthorized(IntrospectionHandler.java:65)
at org.wso2.sample.identity.backend.BookingService.bookingsGet(BookingService.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.wso2.msf4j.internal.router.HttpMethodInfo.invokeResource(HttpMethodInfo.java:187)
at org.wso2.msf4j.internal.router.HttpMethodInfo.invoke(HttpMethodInfo.java:143)
at org.wso2.msf4j.internal.MSF4JHttpConnectorListener.dispatchMethod(MSF4JHttpConnectorListener.java:218)
at org.wso2.msf4j.internal.MSF4JHttpConnectorListener.lambda$onMessage$57(MSF4JHttpConnectorListener.java:129)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
2020-06-09 11:43:46 WARN MSF4JHttpConnectorListener:243 - Unmapped exception
java.lang.RuntimeException: java.io.IOException: Server returned HTTP response code: 403 for URL: https://localhost:9443/oauth2/introspect
at org.wso2.sample.identity.backend.IntrospectionHandler.getIntrospectionResponse(IntrospectionHandler.java:108)
at org.wso2.sample.identity.backend.IntrospectionHandler.isAuthorized(IntrospectionHandler.java:65)
at org.wso2.sample.identity.backend.BookingService.bookingsGet(BookingService.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.wso2.msf4j.internal.router.HttpMethodInfo.invokeResource(HttpMethodInfo.java:187)
at org.wso2.msf4j.internal.router.HttpMethodInfo.invoke(HttpMethodInfo.java:143)
at org.wso2.msf4j.internal.MSF4JHttpConnectorListener.dispatchMethod(MSF4JHttpConnectorListener.java:218)
at org.wso2.msf4j.internal.MSF4JHttpConnectorListener.lambda$onMessage$57(MSF4JHttpConnectorListener.java:129)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: https://localhost:9443/oauth2/introspect
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at org.wso2.sample.identity.backend.IntrospectionHandler.getIntrospectionResponse(IntrospectionHandler.java:95)
... 13 more
added the following to
CARBON_HOME\repository\resources\conf\templates\repository\conf\tomcat\web.xml.j2
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, HEAD, POST, DELETE, OPTIONS, PATCH, PUT</param-value>
</init-param>
<init-param>
<param-name>cors.exposedHeaders</param-name>
<param-value>Location</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Restarted IS and tomcat, still the issue persists.
Testing in Chrome and Firefox browser.
From your updated stack trace, I can see that the issue occurs when the backend service trying to make an introspection call to the WSO2 Identity Server. This introspection call uses the token it's introspecting as the authorization for the call it self. For this to work, the token needs to be obtained with the scope internal_application_mgt_view. But at the moment, the pickup-dispatch application requests tokens with only the openid scope.
To fix this, open the dispatch.properties file in /pickup-dispatch/WEB-INF/classes directory in a text editor and edit the scope property as shown below.
scope=openid internal_application_mgt_view
Restart your Tomcat server and try again.
I hope this helps!

WSO2 Micro Integrator Validate Mediator fails with Unsupported Operation

Working with Integration Studio in Windows 10.
When I try Validate my Payload from REST API body with Sequence with Validate Mediator I get an Error.
Error:
[2020-03-10 11:07:29,295] INFO {TRACE_LOGGER} - Building message. Sequence <SequenceMediator> is content aware
[2020-03-10 11:07:29,309] ERROR {org.apache.synapse.mediators.base.SequenceMediator} - Unsupported Operation org.apache.axiom.om.OMException: Unsupported Operation
at org.apache.axiom.om.impl.llom.OMTextImpl.getInputStream(OMTextImpl.java:422)
at org.apache.synapse.mediators.builtin.ValidateMediator.mediate(ValidateMediator.java:231)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:214)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
at org.apache.synapse.config.xml.AnonymousListMediator.mediate(AnonymousListMediator.java:37)
at org.apache.synapse.config.xml.SwitchCase.mediate(SwitchCase.java:69)
at org.apache.synapse.mediators.filters.SwitchMediator.mediate(SwitchMediator.java:134)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.rest.Resource.process(Resource.java:331)
at org.apache.synapse.rest.API.process(API.java:440)
at org.apache.synapse.rest.RESTRequestHandler.apiProcessNonDefaultStrategy(RESTRequestHandler.java:149)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:95)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:71)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:325)
at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:98)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:367)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:412)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:181)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Then I try to validate from it:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="Reserves" statistics="enable" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<validate cache-schema="false" source="json-eval($)">
<schema key="conf:/schemas/ReservesRoot.json"/>
<on-fail>
<payloadFactory media-type="json">
<format>{"Error":$1"}</format>
<args>
<arg evaluator="xml" expression="$ctx:ERROR_MESSAGE"/>
</args>
</payloadFactory>
<property name="HTTP_SC" scope="axis2" type="STRING" value="500"/>
<respond/>
</on-fail>
</validate>
</sequence>
JSON Schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"Type": {
"type": "string"
}
},
"required": [
"Type"
]
}
When I get the schema in property I see the schema's string.
<property value="get-property('registry', 'conf:/schemas/ReservesRoot.json')" name="ReservesSchema"/>
<log>
<property expression="get-property('ReservesSchema')" name="JSON_P"/>
</log>
This issue occurs when the JSON-schema saved in the registry does not have the correct media-type (must be application/json). Could you please double-check this in Integration studio Resources Editor view.
You can access the resources editor view by right click on registry resource project -> Registry resource editor
This issue occurs with Micro integrator. Micro integrator does not have rdbms registry artifacts. Hence we cannot specify the media type. The work around is to add local entry file with the validation json schema and refer it in synapse.
<validate cache-schema="false">
<schema key="createotpvalidate"/>
<on-fail>
<payloadFactory media-type="json">
<format>{"Error":$1"}</format>
<args>
<arg evaluator="xml" expression="$ctx:ERROR_MESSAGE"/>
</args>
</payloadFactory>
<property name="HTTP_SC" scope="axis2" type="STRING" value="500"/>
<respond/>
<!-- <schema key="conf:/schema/CreateOTPSchema.json"/> -->
</on-fail>
</validate>
Local Entry file:
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="createotpvalidate" xmlns="http://ws.apache.org/ns/synapse"><![CDATA[{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "request_type": { "type": "string" },"mobile": { "type": "string" },"otp": { "type": "string" } }, "required": [ "request_type","mobile","otp" ] }]]></localEntry>

How to enable X-Frame-Options in WSO2 5.4.1?

I tried to configure my jaggery.conf file as stated in the documentation to allow framing as follows :
"filters":[
{
"name":"HttpHeaderSecurityFilter",
"class":"org.apache.catalina.filters.HttpHeaderSecurityFilter",
"params" : [
{"name" : "hstsEnabled", "value" : "false"},
{ "name": "antiClickJackingOption", "value": "SAMEORIGIN" }
]
},
{
"name": "ContentTypeBasedCachePreventionFilter",
"class": "org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter",
"params":[
{"name": "patterns", "value": "text/html\" ,application/json\" ,plain/text"},
{"name": "filterAction", "value": "enforce"},
{"name": "httpHeaders", "value": "Cache-Control: no-store, no-cache, must-revalidate, private"}
]
}
],
Despite, in my client app, I still get a message saying that framing isn't allowed.
Load denied by X-Frame-Options: https://localhost:9444/authenticationendpoint/oauth2_error.do?oauthErrorCode=invalid_callback&oauthErrorMsg=Registered+callback+does+not+match+with+the+provided+url. does not permit framing.
Since this issue is coming from authenticationendpoint, you have to configure HttpHeaderSecurityFilter filter in the file <IS_HOME>/repository/deployment/server/webapps/authenticationendpoint/WEB-INF/web.xml as follows.
<filter>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<init-param>
<param-name>hstsEnabled</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>antiClickJackingOption</param-name>
<param-value>SAMEORIGIN</param-value>
</init-param>
</filter>
Btw, the error in the shared URL is Registered+callback+does+not+match+with+the+provided+url, you can check whether the redirect_uri defined in the request URL is matching with the one configured in the service provider.

Why in WSO2 ESB I can't create two different APIs having the same context value?

I am not so into WSO2 ESB and I have the following problem.
Into my ESB project I have 2 different APIs that have the same context but handling different URLs.
1) The first one is named CommoditiesInACountry and it is defined in this way:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/country" name="CommoditiesInACountry" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/{localizationId}/commodities">
..............................................................
..............................................................
..............................................................
2) The second one is named CommodityInLocationMarkets and it is defined in this way:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/country" name="CommodityInLocationMarkets" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/{localizationId}/commodity/{commodityId}">
..............................................................
..............................................................
..............................................................
So as you can see both have the same context having the value /country but the 2 APIs handle different URLs, infact the first one handle the resource .../country/{localizationId}/commodities and the second one handle the resouce .../country/{localizationId}/commodity/{commodityId}
the problem is that when I deploy my Carbon application I obtain the following error message related to the fact that I have 2 differents APIs having the same context value:
TID: [-1234] [] [2017-12-01 15:37:31,573] INFO {org.apache.synapse.rest.API} - Initializing API: CommodityInLocationMarkets {org.apache.synapse.rest.API}
TID: [-1234] [] [2017-12-01 15:37:31,573] ERROR {org.apache.synapse.config.SynapseConfiguration} - URL context: /country is already registered with the API: CommoditiesInACountry {org.apache.synapse.config.SynapseConfiguration}
TID: [-1234] [] [2017-12-01 15:37:31,573] ERROR {org.wso2.carbon.rest.api.ApiDeployer} - API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed. {org.wso2.carbon.rest.api.ApiDeployer}
org.apache.synapse.SynapseException: URL context: /country is already registered with the API: CommoditiesInACountry
at org.apache.synapse.config.SynapseConfiguration.handleException(SynapseConfiguration.java:1629)
at org.apache.synapse.config.SynapseConfiguration.addAPI(SynapseConfiguration.java:407)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:59)
at org.wso2.carbon.rest.api.ApiDeployer.deploySynapseArtifact(ApiDeployer.java:34)
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:194)
at org.wso2.carbon.application.deployer.synapse.SynapseAppDeployer.deployArtifacts(SynapseAppDeployer.java:131)
at org.wso2.carbon.application.deployer.internal.ApplicationManager.deployCarbonApp(ApplicationManager.java:272)
at org.wso2.carbon.application.deployer.CappAxis2Deployer.deploy(CappAxis2Deployer.java:72)
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136)
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807)
at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144)
at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377)
at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254)
at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371)
at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59)
at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:93)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
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)
TID: [-1234] [] [2017-12-01 15:37:31,574] ERROR {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer} - Deployment of the Synapse Artifact from file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed! {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer}
org.apache.synapse.deployers.SynapseArtifactDeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.handleSynapseArtifactDeploymentError(AbstractSynapseArtifactDeployer.java:474)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:71)
at org.wso2.carbon.rest.api.ApiDeployer.deploySynapseArtifact(ApiDeployer.java:34)
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:194)
at org.wso2.carbon.application.deployer.synapse.SynapseAppDeployer.deployArtifacts(SynapseAppDeployer.java:131)
at org.wso2.carbon.application.deployer.internal.ApplicationManager.deployCarbonApp(ApplicationManager.java:272)
at org.wso2.carbon.application.deployer.CappAxis2Deployer.deploy(CappAxis2Deployer.java:72)
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136)
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807)
at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144)
at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377)
at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254)
at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371)
at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59)
at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:93)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
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.apache.synapse.SynapseException: URL context: /country is already registered with the API: CommoditiesInACountry
at org.apache.synapse.config.SynapseConfiguration.handleException(SynapseConfiguration.java:1629)
at org.apache.synapse.config.SynapseConfiguration.addAPI(SynapseConfiguration.java:407)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:59)
... 22 more
TID: [-1234] [] [2017-12-01 15:37:31,576] INFO {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer} - The file has been backed up into : NO_BACKUP_ON_WORKER.INFO {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer}
TID: [-1234] [] [2017-12-01 15:37:31,576] ERROR {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer} - Deployment of synapse artifact failed. Error reading /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed. {org.apache.synapse.deployers.AbstractSynapseArtifactDeployer}
org.apache.axis2.deployment.DeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:201)
at org.wso2.carbon.application.deployer.synapse.SynapseAppDeployer.deployArtifacts(SynapseAppDeployer.java:131)
at org.wso2.carbon.application.deployer.internal.ApplicationManager.deployCarbonApp(ApplicationManager.java:272)
at org.wso2.carbon.application.deployer.CappAxis2Deployer.deploy(CappAxis2Deployer.java:72)
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136)
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807)
at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144)
at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377)
at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254)
at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371)
at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59)
at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:93)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
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.apache.synapse.deployers.SynapseArtifactDeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.handleSynapseArtifactDeploymentError(AbstractSynapseArtifactDeployer.java:474)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:71)
at org.wso2.carbon.rest.api.ApiDeployer.deploySynapseArtifact(ApiDeployer.java:34)
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:194)
... 20 more
Caused by: org.apache.synapse.SynapseException: URL context: /country is already registered with the API: CommoditiesInACountry
at org.apache.synapse.config.SynapseConfiguration.handleException(SynapseConfiguration.java:1629)
at org.apache.synapse.config.SynapseConfiguration.addAPI(SynapseConfiguration.java:407)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:59)
... 22 more
TID: [-1234] [] [2017-12-01 15:37:31,577] ERROR {org.wso2.carbon.application.deployer.internal.ApplicationManager} - Error occurred while deploying Carbon Application {org.wso2.carbon.application.deployer.internal.ApplicationManager}
org.apache.axis2.deployment.DeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:213)
at org.wso2.carbon.application.deployer.synapse.SynapseAppDeployer.deployArtifacts(SynapseAppDeployer.java:131)
at org.wso2.carbon.application.deployer.internal.ApplicationManager.deployCarbonApp(ApplicationManager.java:272)
at org.wso2.carbon.application.deployer.CappAxis2Deployer.deploy(CappAxis2Deployer.java:72)
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136)
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807)
at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144)
at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377)
at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254)
at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371)
at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59)
at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:93)
at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
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.apache.axis2.deployment.DeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:201)
... 20 more
Caused by: org.apache.synapse.deployers.SynapseArtifactDeploymentException: API deployment from the file : /opt/wso2/wso2ei-6.1.1/wso2/tmp/carbonapps/-1234/1512139051333agrimarketprice-cap_1.0.0.car/CommodityInLocationMarkets_1.0.0/CommodityInLocationMarkets-1.0.0.xml : Failed.
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.handleSynapseArtifactDeploymentError(AbstractSynapseArtifactDeployer.java:474)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:71)
at org.wso2.carbon.rest.api.ApiDeployer.deploySynapseArtifact(ApiDeployer.java:34)
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(AbstractSynapseArtifactDeployer.java:194)
... 20 more
Caused by: org.apache.synapse.SynapseException: URL context: /country is already registered with the API: CommoditiesInACountry
at org.apache.synapse.config.SynapseConfiguration.handleException(SynapseConfiguration.java:1629)
at org.apache.synapse.config.SynapseConfiguration.addAPI(SynapseConfiguration.java:407)
at org.apache.synapse.deployers.APIDeployer.deploySynapseArtifact(APIDeployer.java:59)
Changing one of the 2 APIs context value it is correctly deployed on my Carbon server.
My problem is that I need that the URL of both these 2 APIs start with .../country that is defined by the context value.
How is it possible that WSO2 ESB don't allow to have the same context for two APIs? How can I create two different APIs both having an URL like: XXX.YYY.ZZZ.RRR/country/...
Is it possible do in using WSO2 ESB?
A possible solution (correct me if it is wrong) maybe could be have two different contect of my APIs and then map it into WSO2 API MANAGER defining here the final URL consumed by the final user.
What could be a solution?
ESB/APIM don't allow creating 2 APIs with the same context. But, you can use one API and have multiple resources like this.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/country" name="CommoditiesInACountry" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/{localizationId}/commodities">
................................
................................
</resource>
<resource methods="GET" uri-template="/{localizationId}/commodity/{commodityId}">
................................
................................
</resource>
</api>
On a related note: To adhere to REST standards, your second resource should be /{localizationId}/commodities/{commodityId}

Security constraint causes 404

I'm trying to secure part of my Resteasy rest services by adding Keycloak bearer-only token verification to my webapp.
In my web.xml I added:
<security-constraint>
<web-resource-collection>
<web-resource-name>RestService</web-resource-name>
<url-pattern>/rest/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>RestService</realm-name>
</login-config>
<security-role>
<role-name>user</role-name>
</security-role>
<servlet>
<servlet-name>RestApplication</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.web.rest.ResteasyApplication</param-value>
</init-param>
<init-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RestApplication</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I'm calling the url: http://localhost:8090/rest/app
This does work as far as authentication goes. Only requests with a valid token will get 'accepted' (others will result in a 401 error)
However, when I use this configuration, I always get a 404 error.
When I disable the security-constraint, the Resteasy controller hits the breakpoint and everything is fine.
Do the mappings conflict with each other? How do I pass the request from the authentication phase to the Resteasy processing?
In your <login-config> use <auth-method>KEYCLOAK</auth-method> instead of BASIC