You'd have to create your realm implementation by extending JNDIRealm. Then you could grab the request (in either the hasUserDataPermission or hasResourcePermission methods), from which it should be possible to get all request parameters (assuming that "domain name" is a parameter passed in from the login form).
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: submit parameters other than j_username & j_password