spring-security-redirect problem with facesContext.externalContext.requestServle

Splash Forums Rewrite Users spring-security-redirect problem with facesContext.externalContext.requestServle

This topic contains 15 replies, has 3 voices, and was last updated by  Lincoln Baxter III 5 years, 10 months ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #18105

    Serkan Durusoy
    Participant

    Hi,

    I have a problem and I guess it is very trivial, although I am kind of clueless.

    I have:

    <br />
    <url-mapping id="productDetail" ><br />
    <pattern value="/products/#{slug}"></pattern><br />
    <view-id>/product/details.xhtml</view-id><br />
    </url-mapping><br />

    in my pretty-config.xml

    And I have a login form for spring security, just like the one below:

    <br />
    <form id="loginForm" method="post"<br />
    action="#{facesContext.externalContext.requestContextPath}/j_spring_security_check?spring-security-redirect=#{facesContext.externalContext.requestServletPath}"><br />
    <input type="text" name="j_username"/><br />
    <input type="password" name="j_password"/><br />
    <button type="submit">login</button><br />
    </form><br />

    My problem is, when I am on a page like:

    http://mydomain/myapp/products/some-product-slug

    The EL #{facesContext.externalContext.requestServletPath} resolves to /product/details.xhtml instead of /products/some-product-slug

    Is there a way I can “prettify” this link generated by the EL?

    Thanks,

    Serkan

    EDIT: I intended to post this on the prettyfaces forum but instead posted on the rewrite forum. It seems I cannot revert this nor delete this post to repost on the correct one. Sorry :(

    #21738

    Serkan Durusoy
    Participant

    And by the way, I cannot use pretty:urlbuffer here because this form is included in all the pages, therefore the mappingId can be different for different requests.

    #21739

    Hey Serkan,

    sorry, but I don’t know much about Spring Security because I never used it. But Spring Security has been a topic quite often in the PrettyFaces forums. I would suggest do have a look at these threads because most of them were solved.

    I also remember that there is at least one blog post regarding Spring Security on ocpsoft.com that Lincoln wrote some time ago. Perhaps this contains useful information too.

    I hope this helps a bit.

    Christian

    #21740

    Serkan Durusoy
    Participant

    Hi Christian,

    Please forget about spring security there for a moment.

    My main concern is to obtain the current (prettified) url of the page from within a code fragment that is included in all of the pages.

    I tried using pretty:urlbuffer, but it requires you to know the view id and parameters of the current page.

    So as I explained in the original post, the EL #{facesContext.externalContext.requestServletPath} resolves to the physical url, what I want is an expression or method to obtain the prettified url.

    #21741

    Oh, sorry! I misunderstood your post.

    This should be very easy. You can use the PrettyContext to access the original URL:

    String url = PrettyContext.getCurrentInstance().getRequestURL().toURL()

    But this URL won’t include the query parameters. But if I remember correctly there is a method in PrettyContext that returns the query parameters too.

    Does this fit your needs?

    Christian

    #21742

    Serkan Durusoy
    Participant

    Hi Christian,

    I think that is what I’m looking for.

    I have a few follow up questions though:

    1) What happens for my pages which are not defined in pretty-config.xml? What url does this return in those cases?

    2) The prettified url’s are in the form of some/path/param1/param2, does this mean the returned url using this method does not return param1 and param2 or by query parameters, do you mean the extraparam1 in some/path/param1/param2?extraparam1=somevalue

    Thank you very much

    #21743

    Hey Serkan,

    1) As far as I know this method always returns the original URL that was received by the servlet container. If the URL is mapped or not doesn’t matter.

    2) The URL will contain all path parameters. The only part that is missing is the query string (Everything after the ?). So in your example only extraparam1 will be missing.

    I hope this clears up the situation! :)

    Christian

    #21744

    Serkan Durusoy
    Participant

    Hi Christian,

    In this case, this is exactly what I am looking for.

    Thank you very much.

    One very last question, is it possible that I use a variant of:

    PrettyContext.getCurrentInstance().getRequestURL().toURL()

    directly in an el expression on the page, something like #{PrettyContext.xxxxx} ?

    #21745

    I don’t think there is a way to access this method directly from the expression language because there is a static method involved. I think you will have to create a small bean encapsulating this call yourself! :)

    #21746

    Serkan Durusoy
    Participant

    Alright, that’s what I thought, but wanted to ask nontheless.

    Thank you very much, I appreciate your help.

    #21747

    You’re welcome! :)

    #21748

    Actually, you can access the current PrettyContext from EL using:

    #{prettyContext.getRequestURL().toURL()}

    or if you are using an old version of EL:

    #{prettyContext.requestURL}

    should also work.

    #21749

    Oh, i didn’t know that. How do we do it? Why is prettyContext defined in the EL context?

    #21750

    Simply setting the value in the request attributes map is enough to register it for use in EL. I believe we do this, but I haven’t had time to check to make sure.

    This used to be the case. I believe it still should be but I’m not sure.

    #21751

    Serkan Durusoy
    Participant

    Hi,

    Thanks, the EL is what we used in the end.

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.

Comments are closed.