I\'m writing a java web application which need to perform login through a webservice. Of course, none of the realms supplied with the application server I\'m using (glassfish v2
Check out Sun's article on this subject.
I never actually did this myself, but I'm pretty confident each AS gives you an option to register new realms (security domains) on it.
It probably won't be 100% portable, and for each AS you might need a different config XML, but basically, there is no reason for the code to be any different.