3.3.2. 使用 Elytron 进行 Kerberos 身份验证集成
可以为 Kerberos 或 GSSAPI SASL 身份验证定义 Elytron 安全域来远程进行身份验证。
定义要从中加载身份的安全域。它用于分配角色。
/path=kerberos:add(relative-to=user.home, path=src/kerberos) /subsystem=elytron/properties-realm=kerberos-properties:add(users-properties={path=kerberos-users.properties, relative-to=kerberos, digest-realm-name=ELYTRON.ORG}, groups-properties={path=kerberos-groups.properties, relative-to=kerberos})为服务器身份定义 Kerberos 安全工厂。
/subsystem=elytron/kerberos-security-factory=test-server:add(relative-to=kerberos, path=remote-test-server.keytab, principal=remote/test-server.elytron.org@ELYTRON.ORG)定义安全域,以及 SASL 身份验证工厂。
/subsystem=elytron/security-domain=KerberosDomain:add(default-realm=kerberos-properties, realms=[{realm=kerberos-properties, role-decoder=groups-to-roles}], permission-mapper=default-permission-mapper) /subsystem=elytron/sasl-authentication-factory=gssapi-authentication-factory:add(security-domain=KerberosDomain, sasl-server-factory=elytron, mechanism-configurations=[{mechanism-name=GSSAPI, credential-security-factory=test-server}])在远程子系统中,使用创建的sasl-authentication-factory将它启用以进行远程处理。CLI 命令示例
/subsystem=remoting/http-connector=http-remoting-connector:write-attribute(name=sasl-authentication-factory, value=gssapi-authentication-factory)配置 服务的安全性。
如果您引用 EJB 中的安全域,您必须指定映射到 Elytron 安全域的
application-security-domain。例如,通过 EJB,您可以使用@SecurityDomain注释。CLI 命令示例
/subsystem=ejb3/application-security-domain=KerberosDomain:add(security-domain=KerberosDomain)
将 JAAS 主题用于身份关联不再被支持。希望以编程方式管理 EJB 调用 Kerberos 身份的客户端应迁移并直接使用 AuthenticationConfiguration API,如下所示:
// create your authentication configuration
AuthenticationConfiguration configuration = AuthenticationConfiguration.empty()
.useProvidersFromClassLoader(SecuredGSSCredentialClient.class.getClassLoader())
.useGSSCredential(getGSSCredential());
// create your authentication context
AuthenticationContext context = AuthenticationContext.empty().with(MatchRule.ALL, configuration);
// create a callable that looks up an EJB and invokes a method on it
Callable<Void> callable = () -> {
...
};
// use your authentication context to run your callable
context.runCallable(callable);
创建 AuthenticationConfiguration 时会调用 使用GSSCredential(getGSSCredential())。已有权访问 JAAS 主题的客户端代码可轻松转换以获取 GSSCredential,如下所示:
private GSSCredential getGSSCredential() {
return Subject.doAs(subject, new PrivilegedAction<GSSCredential>() {
public GSSCredential run() {
try {
GSSManager gssManager = GSSManager.getInstance();
return gssManager.createCredential(GSSCredential.INITIATE_ONLY);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
});
}
修订了 2022 年 2 月 18:25:23 +1000