此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Security Kerberos 2.2.0spring-doc.cadn.net.cn

Spring Security Kerberos 示例

参考文档的这一部分介绍示例 项目。可以通过构建 main 手动编译示例 从 github.com/spring-projects/spring-security-kerberos 分发。spring-doc.cadn.net.cn

如果按原样运行示例,则在配置正确之前它将无法工作 被应用。有关具体示例,请参阅下面的注释。spring-doc.cadn.net.cn

使用服务器端身份验证器的 Security Server Side Auth 示例示例spring-doc.cadn.net.cn

Security Server Windows 身份验证示例

此示例的目标:spring-doc.cadn.net.cn

  • 在 Windows 环境中,用户将能够登录应用程序 使用已输入的 Windows Active Directory 凭据 登录 Windows 期间。不应该有任何要求 用户 ID/密码凭据。spring-doc.cadn.net.cn

  • 在非 Windows 环境中,用户将看到一个屏幕 以提供 Active Directory 凭据。spring-doc.cadn.net.cn

server:
    port: 8080
    app:
        ad-domain: EXAMPLE.ORG
        ad-server: ldap://WIN-EKBO0EQ7TS7.example.org/
        service-principal: HTTP/[email protected]
        keytab-location: /tmp/tomcat.keytab
        ldap-search-base: dc=example,dc=org
        ldap-search-filter: "(| (userPrincipalName={0}) (sAMAccountName={0}))"

在上面,您可以看到此示例的默认配置。你 可以使用正常的 Spring Boot 技巧(例如 使用命令行选项或自定义application.yml文件。spring-doc.cadn.net.cn

运行服务器。spring-doc.cadn.net.cn

$ java -jar sec-server-win-auth-2.1.2-SNAPSHOT.jar

您可能需要在 Linux 中使用自定义 Kerberos 配置,方法是使用-Djava.security.krb5.conf=/path/to/krb5.iniGlobalSunJaasKerberosConfig豆。spring-doc.cadn.net.cn

有关如何使用 Windows Kerberos 环境的更多说明,请参阅设置 Windows 域控制器spring-doc.cadn.net.cn

登录到Windows 8.1使用域凭据和访问示例spring-doc.cadn.net.cn

从非 Windows VM 访问示例应用程序并使用域 手动凭据。spring-doc.cadn.net.cn

安全服务器端身份验证示例

此示例演示服务器如何对用户进行身份验证 使用通过 表单登录。spring-doc.cadn.net.cn

运行服务器。spring-doc.cadn.net.cn

$ java -jar sec-server-client-auth-2.1.2-SNAPSHOT.jar
server:
    port: 8080

Security Server Spnego 和表单身份验证示例

此示例演示如何将服务器配置为接受 从浏览器进行基于 Spnego 的协商,同时仍然能够下降 回到基于表单的身份验证。spring-doc.cadn.net.cn

使用user1principal 设置 MIT Kerberos, 使用凭据手动执行 Kerberos 登录。spring-doc.cadn.net.cn

$ kinit user1
Password for [email protected]:

$ klist
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: [email protected]

Valid starting     Expires            Service principal
10/03/15 17:18:45  11/03/15 03:18:45  krbtgt/[email protected]
  renew until 11/03/15 17:18:40

或使用键表文件。spring-doc.cadn.net.cn

$ kinit -kt user2.keytab user1

$ klist
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: [email protected]

Valid starting     Expires            Service principal
10/03/15 17:25:03  11/03/15 03:25:03  krbtgt/[email protected]
  renew until 11/03/15 17:25:03

运行服务器。spring-doc.cadn.net.cn

$ java -jar sec-server-spnego-form-auth-2.1.2-SNAPSHOT.jar

现在您应该能够打开浏览器并让它执行 Spnego 使用现有票证进行身份验证。spring-doc.cadn.net.cn

有关配置浏览器以使用 Spnego 的更多说明,请参阅配置浏览器以进行 Spnego 协商spring-doc.cadn.net.cn

server:
    port: 8080
app:
    service-principal: HTTP/[email protected]
    keytab-location: /tmp/tomcat.keytab

安全客户端 KerberosRestTemplate 示例

这是一个使用 Spring RestTemplate 访问 Kerberos 的示例 受保护的资源。您可以将其与 Security Server Spnego 和 Form Auth Sample 一起使用。spring-doc.cadn.net.cn

默认应用程序配置如下图所示。spring-doc.cadn.net.cn

app:
    user-principal: [email protected]
    keytab-location: /tmp/user2.keytab
    access-url: http://neo.example.org:8080/hello

使用user1principal 设置 MIT Kerberos, 使用凭据手动执行 Kerberos 登录。spring-doc.cadn.net.cn

$ java -jar sec-client-rest-template-2.1.2-SNAPSHOT.jar --app.user-principal --app.keytab-location

在上面,我们简单地将app.user-principalapp.keytab-location为空值,从而禁用 Keytab 文件的使用。spring-doc.cadn.net.cn

如果作成功,您应该会看到下面的输出[email protected].spring-doc.cadn.net.cn

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
  <head>
    <title>Spring Security Kerberos Example</title>
  </head>
  <body>
    <h1>Hello [email protected]!</h1>
  </body>
</html>

或者使用user2使用键表文件。spring-doc.cadn.net.cn

$ java -jar sec-client-rest-template-2.1.2-SNAPSHOT.jar

如果作成功,您应该会看到下面的输出[email protected].spring-doc.cadn.net.cn

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
  <head>
    <title>Spring Security Kerberos Example</title>
  </head>
  <body>
    <h1>Hello [email protected]!</h1>
  </body>
</html>