Though the tomcat-docs gives most information, there are some pitfalls when using tomcats facilities for HTTP Auth in Digest mode including hashed passwords. Following is a list to avoid them (tested on tomcat 6.0.x).
JDBC Driver to classpath
Tomcat realm handling is container internal, therefore it is not enough to have jdbc-driver (e.g. mysql-connector-java-5.1.6.jar) in your application classpath. You have to explicit add it to the container classpath (e.g. TOMCAT_HOME/lib).
Configuration Snippets
Tomcat container config, which can appear as nested element inside <Engine>, <Host> or <Context> (e.g. TOMCAT_HOME/conf/context.xml):
...
<!-- database connection settings + enabling hashed passwords (MD5 sum style) -->
<Realm
className="org.apache.catalina.realm.JDBCRealm"
digest="MD5"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbcURL"
connectionName="dbUser"
connectionPassword="dbPwd"
userRoleTable="role_table"
userTable="user_table"
userNameCol="dbuser_column"
userCredCol="dbpwd_column"
roleNameCol="role_column"/>
...
Webapplication web.xml:
<web-app>
...
<security-constraint>
<web-resource-collection>
<web-resource-name>Secure area</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<!-- enabling HTTP Auth digest mode -->
<auth-method>DIGEST</auth-method>
<realm-name>your-realm</realm-name>
</login-config>
<!-- roles must be defined to be used in security-constraint -->
<security-role>
<description>Role sample</description>
<role-name>admin</role-name>
</security-role>
...
</web-app>
Password patterns
For HTTP Auth Digest tomcat expects a special cleartext pattern for the hashed password entry inside the database. Unfortunately the cleartext snippet is different from the one from Http Auth Basic (this took me some time to find out…).
Bash CLI samples for HTTP Auth password hashing (md5sum):
# Basic style (only the password without user or realm info is hashed)
echo -n password | md5sum
# Digest style ('your-realm' is entry from web.xml->login-config->realm-name)
echo -n username:your-realm:password | md5sum
Migration HTTP Auth Basic to Digest
As you saw above tomcats Auth Basic and Digest cleartext password patterns are different. Therefore just switching the entry of web.xml->login-config->auth-method from ‘BASIC’ to ‘DIGEST’ wouldn’t suffice. I recommend to completely create a new database column (e.g. passwords_digest) so the separation and transition-path between Basic and Digest style is more clear. In case you hashed the Basic passwords already further more you have to reset the user passwords (the nature of good hashes are that you practically cannot map back to cleartext).
Tags: Technologies/Tools
>December 13th, 2009 · No Comments
After all the decades of software development, and recently hyped trends (e.g. “programming in graphical diagrams”) plain text source code is still the most powerful way to build software systems. Regarding this a high degree of importance is readability and comprehension of source code. In fact you’re spending more time in reading as with writing code. Apart from improving the structure of the code itself (the refactoring concept plays a big role here) syntax highlighting is also very important to get a quick overview. Following gives an example how and why to tweak your editor defaults.
IDE defaults
Defaults from several IDEs or more simple text-editors are already giving big help, e.g. in showing keywords, instance fields or comments. Still in my view they can be tweaked, most of editors give options to extend things. Either they work with a graphical interface for changing settings (IDEs like IntelliJ, Eclipse etc.) or are working themselves with plain text highlighting configuration files (vim, krusader etc.). Your syntax highlighting toolbox contains text-decorations (like italic, underscored, bold) and coloring (foreground, background).
For my tweaks I used my favorite IDE IntelliJ, which offers many syntax highlighting options. Just checkout your editor and see what is possible.
Example BEFORE
Following annoyed me on the default settings:
- Could not instantly see parameters and variables
- No difference between local-vars and parameters
- Non-javadoc comments were too grey. I write comments to explain the ‘Why’ or a important block of a code statement. So comments should be better visible.
- Todo comments were blue. Blue is a too “friendly” color to me, whereas looking at todos should wake me up!
- Instance and static vars were colored the same though they have different semantics.
- I tend to use more smaller methods as one monster method. The default highlighting does not separate between method declarations and calls.
The BEFORE snippet:

Example AFTER
I changed settings to:
- Non-instance + static variables are blue now. Parameters should be handled with more care. (changing them side-effect the callee), so they are bold.
- Static and instance vars have different colors now (pink vs. violet).
- Comments have slight green background now.
- Todo flags have the signal-color orange
- Methods are underscored. Declarations are bold, calls are non-bold.
The AFTER snippet:

Tags: Uncategorized
>November 21st, 2009 · No Comments
One of firefox killer-features is the variety of add-ons. Following is an overview of the add-ons I use currently.
Vimperator
Vimperator is a real gem! Adds some vim (editor) feeling to the browser. Makes you faster, because nearly all mouse action can be supplemented with keyboard shortcuts. Also automates more complicated flows with macros. At start using vimperator can be somewhat annoying because pressing some keys do unexpected things, but investing time to get used to it pays off definetely.
Xmarks
Xmarks saves your bookmarks to a server and makes synchronization possible between different machines. Very handy if you are working from different computers. Most likely it could be replaced by upcoming firefox 4 which offers this functionality in its core.
Web Developer
Web Developer is a nice webdeveloper testing kit. Numerous things can be done like style/CSS testing, gathering meta-information of the page, handling cookies, finding broken images.
Firebug
Firebug is a perfect accompany to Webdeveloper for testing/analyzing websites. Offers JavaScript debugging, analyzing DOM tree, viewing CSS styleor watching HTTP calls and request/response contents. It is also plugin aware (see below).
Firecookie
Firecookie is an addon for firebug. Makes cookies handling (reading, deleting, editing) much easier as with Webdeveloper plugin.
YSlow
YSlow is an addon for firebug, which offers performance test for webapplications. Gives a good overview how your site performs and gives a summary in grade style (A-F). If it gives you bad grade, still question whether they are appropriate in your special case (e.g. YSlow moans about missing CDNs, but an usage of a CDN doesn’t always makes sense or you don’t have any control over certain included components).
Live HTTP Headers
Firebug offers good HTTP traffic tracking. But sometimes I also use Live HTTP Headers because you can filter tracking HTTP calls by URL and content-type, for HTTP POST you can set your own defined payload.
JSONView
When testing webapps, instead of using curl sometimes it is handy to fire a HTTP request directly through firefox. If doing so by default firefox makes problems and prompts to save json (Content-type: application/json) as a file to instead of just displaying the content inside the browser window. JSONView bypasses this and displays json content appropriately.
Tags: Technologies/Tools