0

I'm trying to secure my webapplication using tomcats security constraint. Therefore i added a folder "prot", I want to secure through the url-pattern in the web.xml. When I change the tag to <url-pattern>/prot</url-pattern> my login page doesn't appear, therefor the file i wanted to protect. Wehn I change the path to <url-pattern>/*</url-pattern> the page login-page appears, but without any javascript i defined in a separate file (which is blocked from tomcat?). On the context i added the path /mywebapp/prot. How do i secure the folder prot ? Thanks in advance!

1 Answer 1

2

You should secure by default and unsecure what you want.

The constraints must be declared from the most specific to the most generic in web.xml, so that you match the most specific first.

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Unsecure resources</web-resource-name>
        <url-pattern>/unsecure</url-pattern>
    </web-resource-collection>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Secure resources</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>authenticated</role-name>
    </auth-constraint>
</security-constraint>
Sign up to request clarification or add additional context in comments.

1 Comment

It is not-so-straight forward, that the mere existence of <auth-constraint> decides about security or not, but it does indeed make sense at a 2nd glance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.