How to use both database and LDAP authentication i

2019-07-26 02:16发布

问题:

We have a Spring MVC application. We now have to integrate spring security in it.

The authentication can be done using either database or using LDAP.

We will a have a configuration setting either in a properties file or a database to decide which authentication to use i.e. if the user should be authenticated against a database or a LDAP.

At any given time there will be only one type of authentication.

e.g. A company test1 can have a database authentication and another company test 2 can have ldap authentication.

回答1:

Some ideas:

  1. If each client is deployed separately with its own configuration, configure the DAO and LDAP authentication in 2 different XML files. At build time, choose which one you want to use and bundle it in your WAR.
  2. If there is only 1 WAR, maybe try including both XML files in the WAR, and set a system property using -Dmyprop=foo (o some other way) when starting up the app. Then, in your Spring config, include the appropriate config file using ${myprop} so that the correct file is called and used.