I have added swagger-ui on a spring boot 2.3.1 app, it works fine locally.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.3.9</version>
</dependency>
This application is deployed in a kubernetes cluster but it's not accessible (no ingress)
Instead we deployed another spring boot app that is accessible and can call this service.
API calls get redirected fine but swagger-ui does not work.
Basically, my proxy app is accessible like this :
https://app-dev.domain.io/proxy-service/v2/my-service/**
=> https://app-dev.domain.io/proxy-service/v2/my-service/swagger-ui.html
In my proxy service, I set the X-Forwarded headers like this :
X-Forwarded-Host = Host header (app-dev.domain.io)
X-Forwarded-Proto = https
X-Forwarded-Prefix = /proxy-service/v2/my-service/
I also set the header Accept-Encoding=identity
The proxy service then calls http://my-service inside the cluster
In MyService configuration I set :
server.forward-headers-strategy=framework
It seems to find static files, but i get javascript errors and a blank page :
Uncaught SyntaxError: Unexpected end of input
swagger-ui-standalone-preset.js:21 Uncaught SyntaxError: Invalid or unexpected token
index.html?configUrl=/proxy-service/v2/my-service/v3/api-docs/swagger-config:41 Uncaught ReferenceError: SwaggerUIBundle is not defined
at window.onload
From what I have searched, I did what was needed (headers-strategy in called service and X-Forwarded in proxy)
Any help would be awesome, as I would like for the services to be easily testable without maintaining a postman collection manually or something similar. ( always forgotten at some point )
Thanks
I have found out that the javascript files are getting truncated.
So the javascript errors make sense.
I'll try again after fixing this
Edit :
It is now working with the complete javascript files.
I used HttpURLConnection instead of RestTemplate which tuncates the files for no reason
Related
In Springboot application we are facing issue after authentication with AD and while doing redirection.
We have added the below redirection in application.properties file:
aad.redirectHomeUri=https://icaps-userhelpertool-dev-cloudrun-kwyk47pogq-ez.a.run.app/resetpassword
Above url is cloud run url where we have deployed our code and same url we have added in AD also . But after authentication its not redirecting and we are getting below error.
19-01-2023 10:08:07.259 ERROR c.m.a.m.ConfidentialClientApplication - [Correlation ID: b396dc37-982d-4f56-ac5d-a754f24f4f53] Execution of class com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier failed.
com.microsoft.aad.msal4j.MsalServiceException: AADSTS500112: The reply address 'http://icaps-userhelpertool-dev-cloudrun-kwyk47pogq-ez.a.run.app/resetpassword' does not match the reply address 'https://icaps-userhelpertool-dev-cloudrun-kwyk47pogq-ez.a.run.app/resetpassword' provided when requesting Authorization code.
I tried to reproduce the same in my environment
Received the error:
AADSTS50011: The redirect URI 'http://xxx/signin-oidc' specified in the request does not match the redirect URIs configured for the application '50065a5f-d3e4-426f-a4f4-1e6fbd2ed06e'. Make sure the redirect URI sent in the request matches one added to your application in the Azure portal.
This error occurred as in my code ,the http protocol it used is http But the one registered in portal is https .
This can be set properly with HttpsRedirection middleware configuration
In spring ,this occurs when your Tomcat server is behind a proxy which redirects to http protocol.
Set the below configurations in application.properties with the proper url in registered-redirect-uri and x-forwarded-proto as mentioned here spring-boot-application-with-azure-ad-throws-reply-url-does-not-match | StackOverflow
application.properties
security.oauth2.client.pre-established-redirect-uri=https://yourappurl.net/login
security.oauth2.client.registered-redirect-uri=https://yourappurl.net/login
security.oauth2.client.use-current-uri=false
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
server.tomcat.use-relative-redirects=true
server.use-forward-headers=true
server.tomcat.internal-proxies=.*
and Add server.forward-headers-strategy=native
Reference : spring-redirect-happening-to-http-login-instead-of-https-login | Stack Overflow
Related question:
Spring Boot Remove Whitelabel Error Page
For my case,
I disabled whitelabel by setting whitelabel.enabled = false, and I also exclude ErrorMvcAutoConfiguration. It worked in regular spring boot service. But I deployed the same service on PCF cloud foundry, then spring still want to redirect error to /error page.
Any help and suggestion is welcome.
Edit:
I added exclude annotation on Application, then it works on PCF.
Previously I added exclude configuration in application.yml, then it didn't work on PCF
You need to create a separate endpoint /error and then handle it in the method. I would suggest you to maintain a separate controller infact. My code would look something like this
#RestController
#RequestMapping(path = "/error")
public class ErrorController {
#ApiOperation(value = "Error Page", notes = "Error Page")
#GetMapping
public String error() {
return "Some Error Occurred and I will Graciously show the Error"
}
}
It turns out circuit breaker service set exclusion property first, than local application.yml didn't take effect. If I add exclusion property in repo, then it take preference.
I feel this is kind of spring bug, since exclusion is list, it should include all items, instead of taking the first configuration only.
I want to send https consumer request using camel-jetty component and that address returns some response in JSON format, below I mention my DSL code.
from("jetty:https://someSiteAddress.com/api/control/authorizeUser?username=__&password=__").to("stream:out");
I am getting this warning:
[WARNING]
java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0 (Native Method)
at sun.nio.ch.Net.bind (Net.java:433)
at sun.nio.ch.Net.bind (Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind
But whenever I hit this HTTP URL in browser it will execute perfectly with authentication.
If anyone knows what to do to perform this action in apache camel please help me it will be very cheerful for me and others.
And how could I know which method camel using for sending a request like POST or GET.
Thank You
Could you try this instead? I'll comment each line to help understand your problem.
// endpoint to start your route. could be a http endpoint you expose via jetty, jms, vm, seda or any other option. Here I'm using the simplest one.
from("direct:start")
// logs on
.to("log:DEBUG?showBody=true&showHeaders=true")
// consume the endpoint
.to("https://someSiteAddress.com/api/control/authorizeUser?username=__&password=__"")
// log the body to the console so you could process the response later knowing what to do (the token you are mentioning should be in here.
.to("log:DEBUG?showBody=true&showHeaders=true")
.to("stream:out") //or whatever you want to
Don't forget the camel-http dependency for this example to work:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
</dependency>
Cheers!
This is also working fine.
from("direct:in")
.to("https://www.someAddress.com/api/control /authorizeUser?username=__ &password=__")
.to("stream:out");
Thanks #RicardoZanini
Hi I am using spring data rest provided HAL browser to view my spring data rest HAL based api .So far things have been good when I am running it via eclipse or as a spring boot app for testing in my local .Though when I deploy on aws on a tomcat container (as a spring boot war) I get this weird error as below when I browse to the roor or the address of the hal browser /browser/index.html#
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Aug 24 07:05:46 UTC 2015
There was an unexpected error (type=Internal Server Error, status=500).
Jar URL cannot be resolved to absolute file path because it does not reside in the file system: war:jar:file:/deployment/wars/hfds.1.3.war!/WEB-INF/lib/spring-data-rest-hal-browser-2.4.0.BUILD-SNAPSHOT.jar
I am still not able to find a valid justification on why its not being able to find the provided hal browser though things work fine in local .Am I missing something can someone please help .Is this a bug with spring framework or otherwise
UPDATE
This seems to be an environment specific issue as in windows environmnet I get the url file:/.... whil ein linux I get war:jar:file which causes the issue due to this code section in org.springframework.util.ResourceUtils
public static File getFile(URL resourceUrl, String description) throws FileNotFoundException {
Assert.notNull(resourceUrl, "Resource URL must not be null");
if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) {
throw new FileNotFoundException(
description + " cannot be resolved to absolute file path " +
"because it does not reside in the file system: " + resourceUrl);
}
try {
return new File(toURI(resourceUrl).getSchemeSpecificPart());
}
catch (URISyntaxException ex) {
// Fallback for URLs that are not valid URIs (should hardly ever happen).
return new File(resourceUrl.getFile());
}
}
Hi so with the help of Andy finally figured out that the workaround is to set unpackwar to true to make the HAL browser work .Not sure this is a mandate yet so have raised an issue for spring boot at https://github.com/spring-projects/spring-boot/issues/3826 to look further .But as of now setting upackwar=true works just fine .
UPDATE
This has been fixed in the 4.2.2 and greater spring version via https://jira.spring.io/browse/SPR-13393
I have followed the steps given in the below site to create a simple spring boot application that access the facebook data using maven and spring boot.
http://spring.io/guides/gs/accessing-facebook/
which is also same as http://www.technicalkeeda.com/spring/spring-social-facebook-integration-example but in gradle.
The problem i am facing is when i am trying to run the application, I have am seeing that url is successfully redirected to "/connect/facebook" but it doesnt load the facebookConnect.html instead it throws error
as shown below:
"
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Mar 10 19:24:41 IST 2015
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported
"
I have also tried using the same code given in the site and also used my facebook appId and appSecret in it , which i had generated by giving a random host name in the facebook app, still i get same error.
I have also tried adding the random host name which i created to the /etc/hosts file in the windows.
Could anyone please help me why i am not able to see the .html page that has to be rendered by the ConnectController automatically ?
I finally got the answer.
it is we need to additional parameter in the application.properties file which is
"spring.social.auto_connection_views=true
along with the id and secret.
spring.social.facebook.appId=
spring.social.facebook.appSecret=
this property was not mentioned in the tutorials. finally this worked. :)
"
Had the exact same issue. spring.social.auto-connection-views: true in the application.yml (or .parameter equivalent) does indeed solve it, but then the default facebookConnect.html and facebookConnected.html are being used.
I solved it by removing the above application parameter and simply adding Thymeleaf tempting engine to the pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
And then you can use your own facebookConnect.html and facebookConnected.html located at src/main/resources/templates/connect/
Hope it can help.