java.lang.Object
com.sun.security.auth.module.JndiLoginModule
- 所有已实现的接口:
LoginModule
该模块提示输入用户名和密码,然后根据 JNDI 下配置的目录服务中存储的密码验证密码。
此 LoginModule
可与任何符合 JNDI 的服务提供者互操作。要指示此 LoginModule
使用特定的 JNDI 服务提供者,必须在登录名 Configuration
中为此 LoginModule
指定两个选项。
user.provider.url=name_service_url group.provider.url=name_service_urlname_service_url指定此
LoginModule
可以访问相关用户和组信息的目录服务和路径。因为这个 LoginModule
只执行一级搜索来查找相关的用户信息,所以 URL
必须指向目录服务中存储用户和组信息的上一级目录。例如,要指示此 LoginModule
联系 NIS 服务,必须指定以下 URL:
user.provider.url="nis://NISServerHostName/NISDomain/user" group.provider.url="nis://NISServerHostName/NISDomain/system/group"NIS 服务主机名指定 NIS 服务的服务主机名(例如,nis.sun.com, 和NISDomain指定该 NIS 服务的域(例如,jaas.sun.com.要联系 LDAP 服务,必须指定以下 URL:
user.provider.url="ldap://LDAPServerHostName/LDAPName" group.provider.url="ldap://LDAPServerHostName/LDAPName"LDAP服务主机名指定 LDAP 服务的服务主机名,其中可能包含端口号(例如,ldap.sun.com:389), 和LDAP名称指定 LDAP 目录中的条目名称(例如,ou=人,o=太阳,c=美国和ou=Groups,o=Sun,c=US分别用于用户和组信息)。
RFC 2307 指定了用户信息必须存储在目录服务中的格式。具体来说,这个LoginModule
将使用用户的uid属性,其中uid=username.如果搜索成功,这个 LoginModule
将使用userPassword属性。此 LoginModule
假定密码存储为字节数组,当转换为 String
时,具有以下格式:
"{crypt}encrypted_password"LDAP 目录服务必须配置为允许对 userPassword 属性进行读取访问。如果用户输入了有效的用户名和密码,则
LoginModule
会将 UnixPrincipal
、UnixNumericUserPrincipal
和相关的 UnixNumericGroupPrincipals 与 Subject
相关联。
此 LoginModule 还识别以下 Configuration
选项:
debug if, true, debug messages are output to System.out.
useFirstPass if, true, this LoginModule retrieves the
username and password from the module's shared state,
using "javax.security.auth.login.name" and
"javax.security.auth.login.password" as the respective
keys. The retrieved values are used for authentication.
If authentication fails, no attempt for a retry is made,
and the failure is reported back to the calling
application.
tryFirstPass if, true, this LoginModule retrieves the
the username and password from the module's shared state,
using "javax.security.auth.login.name" and
"javax.security.auth.login.password" as the respective
keys. The retrieved values are used for authentication.
If authentication fails, the module uses the
CallbackHandler to retrieve a new username and password,
and another attempt to authenticate is made.
If the authentication fails, the failure is reported
back to the calling application.
storePass if, true, this LoginModule stores the username and password
obtained from the CallbackHandler in the module's
shared state, using "javax.security.auth.login.name" and
"javax.security.auth.login.password" as the respective
keys. This is not performed if existing values already
exist for the username and password in the shared state,
or if authentication fails.
clearPass if, true, this LoginModule
clears the
username and password stored in the module's shared state
after both phases of authentication (login and commit)
have completed.
-
字段详细信息
-
USER_PROVIDER
该模块可以访问相关用户信息的目录服务/路径。- 参见:
-
GROUP_PROVIDER
此模块可以访问相关组信息的目录服务/路径。- 参见:
-
-
构造方法详细信息
-
JndiLoginModule
public JndiLoginModule()创建一个JndiLoginModule
。
-
-
方法详情
-
initialize
public void initialize(Subject subject, CallbackHandler callbackHandler, Map <String , ?> sharedState, Map <String , ?> options) 初始化这个LoginModule
。- 指定者:
initialize
在接口LoginModule
中- 参数:
subject
- 要验证的Subject
。callbackHandler
- 一个CallbackHandler
用于与最终用户通信(例如,提示输入用户名和密码)。sharedState
- 共享LoginModule
状态。options
- 在登录Configuration
中为此特定的LoginModule
指定的选项。
-
login
提示输入用户名和密码。根据相关名称服务验证密码。- 指定者:
login
在接口LoginModule
中- 返回:
-
总是正确的,因为这个
LoginModule
不应该被忽略。 - 抛出:
FailedLoginException
- 如果身份验证失败。LoginException
- 如果此LoginModule
无法执行身份验证。
-
commit
提交身份验证过程(第 2 阶段)的抽象方法。如果 LoginContext 的整体身份验证成功(相关的 REQUIRED、REQUISITE、SUFFICIENT 和 OPTIONAL LoginModules 成功),则调用此方法。
如果此 LoginModule 自己的身份验证尝试成功(通过检索
login
方法保存的私有状态进行检查),则此方法将UnixPrincipal
与位于LoginModule
中的Subject
相关联。如果此 LoginModule 自己的身份验证尝试失败,则此方法会删除最初保存的所有状态。- 指定者:
commit
在接口LoginModule
中- 返回:
- 如果此 LoginModule 自己的登录和提交尝试成功,则为 true,否则为 false。
- 抛出:
LoginException
- 如果提交失败
-
abort
如果 LoginContext 的整体身份验证失败,则调用此方法。 (相关的 REQUIRED、REQUISITE、SUFFICIENT 和 OPTIONAL LoginModules 没有成功)。如果此 LoginModule 自己的身份验证尝试成功(通过检索
login
和commit
方法保存的私有状态进行检查),则此方法会清除最初保存的任何状态。- 指定者:
abort
在接口LoginModule
中- 返回:
- 如果此 LoginModule 自己的登录和/或提交尝试失败,则为 false,否则为 true。
- 抛出:
LoginException
- 如果中止失败。
-
logout
注销用户。此方法删除由
commit
方法添加的主体。- 指定者:
logout
在接口LoginModule
中- 返回:
-
在所有情况下都为真,因为不应忽略此
LoginModule
。 - 抛出:
LoginException
- 如果注销失败。
-