Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set public urls on web.xml? #55

Closed
rodvlopes opened this issue Mar 22, 2013 · 3 comments
Closed

how to set public urls on web.xml? #55

rodvlopes opened this issue Mar 22, 2013 · 3 comments
Labels

Comments

@rodvlopes
Copy link

I've got a SecurityFilter set to /* pattern and I need to set the /public/* as a public path. How could it be done?

I can't use the valve approach with security-constraints.

I am following the example given with the waffle-filter project.

<filter>
        <filter-name>SecurityFilter</filter-name>
        <filter-class>waffle.servlet.NegotiateSecurityFilter</filter-class>
        <init-param>
            <param-name>principalFormat</param-name>
            <param-value>fqn</param-value>
        </init-param>
        <init-param>
            <param-name>roleFormat</param-name>
            <param-value>both</param-value>
        </init-param>
        <init-param>
            <param-name>allowGuestLogin</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>securityFilterProviders</param-name>
            <param-value>waffle.servlet.spi.NegotiateSecurityFilterProvider
waffle.servlet.spi.BasicSecurityFilterProvider</param-value>
        </init-param>
        <init-param>
            <param-name>waffle.servlet.spi.NegotiateSecurityFilterProvider/protocols</param-name>
            <param-value>NTLM
Negotiate</param-value>
        </init-param>
        <init-param>
            <param-name>waffle.servlet.spi.BasicSecurityFilterProvider/realm</param-name>
            <param-value>myrealm</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>SecurityFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
@dblock
Copy link
Collaborator

dblock commented Apr 9, 2013

Did you figure this one out? Bring it up on the mailing list?

@rodvlopes
Copy link
Author

Yes I did. I wrote a another filter that manages the public path.

   @Override
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        String contextPath = ((HttpServletRequest) request).getContextPath();
        String uri = ((HttpServletRequest) request).getRequestURI();
        String url = uri.substring(contextPath.length());

        if (isPulic(url)) {
            log("public - " + url);
            chain.doFilter(request, response);
        } 
        else {
            log("protected - " + url);
            securityFilter.doFilter(request, response, chain);   /*cat jump */
        }

    }


    @Override
    public void init(FilterConfig fConfig) throws ServletException {

        this.filterConfig = fConfig;
        this.publicPath = "^/(public|css|js|images|plugins).*";

        if (this.publicPath != null && this.publicPath.length() > 0)
            this.publicPathPattern = Pattern.compile(this.publicPath, Pattern.CASE_INSENSITIVE);
        else
            log("publicPath has to be set in web.xml");

        this.securityFilter = new NegotiateSecurityFilter();
        this.securityFilter.init(filterConfig);
    }

@dblock
Copy link
Collaborator

dblock commented Apr 10, 2013

Thanks, I'll close this. I'd appreciate an FAQ entry maybe on this if you have a moment to contribute one.

@dblock dblock closed this as completed Apr 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants