Topic
  • 1 reply
  • Latest Post - ‏2013-04-30T21:13:40Z by aclemons
aclemons
aclemons
2 Posts

Pinned topic HttpServletRequest.getServletPath() empty in WAB

‏2013-04-23T21:16:55Z |

I am deploying an EBA with a WAB (for this example Web-ContextPath: /mypath) on WebSphere 8.5 FP1. I use Spring Security http path expressions to protect the application.

Previously deploying with pax-web (with jetty) in a felix container, I could use path expressions like /mypath/admin/* or /mypath/public/*. The code in spring security uses:

    private String getRequestPath(HttpServletRequest request) {
        String url = request.getServletPath();

        if (request.getPathInfo() != null) {
            url += request.getPathInfo();
        }

        url = url.toLowerCase();

        return url;
    }

If I send a request for http://localhost:9080/mypath/admin/blibb, this method returns /admin/blibb on websphere, but /mypath/admin/blibb when using pax-web (jetty). The requires me to have different configurations for each environment. Is this expected behaviour? I googled around a bit and found some old postings talking about something similar, but none of the referenced documentation seems to do what I wanted. Is there a way to expose the servletpath on WebSphere as well?

  • aclemons
    aclemons
    2 Posts
    ACCEPTED ANSWER

    Re: HttpServletRequest.getServletPath() empty in WAB

    ‏2013-04-30T21:13:40Z  

    Just to follow up on my own post.

    I solved this by writing a RequestMatcher to use on WebSphere which does that same thing as AntPathRequestMatcher but instead of the code above it uses:

        private String getRequestPath(HttpServletRequest request) {
            String url = request.getContextPath();
    
            if (request.getPathInfo() != null) {
                url += request.getPathInfo();
            }
    
            url = url.toLowerCase();
    
            return url;
        }
    

     

    This gives me the full path on websphere and I don't need to maintain two sets for security expressions. I just include a switch in my spring context  to  choose the RequestMatcher depending on the deployment environment.

  • aclemons
    aclemons
    2 Posts

    Re: HttpServletRequest.getServletPath() empty in WAB

    ‏2013-04-30T21:13:40Z  

    Just to follow up on my own post.

    I solved this by writing a RequestMatcher to use on WebSphere which does that same thing as AntPathRequestMatcher but instead of the code above it uses:

        private String getRequestPath(HttpServletRequest request) {
            String url = request.getContextPath();
    
            if (request.getPathInfo() != null) {
                url += request.getPathInfo();
            }
    
            url = url.toLowerCase();
    
            return url;
        }
    

     

    This gives me the full path on websphere and I don't need to maintain two sets for security expressions. I just include a switch in my spring context  to  choose the RequestMatcher depending on the deployment environment.