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

Spring Security Kerberos 示例

参考文档的这一部分介绍了样本 项目。 样本可以通过构建主分发方式手动编译从 github.com/spring-projects/spring-security-kerberosspring-doc.cadn.net.cn

如果你直接运行样本,除非应用正确的配置。具体样本请见下方注释。spring-doc.cadn.net.cn

安全服务器 Windows 认证示例

本样本的目标:spring-doc.cadn.net.cn

  • 在Windows环境中,用户能够登录应用程序使用已输入的Windows活动目录凭证登录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虚拟机访问示例应用并手动使用域凭证。spring-doc.cadn.net.cn

安全服务器端认证示例

本示例展示了服务器如何能够通过通过表单登录传递的凭证,对用户进行身份验证针对 Kerberos 环境。spring-doc.cadn.net.cn

开个服务器。spring-doc.cadn.net.cn

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

安全服务器 Spnego 和表单认证示例

本示例展示了如何配置服务器接受来自浏览器的基于Spnego的协商,同时仍能回归到基于表单的认证。spring-doc.cadn.net.cn

使用用户1主理设置MIT克尔博罗斯,手动使用凭证登录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

或者使用Keytab文件。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

现在你应该能打开浏览器,让它用现有工单进行认证。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

Security Client KerberosRestTemplate Sample

这是一个使用Spring RestTemplate访问Kerberos受保护资源的示例。你可以与Security Server Spnego和表单认证示例一起使用。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

使用用户1主理设置MIT克尔博罗斯,手动使用凭证登录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>

或者使用用户2用一个 keytab 文件。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>