在Embedded Tomcat Realm中配置多个用户

时间:2013-05-08 08:43:49

标签: java embedded-tomcat-7

我想在我的领域支持多个用户 怎么办呢?

1 个答案:

答案 0 :(得分:0)

以下方法应覆盖如下:

    @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
    }