Iam using spring-security-core 3.1.1 in my grails 3.2.7 application. I have added the following code in my application.yml
server:
contextPath: /LGP
port: 9090
So the appcode LGP will be appended to my URL. eg: http://localhost:9090/LGP/home
But the problem is when i'm using the Projects tag, the URL is becoming http://localhost:9090/home , the app code (LGP) getting skipped from the URL.
Why this is happening?
For the time being i update the tag as Projects but this gives the URL only as
lgp/projects
the http://localhost:9090/ section is getting missed.
Why this is like this?
If you're linking to a controller use:
<g:link controller="projects">Projects</g:link>
If you're linking to e.g. a static resource use:
<g:link uri="/projects">Projects</g:link>
Related
We are running a service behind an nginx proxy so that:
http://service-post:8080/swagger-ui.html is routed to public address https://host.com/services/post/swagger-ui.html
Or to define from the other way:
When nginx receives request on https://host.com/services/post/swagger-ui.html, it strips the /services/post/ prefix and passes the request to the post service on /swagger-ui.html path.
Before setting up anything (with default SpringDoc configuration) I can correctly see the swagger docs on http://service-post:8080/swagger-ui.html.
To set the paths for the public address on host.com, I am using:
springdoc.api-docs.path: /services/post/api-docs
springdoc.swagger-ui.path: /services/post/swagger-ui.html
springdoc.swagger-ui.configUrl: /services/post/v3/api-docs/swagger-config
However it seems that this brakes it completely:
/swagger-ui.html, /api-docs and /v3/api-docs/swagger-config return 404 both for service-post:8080/* and https://host.com/services/post/*
Only thing that seems to work is https://host.com/services/post/swagger-ui/index.html which shows the petstore documentation.
We are not using Spring Boot, just Spring MVC of version 5.3.1.
So how do I set up to keep the handling of the original paths (eg. /api-docs), but performing the lookup on the prefixed path (/services/post/api-docs)?
In the end I completely ignore the default redirect:
swagger-ui.html -> `swagger-ui/index.html?url=/v3/api-docs
And implemented my own one:
docs -> swagger-ui/index.html?url=MY_PREFIX/v3/api-docs
This way I don't need to change anything and everything works with default settings.
It's all documented here:
https://springdoc.org/index.html#how-can-i-deploy-springdoc-openapi-ui-behind-a-reverse-proxy
If you are not using spring-boot, you can add the ForwardedHeaderFilter bean:
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/filter/ForwardedHeaderFilter.html
I'm using Angular2 Beta 14 and calling a URL with a "dot" in it leads to a 404 not found error from the lite server which is 2.2.0.
This is the URL I'm calling:
http://localhost:3000/confirmuser/token/eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjYsInVzZXJOYW1lIjoiYXNkZmFzQGNlZC5saSJ9.PMzNWp8mbUKbSAiOqhOqjhZUYNejXY3pIQueBkc8_2E
The router path in app.component.ts looks like this:
{path: '/confirmuser/token/:token', name: 'ConfirmUser', component: ConfirmUserComponent}
The Chrome console shows this:
Failed to load resource: the server responded with a status of 404 (Not Found)
Ant the Lite Server:
[1] 16.04.13 15:57:13 404 GET /confirmuser/token/eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjYsInVzZXJOYW1lIjoiYXNkZmFzQGNlZC5saSJ9.PMzNWp8mbUKbSAiOqhOqjhZUYNejXY3pIQueBkc8_2E
When ever I call the url without a "dot", the page gets loaded correctly.
My aim here is, to confirm a user sign up. He receives an email with an URL he has to confirm. Using a JWT in this (and other cases) is habit I've been using.
Now I doubt this is an Angular issue, I believe this is a lite server issue.
Anyone experience with this?
Thanks
I found a suitable workaround for this issue.
Basically I'm getting rid of the path parameter ":token" and replacing it by a query parameter
In the app.component.ts the new path now looks like this:
{path: '/confirmuser', name: 'ConfirmUser', component: ConfirmUserComponent}
An the URL like this:
http://localhost:3000/confirmuser?token=eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjYsInVzZXJOYW1lIjoiYXNkZmFzQGNlZC5saSJ9.PMzNWp8mbUKbSAiOqhOqjhZUYNejXY3pIQueBkc8_2E
In the component that handles this request I can continue to call route params as I was used to. So nothing to change there:
constructor(params: RouteParams){
this.token = params.get('token')
...
This question has been answered in https://stackoverflow.com/a/36283859/1465640#
But it can be summarized with dots doesn't work in urls unless you do some work on the lite-server config.
If you are using webpack then you need to change the config to make it working.
Please make the change in webpack dev server config file
historyApiFallback: {
disableDotRule: true
},
I am trying to integrate swagger with camel project
following this example https://github.com/smparekh/camel-example-servlet-rest-tomcat
How do i access swagger-ui using this example project ?
I delopyed the war file in tomcat.
and access http://localhost:8080/camel-example-servlet-rest-tomcat/api-docs i get this ...
{"apiVersion":"1.2.3","swaggerVersion":"1.2","apis":[{"path":"/user","description":"User rest service"}],"info":{"title":"User Services","description":"Camel Rest Example with Swagger that provides an User REST service"}}
BUT MY QUESTION IS - how do i access swagger-ui/index.html?
what is the exact URL to access swagger-UI?
You must copy the contents of the dist folder of swagger-ui into your project's webapp folder.
In index.html,
window.swaggerUi = new SwaggerUi({
url: "http://petstore.swagger.wordnik.com/api/api-docs",
dom_id: "swagger-ui-container",
you must replace url with this
http://localhost:8080/camel-example-servlet-rest-tomcat/api-docs
For details, Follow this link to integrate swagger-ui.
https://github.com/swagger-api/swagger-ui
You should use http://localhost:${port}/${contextPath}/swagger/index.html
http://localhost:8080/camel-example-servlet-rest-tomcat/{basepath}/dist/index.html if you have copied dist folder as is. If you have renamed dist folder, use the new name instead of dist. replace basepath with basepath you have configured in web.xml. The code snippet for that looks like this:
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>/rest</param-value>
</init-param>
To access swagger2 it is
http://localhost:${port}/${contextPath}/swagger-ui.html
These are your Swagger Docs:
{"apiVersion":"1.2.3","swaggerVersion":"1.2","apis":[{"path"...
Now you need Swagger-UI to consume them. You can install it anywhere. There is no hard requirement that you put Swagger-UI in your project. You just need to edit the index.html file to point to your docs path (the JSON output above.)
The following code works as expected on Grails 2.0.4 and Eclipse STS 3.2 using Eclipse's embedded tcServer 2.7 as the web container...
class TestController {
def service() {
println request.request.getRequestURL()
//render response here...
}
For a client request of http://svr1:8080/testapp/test/node1, the above code prints the full request URL, http://svr1:8080/testapp/test/node1.
We created a WAR and deployed it to Jetty 8.1.10, but found that request.request returns null, so the above code fails with a null pointer. We tried using request.getRequestURL() but it returns a URL containing grails dispatch syntax, so it does not match the original client request url which is what we need.
As a workaround, we manually constructed most of the URL using request.getServerName(), request.getServerPort(), and request.getContextPath(), giving http://svr1:8080/testapp, but that still leaves out the uri portion, /test/node1. We assume this problem may be attributed to Jetty's Servlet API implementation, but if that were the case surely someone else would have picked up on this before us.
Found a workaround that appears to work on tcServer and Jetty posted here. We construct the base URL manually, then use this utility to get the remaining portion.
In grails acegi plugin, you can specify the authenticationFailureUrl property in SecurityConfig.
Is there a way to get the url that caused the auth failure in the scope of the authenticationFailureUrl?
This is not as simple as just getting the request or looking on the params. If there is an auth failure, you get redirected to the authenticationFailureUrl, so the url on the request at that point is the authenticationFailureUrl, not the url that caused the auth failure.
Im my case, I set authenticationFailureUrl to be a controller method -- looking at everything in the debugger no solution is obvious to me....
Thanx in advance.
The SavedRequest representing the original request is stored as a session attribute with name specified by the constant DefaultSavedRequest.SPRING_SECURITY_SAVED_REQUEST_KEY (or AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY in pre-3.0 versions).
This may help for others working with Spring Security 3.0.0 . In SS 3.0.3
AbstractProcessingFilter is deprecated and there is no constant SPRING_SECURITY_SAVED_REQUEST_KEY in DefaultSavedRequest. So you can get this by:
SavedRequest savedRequest = (SavedRequest) session.getAttribute(WebAttributes.SAVED_REQUEST);
Reference :
Spring Security: How to get the initial target url