How to use https in play framework? - scala

when I use https in play framework it shows like this
WARN akka.actor.ActorSystemImpl akka.actor.ActorSystemImpl(play-dev-mode) Illegal request, responding with status '400 Bad Request': Unsupported HTTP method: The HTTP method started with 0x16 rather than any known HTTP method from 127.0.0.1:45436. Perhaps this was an HTTPS request sent to an HTTP endpoint?
if anyone know how to use HTTPS in play framework,please explain the steps properly.
i can't clearly understad the documentation

instead of "sbt run" we need to use "sbt run -Dhttps.port=9443 -Dhttp.port=disabled"
and it runs in port number :9443

Related

How to get more information about Network Error on Axios?

I get the following error using Axios http client on my Expo Go App:
{"message":"Network
Error","name":"Error","stack":"createError#http://192.168.0.77:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:313278:26\nhandleError#http://192.168.0.77:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:312858:27\ndispatchEvent#http://192.168.0.77:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:33492:31\nsetReadyState#http://192.168.0.77:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:32592:33\n__didCompleteResponse#http://192.168.0.77:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:32370:29\nemit#http://192.168.0.77:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:2744:42\n__callFunction#http://192.168.0.77:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:23976:36\nhttp://192.168.0.77:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:23704:31\n__guard#http://192.168.0.77:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:23930:15\ncallFunctionReturnFlushedQueue#http://192.168.0.77:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:23703:21\ncallFunctionReturnFlushedQueue#[native
code]","config":{"url":"https://my-api-service.com/v1/auth/login","method":"post","data":"{"identifier":"test#gmail.com","password":"123456"}","headers":{"Accept":"application/json,
text/plain,
/","Content-Type":"application/json","Access-Control-Allow-Origin":"*"},"transformRequest":[null],"transformResponse":[null],"timeout":0,"responseType":"json","xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false}}}
This doesn't tell me much, how can I find out more information about what caused the error?

Keycloak is stripping the port from my redirect_uri in the Location header. Why?

