LoginModule 接口有这个方法:
public void initialize(Subject subject, CallbackHandler callbackHandler,
Map<String, ?> sharedState, Map<String, ?> options);
我可以通过扩展配置将值传递给选项(第四个参数):
public class CustomConfiguration extends Configuration
{
private Map<String, ?> options;
private String loginModuleName;
public CustomConfiguration()
{
}
public CustomConfiguration(final String loginModuleName, final Map<String, ?> options)
{
this.loginModuleName = loginModuleName;
this.options = options;
}
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name)
{
AppConfigurationEntry entry = new AppConfigurationEntry(loginModuleName,
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
options);
return new AppConfigurationEntry[] { entry };
}
}
我正在尝试使用 LdapLoginModule。它使用 sharedState(第三个参数)值来获取用户名和密码(在 login() 中):
username = (String)sharedState.get(USERNAME_KEY);
password = (char[])sharedState.get(PASSWORD_KEY);
我的问题是,如何将值传递给 sharedState?