Hello,
My web application has the notion of agents and clients. Clients "belong" to an agent (and only one agent). Agents are the main users of the application as far as I am concerned and logon "normally". Clients will login via a special URL that is specific to the agent and may contain logos, etc for that agent.
There are separate database tables for AGENT and CLIENT, both with username and password:
Note that the agent's username is unique across all agents and the client's username is unique across all clients. This allows the possibility of a client to have the same username as an agent, and why not?Code:CREATE TABLE AGENT ( AGENT_ID INT NOT NULL AUTO_INCREMENT, USERNAME VARCHAR(20) NOT NULL, PASSWORD VARCHAR(32) NOT NULL, PRIMARY KEY(AGENT_ID), UNIQUE KEY `USERNAME` (`USERNAME`), ); CREATE TABLE CLIENT ( CLIENT_ID INT NOT NULL AUTO_INCREMENT, USERNAME VARCHAR(20) NOT NULL, PASSWORD VARCHAR(32) NOT NULL, PRIMARY KEY(CLIENT_ID), UNIQUE KEY `USERNAME` (`USERNAME`) );
I have the authentication/authorisation for agents all nicely working. Now I want to do the same for clients. This is where I'm not exactly sure how to proceed!
My UserDetailsService implementation has the agentDAO dependency injected. The loadUserByUsername() asks the agentDAO to find by username. I could add the clientDAO in here also and call clientDAO.findByUsername() if (and only if) the agentDAO lookup failed. This doesn't seem right though because if the client has the same username as an agent, the agent will be found first.
The other way I thought about doing it was to have one database table to store the username/password for agents and clients. This would mean usernames have to be unique for both fundamental types of users but that's perhaps not a major issue. It would also mean some strange linking in the database to link back from the USERNAME_PASSWORD table to the AGENT or CLIENT table. It seems far better to have the credentials in the respective AGENT or CLIENT tables.
Perhaps this could be solved with multiple authentication providers or user details services?
Please help!
Thanks,
PUK