I have the following allowed redirect uri set for my client: exp://192.168.2.212:19000
After a code exchange using the following URL:
GET /auth/realms/xxxxx/protocol/openid-connect/auth?code_challenge=m71Cl...D4hw&redirect_uri=exp%3A%2F%2F192.168.2.212%3A19000&client_id=3B03...
X-Forwarded-For: 178.84.x.x
X-Forwarded-Host: oidc.production.my.domain.com
X-Forwarded-Port: 443
X-Forwarded-Proto: https
X-Forwarded-Server: 09918a799a23
X-Real-Ip: 178.84.x.x
I get a HTTP/1.1 302 Found with the following Location field:
Location: exp://192.168.2.212?state=T0pvzPyHF6&session_state=b1cf16ad-b.....
The port is missing. My (Expo) client in android emulator then barfs about not being able to connect to 192.168.2.212 port 80. Naturally.
I am using the docker hub images 11.0.0
How can I prevent this? Is it a bug?
(The iOS version of my app uses a different redirect_uri (exp://127.0.0.1:19000), but although Keycloak strips the port there as well and it receives a Location: exp://127.0.0.1?state=T0p... it does connect to port 19000 and works fine for some reason.)
EDIT: Note that authentication works fine on iOS, and I run exactly the same Keycloak settings in iOS as Android (It's a React Native application).
Keycloak logs no error, and the following debug message:
13:24:33,365 DEBUG [org.keycloak.events] (default task-47) type=LOGIN, realmId=neemop, clientId=3B03FD35, userId=28619cd3-c51d-4756-9d06-fb47********, ipAddress=178.84.x.x, auth_method=openid-connect, auth_type=code, response_type=code, redirect_uri=exp://192.168.2.212:19000, consent=no_consent_required, code_id=a0faa4d4-6826-4c2f-9243-*******, response_mode=query, username=ron.arts#mydomain.com, authSessionParentId=a0faa4d4-6826-4c2f-9243-*******, authSessionTabId=-Pn******
shows the redirect_uri is parsed correctly. It's just that in the actual HTTP response the Location: header omits the port. Which imho should not happen.
Seems like a bug: https://issues.redhat.com/browse/KEYCLOAK-9405?_sscc=t
Tested on 12.0.4 and it still occurs. It appears to be an issue with any non-http(s) protocol
another bug has been submitted to keycloak team:
https://issues.redhat.com/browse/KEYCLOAK-17141
a fix is available in keycloak version >= 13.0.0

Disable SSL security in akka http client

I have to make https calls to an api that appears to not have validated SSL certificate. I would still like to make calls to the api using the Http().singleRequest method of akka-http.
When I make a call, I however get the following error:
javax.net.ssl.SSLHandshakeException: General SSLEngine problem
When I make a call with curl, I get
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it.
The calls with curl however work if I had the flag --insecure.
In akka-http, I tried the following:
val badSslConfig = AkkaSSLConfig().mapSettings(
s => s.withLoose(
s.loose
.withAcceptAnyCertificate(true)
.withAllowLegacyHelloMessages(Some(true))
.withAllowUnsafeRenegotiation(Some(true))
.withAllowWeakCiphers(true)
.withAllowWeakProtocols(true)
.withDisableHostnameVerification(true)
.withDisableSNI(true)
)
)
val badCtx = Http().createClientHttpsContext(badSslConfig)
Http()
.singleRequest(
HttpRequest(
HttpMethods.POST,
uri = Uri("https://..."),
protocol = HttpProtocols.`HTTP/1.1`
),
connectionContext = badCtx
)
but I still get the same error.
What should I do to fix the issue?
PS: I understand (given the many warnings in akka-http docs) that it is something that I shouldn't do in production but I'd like this workaround to work for now...
I had similar problem some time ago and as far as I remember it had to do with this issue. Workaround for that problem is to have own implementation of SSLContext that will accept just anything. Implementation is pretty straightforward and the example can be found in the last comment of of issue linked above.

Request is missing required `Host` header error in Scala Play 2.6.7 Akka

In production mode, the server failed to start and keeps print the following log. I cannot access the web pages. But the code runs fine in development mode. How to resolve the problem?
2017-11-23T10:04:07+08 [INFO] from play.core.server.AkkaHttpServer [main]
Listening for HTTP on /0:0:0:0:0:0:0:0:9000
2017-11-23T10:04:08+08 [WARN] from akka.actor.ActorSystemImpl [application-akka.actor.default-dispatcher-4]
Illegal request, responding with status '400 Bad Request': Request is
missing required `Host` header: Cannot establish effective URI of request
to `/`, request has a relative URI and is missing a `Host` header;
consider setting `akka.http.server.default-host-header`
2017-11-23T10:04:08+08 [WARN] from akka.actor.ActorSystemImpl [application-akka.actor.default-dispatcher-3]
Illegal request, responding with status '400 Bad Request': Request is
missing required `Host` header: Cannot establish effective URI of request
to `/`, request has a relative URI and is missing a `Host` header;
consider setting `akka.http.server.default-host-header`
the haproxy server health check did not send the Host header to the server
haproxy httpchk should be modified as this
option httpchk GET / HTTP/1.1\r\nHost:localhost
Depending on your HAProxy version the supported syntax might vary. This appears to be working with HAProxy 2.0.x
option httpchk GET /health
http-check send hdr Host localhost
Make sure to check the documentation for you version.

SoapUI endpoint error randomly

I don't understand something about SoapUI and his mockservice's behaviour.
I'm using the client of SoapUI (testcase) and a Java EE application with JAX-RPC.
My problem is :
when I'm trying to call any webservice, from my Java Client, or the testcase of SoapUI, the mockservice return a well message at first call, and the error below at the second call, with the same call or not.
But if I'm waiting, It works ...
So, I have enabled the option in SOAPui : "close HTTP connection after each SOAP request" and it works all the time...
So my question is :
"Is it a normal behaviour of the mockservice, and how to implement this with my java client ?"
Thank you all.
<soapenv:Fault>
<faultcode>Server</faultcode>
<faultstring>Missing operation for soapAction [] and body element [null] with SOAP Version [SOAP 1.1]</faultstring>
</soapenv:Fault>
OK,
I found a solution on the forum of SoapUI : http://www.soapui.org/forum/viewtopic.php?t=5648
It is when you have the settings flag "HTTP Settings/Logs wire content of all mock requests" set to true.
=> Uncheck the flag and it works fine!
Thanks a lot !
I had the same problem, using SoapUI 5.1.2 Pro.
After receiving first asynchronous response to the MockService, the MockService
stopped and could not receive any more responses for the request I sent.
The error message was:
Thu Jul 02 12:59:44 CEST 2015:ERROR:An error occurred [Missing operation for soapAction [XXXX] and body element [null] with SOAP Version [SOAP 1.1]], see error log for details
In SoapUI Settings:
File->Preferences->Http Settings: "Enable Mock HTTP log", uncheck box:
"Logs wire content of all mock requests".
Now I receive several asynchronous responses in a row, and give response back on them.
The same problem may happen when two mock services run with the same endpoint address (including port and path) on SoapUI.