Hi All,
I am implementing login component in which I want to support goto parameter for example
https://myDomain/login.html?goto=https://myDomain/securePage.html.
I am able to get the redirect path in my servlet from the query parameter but from query parameter how do i get the resource path? I was hoping resolve method might come handy but it does not seem to work :(. Anything more elegant that string manipulation to solve this problem?
final String gotoPath = xssApi.filterHTML(request.getParameter(gotoParam)); if (StringUtils.isNotEmpty(gotoPath)) { final Resource gotoPathResource = request.getResourceResolver().resolve(gotoPath); if (null != gotoPathResource && null != gotoPathResource.adaptTo(Page.class)) { response.sendRedirect(gotoPath); return; } }
Above code is giving resource as non existent
Thanks!
Shehjad
Solved! Go to Solution.
Views
Replies
Total Likes
I have changed code to below to make it work.
final String gotoPath = xssApi.filterHTML(request.getParameter(gotoParam)); final URI gotoUri = new URI(gotoPath, false); if (StringUtils.isNotEmpty(gotoPath)) { final Resource gotoPathResource = request.getResourceResolver().resolve(gotoUri.getPath()); if (null != gotoPathResource && null != gotoPathResource.adaptTo(Page.class)) { response.sendRedirect(gotoPath); return; } } redirect(request, response, redirectPath);
I'm assuming that you have some rewriting going on to handle the URL without /content/<path>/, so, you could simply take your go to parameter, strip out the https://<domain> and use what is left over (minus the .html)
So, https://www.mydomain.com/mypage.html would become "mypage", you know the content path, so prepend it and the string becomes /content/<path>/mypage and then get the resource.
Views
Replies
Total Likes
Asling Thanks for your reply, yes i understand i can do some string manipulation but I don't find that be a elegant way :)
Yes we have mapping to map short urls as you mentioned in your comment
Views
Replies
Total Likes
I have changed code to below to make it work.
final String gotoPath = xssApi.filterHTML(request.getParameter(gotoParam)); final URI gotoUri = new URI(gotoPath, false); if (StringUtils.isNotEmpty(gotoPath)) { final Resource gotoPathResource = request.getResourceResolver().resolve(gotoUri.getPath()); if (null != gotoPathResource && null != gotoPathResource.adaptTo(Page.class)) { response.sendRedirect(gotoPath); return; } } redirect(request, response, redirectPath);