For the latest stable version, please use Spring Security Kerberos 2.1.0!spring-doc.cn

Spring Security Kerberos Samples

This part of the reference documentation is introducing samples projects. Samples can be compiled manually by building main distribution from github.com/spring-projects/spring-security-kerberos.spring-doc.cn

If you run sample as is it will not work until a correct configuration is applied. See notes below for specific samples.spring-doc.cn

Security Server Windows Auth Sample sample for Windows environmentspring-doc.cn

Security Server Side Auth Sample sample using server side authenticatorspring-doc.cn

Security Server Spnego and Form Auth Sample sample using ticket validation with spnego and formspring-doc.cn

Security Server Spnego and Form Auth Xml Sample sample using ticket validation with spnego and form (xml config)spring-doc.cn

Security Server Windows Auth Sample

Goals of this sample:spring-doc.cn

  • In windows environment, User will be able to logon to application with Windows Active directory Credential which has been entered during log on to windows. There should not be any ask for userid/password credentials.spring-doc.cn

  • In non-windows environment, User will be presented with a screen to provide Active directory credentials.spring-doc.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}))"

In above you can see the default configuration for this sample. You can override these settings using a normal Spring Boot tricks like using command-line options or custom application.yml file.spring-doc.cn

Run a server.spring-doc.cn

$ java -jar sec-server-win-auth-2.0.1.jar

You may need to use custom kerberos config with Linux either by using -Djava.security.krb5.conf=/path/to/krb5.ini or GlobalSunJaasKerberosConfig bean.spring-doc.cn

See Setup Windows Domain Controller for more instructions how to work with windows kerberos environment.spring-doc.cn

Login to Windows 8.1 using domain credentials and access samplespring-doc.cn

Access sample application from a non windows vm and use domain credentials manually.spring-doc.cn

Security Server Side Auth Sample

This sample demonstrates how server is able to authenticate user against kerberos environment using his credentials passed in via a form login.spring-doc.cn

Run a server.spring-doc.cn

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

Security Server Spnego and Form Auth Sample

This sample demonstrates how a server can be configured to accept a Spnego based negotiation from a browser while still being able to fall back to a form based authentication.spring-doc.cn

Using a user1 principal Setup MIT Kerberos, do a kerberos login manually using credentials.spring-doc.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

or using a keytab file.spring-doc.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

Run a server.spring-doc.cn

$ java -jar sec-server-spnego-form-auth-2.0.1.jar

Now you should be able to open your browser and let it do Spnego authentication with existing ticket.spring-doc.cn

See Configure Browsers for Spnego Negotiation for more instructions for configuring browsers to use Spnego.spring-doc.cn

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

Security Server Spnego and Form Auth Xml Sample

This is a same sample than Security Server Spnego and Form Auth Sample but using xml based configuration instead of JavaConfig.spring-doc.cn

Run a server.spring-doc.cn

$ java -jar sec-server-spnego-form-auth-xml-2.0.1.jar

Security Client KerberosRestTemplate Sample

This is a sample using a Spring RestTemplate to access Kerberos protected resource. You can use this together with Security Server Spnego and Form Auth Sample.spring-doc.cn

Default application is configured as shown below.spring-doc.cn

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

Using a user1 principal Setup MIT Kerberos, do a kerberos login manually using credentials.spring-doc.cn

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

In above we simply set app.user-principal and app.keytab-location to empty values which disables a use of keytab file.spring-doc.cn

If operation is succesfull you should see below output with [email protected].spring-doc.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>

Or use a user2 with a keytab file.spring-doc.cn

$ java -jar sec-client-rest-template-2.0.1.jar

If operation is succesfull you should see below output with [email protected].spring-doc.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>