第 3 章 其他功能
3.1. 添加 FORM 登录作为 Fallback 复制链接链接已复制到粘贴板!
JBoss EAP 及其部署的应用还可以配置 FORM 登录身份验证机制,以用作回退。这允许应用程序在不存在 Kerberos/SPNEGO 令牌的情况下显示登录页面以进行身份验证。此身份验证独立于 Kerberos 身份验证进行。因此,根据 FORM 登录回退的配置方式,用户可能需要单独的凭证来通过此方法进行身份验证。
如果不存在 SPNEGO 或 NTLM 令牌,或者存在 SPNEGO 令牌,但来自其他 KDC,则可以使用回退到 FORM 登录。
3.1.1. 更新应用程序 复制链接链接已复制到粘贴板!
为 FORM 登录配置应用程序作为回退,需要执行以下步骤:
将 JBoss EAP 和 Web 应用配置为使用 Kerberos 和 SPNEGO.
有关配置 JBoss EAP 和 Web 应用以使用 Kerberos 和 SPNEGO 进行身份验证和授权所需的步骤,请参阅如何使用 Kerberos 设置 SSO。
添加登录和错误页面。
要使用 FORM 登录,需要登录和错误页面。这些文件添加到 Web 应用中,并在身份验证过程中使用。
示例:
login.jspFile<html> <head></head> <body> <form id="login_form" name="login_form" method="post" action="j_security_check" enctype="application/x-www-form-urlencoded"> <center> <p>Please login to proceed.</p> </center> <div style="margin-left: 15px;"> <p> <label for="username">Username</label> <br /> <input id="username" type="text" name="j_username"/> </p> <p> <label for="password">Password</label> <br /> <input id="password" type="password" name="j_password" value=""/> </p> <center> <input id="submit" type="submit" name="submit" value="Login"/> </center> </div> </form> </body> </html>示例:
Error.jspFile<html> <head></head> <body> <p>Login failed, please go back and try again.</p> </body> </html>修改
web.xml。向 Web 应用中添加登录和错误页面后,必须更新
web.xml,以将这些文件用于 FORM 登录。确切的 值FORM必须添加到<auth-method>元素中。因为<auth-method>需要一个用逗号分开的列表和顺序,所以<auth-method>的确切 值必须更新为SPNEGO,FORM。另外,<form-login-config>元素必须添加到<login-config>中,以及作为 <form-login-page> 和元素指定的登录路径和错误页面。<form-error-page>示例:更新的
web.xml文件<web-app> <display-name>App1</display-name> <description>App1</description> <!-- Define a security constraint that requires the Admin role to access resources --> <security-constraint> <display-name>Security Constraint on Conversation</display-name> <web-resource-collection> <web-resource-name>examplesWebApp</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>Admin</role-name> </auth-constraint> </security-constraint> <!-- Define the Login Configuration for this Application --> <login-config> <auth-method>SPNEGO,FORM</auth-method> <realm-name>SPNEGO</realm-name> <form-login-config> <form-login-page>/login.jsp</form-login-page> <form-error-page>/error.jsp</form-error-page> </form-login-config> </login-config> <!-- Security roles referenced by this web application --> <security-role> <description> role required to log in to the Application</description> <role-name>Admin</role-name> </security-role> </web-app>
3.1.2. 更新 Elytron 子系统 复制链接链接已复制到粘贴板!
在
http-authentication-factory中添加 FORM身份验证机制。您可以使用您为基于 kerberos 的身份验证配置的现有
http-authentication-factory,以及用于 FORM身份验证的额外机制。/subsystem=elytron/http-authentication-factory=example-krb-http-auth:list-add(name=mechanism-configurations, value={mechanism-name=FORM})添加额外的回退主体。
基于 kerberos 的身份验证的现有配置应已配置了安全域,用于将主体从 kerberos 令牌映射到应用的角色。您可以向该域添加用于回退身份验证的其他用户。例如,如果您使用的是
filesystem-realm,只需创建一个具有适当角色的新用户:
/subsystem=elytron/filesystem-realm=exampleFsRealm:add-identity(identity=fallbackUser1)
/subsystem=elytron/filesystem-realm=exampleFsRealm:set-password(identity=fallbackUser1, clear={password="password123"})
/subsystem=elytron/filesystem-realm=exampleFsRealm:add-identity-attribute(identity=fallbackUser1, name=Roles, value=["Admin","Guest"])
3.1.3. 更新传统安全子系统 复制链接链接已复制到粘贴板!
如果您使用 JBoss EAP 中的传统 安全 子系统,您必须更新安全域以进行回退身份验证。
Web 应用安全域必须配置为支持回退登录机制。这需要以下步骤:
- 添加新的安全域,以充当回退身份验证方法。
-
向指向回退域的 Web 应用安全域添加
usernamePasswordDomain模块选项。
示例:使用回调安全域配置安全域
/subsystem=security/security-domain=app-fallback:add(cache-type=default)
/subsystem=security/security-domain=app-fallback/authentication=classic:add()
/subsystem=security/security-domain=app-fallback/authentication=classic/login-module=UsersRoles:add(code=UsersRoles, flag=required, module-options=[usersProperties="file:${jboss.server.config.dir}/fallback-users.properties", rolesProperties="file:${jboss.server.config.dir}/fallback-roles.properties"])
/subsystem=security/security-domain=app-spnego/authentication=classic/login-module=SPNEGO:add(code=SPNEGO, flag=required, module-options=[serverSecurityDomain=host])
/subsystem=security/security-domain=app-spnego/authentication=classic/login-module=SPNEGO:map-put(name=module-options, key=usernamePasswordDomain, value=app-fallback)
/subsystem=security/security-domain=app-spnego/authentication=classic/login-module=SPNEGO:map-put(name=module-options, key=password-stacking, value=useFirstPass)
reload