{"id":402,"date":"2003-05-24T21:59:45","date_gmt":"2003-05-25T01:59:45","guid":{"rendered":"http:\/\/wordpress.cephas.net\/?p=402"},"modified":"2003-05-24T21:59:45","modified_gmt":"2003-05-25T01:59:45","slug":"declarative-security-for-web-application","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2003\/05\/24\/declarative-security-for-web-application\/","title":{"rendered":"Declarative Security for Web Application"},"content":{"rendered":"<p>Catching up on the homework for the free <a href=\"http:\/\/www.javapassion.com\/j2ee\/Class.html#Class_5\">J2EE Programming Class<\/a> I&#8217;m taking, this week drills down into the security options offered by servlet containers, specifically Tomcat.  One of the things I hadn&#8217;t spent much time on before was the declarative security functionality that exists (apparently) in all servlet containers.  Unlike ColdFusion and ASP, servlet containers (and thus Tomcat) give system administrators (not the developer) the ability to create password protected directories, &#8216;realms&#8217; and users that access the directories within a specific realm.  All the administration is done within the web.xml file of your web application.  Here&#8217;s an example:<\/p>\n<p>&lt;web-app&gt;<br \/>\n&nbsp;&lt;!&#8211;&nbsp;&#8230;&nbsp;&#8211;&gt;<br \/>\n&nbsp;&lt;security-constraint&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&lt;web-resource-collection&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;web-resource-name&gt;Sensitive&lt;\/web-resource-name&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url-pattern&gt;\/sensitive\/*&lt;\/url-pattern&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&lt;\/web-resource-collection&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&lt;auth-constraint&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;role-name&gt;administrator&lt;\/role-name&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;role-name&gt;executive&lt;\/role-name&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&lt;\/auth-constraint&gt;<br \/>\n&nbsp;&lt;\/security-constraint&gt;<br \/>\n&nbsp;&lt;login-config&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;auth-method&gt;FORM&lt;\/auth-method&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;form-login-config&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;form-login-page&gt;\/login.jsp&lt;\/form-login-page&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;form-error-page&gt;\/login-error.html&lt;\/form-error-page&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/form-login-config&gt;<br \/>\n&nbsp;&lt;\/login-config&gt;<br \/>\n&nbsp;&lt;!&#8211;&nbsp;&#8230;&nbsp;&#8211;&gt;<br \/>\n&lt;\/web-app&gt;<\/p>\n<p>The above locks down the &#8216;\/sensitive\/&#8217; directory (and everything inside it) to users in the administrative and executive realms and forces anyone and everyone trying to access said directory to login using \/login.jsp.  <\/p>\n<p>Couple benefits that I see to this idea of declarative (rather than programmatic) security:<\/p>\n<p>a) administration chores are handled by system administrators, no developer intervention is required outside of setting up the login pages.<\/p>\n<p>b) According to this <a href=\"http:\/\/www.cafesoft.com\/products\/cams\/tomcat-security.html\">article<\/a>, &#8220;<i>.. J2EE compliant servlet containers are required to track authentication information at the container level (rather than at the web application level)<\/i>&#8221; which means that if you setup multiple websites on a J2EE compliant servlet container, you get single sign on to all the applications running on that servlet container.  Very cool.<\/p>\n<p>c) Very little coding is required of programmers, giving them more time to focus on the applications they&#8217;re building, this also means fewer bugs.<\/p>\n<p>Interested in reading more?<\/p>\n<p>Declarative Web Application Security with Servlets and JSP: <a href=\"http:\/\/www.informit.com\/isapi\/product_id~%7B116C8D3F-BE60-47A3-B8EC-EF132654A5A3%7D\/content\/index.asp\">http:\/\/www.informit.com\/isapi\/product_id~%7B116C8D3F-BE60-47A3-B8EC-EF132654A5A3%7D\/content\/index.asp<\/a><\/p>\n<p>Tomcat 4 Servlet\/JSP Container Realm Configuration: <a href=\"http:\/\/jakarta.apache.org\/tomcat\/tomcat-4.1-doc\/realm-howto.html\">http:\/\/jakarta.apache.org\/tomcat\/tomcat-4.1-doc\/realm-howto.html<\/a><\/p>\n<p>Tomcat 4 Single Sign On: <a href=\"http:\/\/jakarta.apache.org\/tomcat\/tomcat-4.1-doc\/config\/host.html\">http:\/\/jakarta.apache.org\/tomcat\/tomcat-4.1-doc\/config\/host.html<\/a><\/p>\n<p>JRUN Security (no mention of any declarative security functionality): <a href=\"http:\/\/livedocs.macromedia.com\/jrun4docs\/JRun_Administrators_Guide\/authentic.jsp\">http:\/\/livedocs.macromedia.com\/jrun4docs\/JRun_Administrators_Guide\/authentic.jsp<\/a><\/p>\n<p>The JavaTM Web Services Tutorial: Web-Tier Security: <a href=\"http:\/\/java.sun.com\/webservices\/docs\/1.0\/tutorial\/doc\/WebAppSecurity4.html\">http:\/\/java.sun.com\/webservices\/docs\/1.0\/tutorial\/doc\/WebAppSecurity4.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Catching up on the homework for the free J2EE Programming Class I&#8217;m taking, this week drills down into the security options offered by servlet containers, specifically Tomcat. One of the things I hadn&#8217;t spent much time on before was the declarative security functionality that exists (apparently) in all servlet containers. Unlike ColdFusion and ASP, servlet &hellip; <a href=\"https:\/\/cephas.net\/blog\/2003\/05\/24\/declarative-security-for-web-application\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Declarative Security for Web Application<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/402"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=402"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/402\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}