0
votes

Here is my problem:

Context : -Windows Server 2012 with ActiveDirectory -Tomcat -Rest API (Spring)

I'm currently trying to restrict REST request. I want that only specific groups of the AD could access to specific resources. I'm restricted to Kerberos authentication.

System configuration

  1. Create a user in domain "Tomcat"
  2. setspn -a HTTP/apirest.domain@DOMAIN
  3. Generate a tomcat.keytab using ktpass

API rest configuration

I'm using the spring security sample on github that you can find here :

https://github.com/spring-projects/spring-security-kerberos/tree/master/spring-security-kerberos-samples/sec-server-win-auth

I know that there is an EntryPoint and this is not needed in my context (API Rest). I've chosen this sample because it seems to use the windows authentication context and use it to automatically authenticate me in the spring security context. Right after, an ldap request is send to extract all information about the user logged. In my case, I need to extract the group.

I'm also using :

https://github.com/GyllingSW/kerberos-demo

To extract the role of the user with the class "RoleStrippingLdapUserDetailsMapper.java" instead of the "ActiveDirectoryLdapAuthoritiesPopulator". This implementation also offers localhost authentication but the issue with the NTLM token seems to be fixed in last commit of spring security.

I'm not really sure if this is the right way to do what I want.

My authentication seems to fail and I only have one things going wrong in my logs..

"Property 'userDn' not set - anonymous context will be used for read-write operations"

Questions

  1. Do I have to run my tomcat service using the tomcat account ? (Seems to be, yes)
  2. Am I doing the right things with Kerberos security ?
  3. How can I get rid of the anonymous context?
  4. The anonymous context seems to be set just right after Tomcat start. I want to get a context just after that my user (For instance, user1) requests the rest API (EntryPoint or whatever)

If there is something unclear let me know, I will try to reformulate!

Thanks,

2
Please avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. - T-Heron
Thanks, I will keep it mind for the next time - csik

2 Answers

1
votes

You do not need to query LDAP to get information about which groups does user belong to. Active Directory already adds this information to the Kerberos ticket which is sent from browser to Tomcat.

You just need to extract this information from the token for example using Kerb4J library. It comes with Spring integration inspired by spring-security-kerberos project so it should be pretty easy to switch to it.

If you still want to query LDAP you need to authenticate in LDAP before you can make any queries. Again there's no need to use end-user accounts for it - you can use the keytab file for Kerberos authentication in LDAP and query groups using "Tomcat" account

0
votes

I found a way to fix my issue.

In a REST API context, you have no entry point. I tried to set my entry point to an unmapped URL, just to do the negociation. By doing this, you will receive an HTTP response with the error code 404 (Not found) but with the right header was added by spring security (WWW-Authenticate).

The web browser will not send the ticket service if the error code is not 401.

To solve this problem, you have to create a CustomEntryPoint class (implements AuthenticationEntryPoint) and you need to override the "commence" method to return a 401 HTTP code with the right header.

I hope that could help. If there is a better way, let me know !