Passing additional parameters to j_security_check

1.6k Views Asked by At

In our application we need to let user select the desired datasource when logging in with form-based authentication, and I'm not sure if it's at all possible when using standard form-based authentication. I heard it was possible using TextInputCallback, but have no idea how (and where) to implement it.

1

There are 1 best solutions below

2
On

In the web.xml there could be maximum one <login-config> tag. It means that you cannot use more than one realm in one web application. So, you need a more or less container specific solution.

In Tomcat there is a CombinedRealm which can uses other realms.

Realm implementation that contains one or more realms. Authentication is attempted for each realm in the order they were configured. If any realm authenticates the user then the authentication succeeds. When combining realms usernames should be unique across all combined realms.

Maybe it matches with your requirements. If not and users exist in more than one realm (with the same username) you could use prefixes. For example set "domain\myuser" as the username.

If you use nested JDBCRealms you could create a database view which contains the prefixed usernames (just concat the prefix with the username) and use this view as the user table.

Another approach is removing the prefix in a custom realm and call the container's JDBCRealm (or its other realms) but it needs some coding. Anyway, it shouldn't be too hard, already existed realms probably can be used with the delegate design pattern.