Enhanced Security Models in TOMCAT for Access Control
140 likes | 195 Vues
Learn about Declarative and Programmatic Security models, Role-based Authorization, and Authentication Methods in TOMCAT for better access control. Understand configuration tips and user role management. Access helpful APIs and tutorials.
Enhanced Security Models in TOMCAT for Access Control
E N D
Presentation Transcript
Access control 2/18/2009
TOMCAT Security Model • Declarative Security: • the expression of application security external to the application, and it allows runtime configuration • Configure in web.xml • Programmatic Security: • implement fine-grained access control, enabling components to become security aware • Involves using HttpServletRequest API method
Declarative Security • the expression of application security external to the application, and it allows runtime configuration • Configure in web.xml
Role-based Authorization • Use role-based authorization to manage access • Define role in /conf/tomcat-user.xml <tomcat-users> <role rolename="tomcat"/> <role rolename="role1"/> <role rolename="user"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user username="role1" password="tomcat" roles="role1"/> <user username="both" password="tomcat" roles="tomcat,role1"/> <user username="jerry" password="jerry" roles="user"/> </tomcat-users> *Need to restart TOMCAT after reconfiguration.
Role-based Authorization • Define security role in web.xml <security-role> <description>The role that is required to log in to the Manager Application </description> <role-name>user</role-name> </security-role> <security-constraint> <web-resource-collection> <url-pattern> /protected/* </url-pattern> </web-resource-collection> <auth-constraint> <role-name>user</role-name> </auth-constraint> </security-constraint>
Authentication Method – 1: Basic • Usage: • Pop up a dialog box • Browser-based auth • User & Password are sent in every http request • Must exit the browser to logout • Not secure at all (no encryption) • Configuration in web.xml <login-config> <auth-method>BASIC</auth-method> <realm-name>Tomcat Manager Application</realm-name> </login-config>
Authentication Method – 2: Digest • Usage: • Same as BASIC • Username and password are encrypted into a message digest value • Configuration in web.xml <login-config> <auth-method>DIGEST</auth-method> <realm-name>Tomcat Manager Application</realm-name> </login-config> Has to use a secure connection, such as SSL, etc
Authentication Method – 3: Form • Usage: • Define your own login and error page • Authentication is defined in servlet session • Logout by session.invalidate() • Configuration in web.xml <login-config> <auth-method>FORM</auth-method> <form-login-config> <form-login-page>/protected/login.jsp</form-login-page> <form-error-page>/protected/error.jsp</form-error-page> </form-login-config> </login-config>
Authentication Method – 3: Form • Must follow the rules • Use j_username field for the username • Use j_password field for the password • Submit to j_security_check • Login.jsp <form action='j_security_check' method='post'> Name:<input type='text' name='j_username'><br> Password:<input type='password' name='j_password' size='8'><br> <input type='submit' value='login'> </form> • Error.jsp <font size='4' color='red'> The username and password you supplied are not valid.</p> Click <a href='<%= response.encodeURL("login.jsp") %>'>here</a> to retry login
Authentication Method – 4: Client • Usage • implemented with SSL and requires the client to possess a public key certificate • Most secure, but costly
Programmatic Security • implement fine-grained access control, enabling components to become security aware • Involves using HttpServletRequest API method
Access authentication info. • getRemoteUser() • getAuthType() • isUserInRole() • getUserPrincipal() • Principal is an alternated object to identify user • show_security.jsp User principal: <%= request.getUserPrincipal().getName() %>.<br/> User name: <%= request.getRemoteUser() %>.<br/> Request Authenticated with: <%= request.getAuthType() %>.<br/> <% if(request.isUserInRole("user")) { %> You are in <i>user</i> role<br/> <% } %>
Use Role in Web App. Under Structs • Restricted access to Actions • <action path=“……" type= …… name=…… scope="request"roles="administrator"></action> • In JSP • <logic:present role="administrator"/> ……</logic:present>
Reference • Good security tutorial: http://www.informit.com/articles/article.aspx?p=24253 • Http servlet request APIs: http://www.caucho.com/resin-javadoc/javax/servlet/http/HttpServletRequest.html • http://www.java2s.com/Tutorial/Java/0400__Servlet/0440__Authentication.htm