web.xml - How do I provide basic http authentication for static tomcat webapps without changing tomcat-users.xml? -


i have access tomcat manager , can upload war-files. 1 of these wars static web project (zipped html + media files, renamed *.war). want add web-inf/web.xml file war protect content basic http auth.

i know how adding global users , assigning roles in tomcat-users.xml, want have usernames , passwords defined in war-file.

  1. can done without touching tomcat's tomcat-users.xml?
  2. and if yes, how specify in static project's web.xml?

thx, juve

i found solution here: http://wiki.metawerx.net/wiki/securingyoursitewithcontainermanagedsecurity

the page describes how define own meta-inf/context.xml pointing own web-inf/users.xml. unfortunately, link users.xml file has absolute, , not want make assumptions on os/filesystem paths in config files.

here current web-inf/web.xml:

<?xml version="1.0" encoding="iso-8859-1"?> <web-app     xmlns="http://java.sun.com/xml/ns/j2ee"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"     version="2.5">      <display-name>supercooltool</display-name>     <description>what awesome app!</description>      <security-role>         <role-name>manager</role-name>     </security-role>     <security-role>         <role-name>keyuser</role-name>     </security-role>      <security-constraint>         <web-resource-collection>             <web-resource-name>                 entire application             </web-resource-name>             <url-pattern>/*</url-pattern>         </web-resource-collection>         <auth-constraint>             <role-name>keyuser</role-name>             <role-name>manager</role-name>         </auth-constraint>     </security-constraint>      <login-config>         <auth-method>basic</auth-method>         <realm-name>evaluation area</realm-name>     </login-config>  </web-app>  

an matching meta-inf/context.xml this:

<?xml version="1.0" encoding="utf-8"?> <context>     <realm classname="org.apache.catalina.realm.memoryrealm"            pathname="[path-to-your-webapp]/web-inf/users.xml"/> </context> 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -