Search code examples
javaembedded-tomcat-7

Configuring more than one user in Embedded Tomcat Realm


I would like to support more than one user in my realm.
How can this be done?


Solution

  • The following methods should be override as follows:

        @Override
        protected String getPassword(String username)
        {
            if(username.equals(_firstUser))
                return _firstUserPassword;
            else if(username.equals(_secondUser))
                return _secondUserPassword;
            //etc with your other users
        }
    
        @Override
        protected Principal getPrincipal(String username)
        {
            if(username.equals(_firstUser))
            {
                return new GenericPrincipal(username, _firstUserPassword, _roles);
            }
            else if(username.equals(_secondUser)
            {
                return new GenericPrincipal(username, _secondUserPassword, _roles);
            }
            //etc with your other users
        }