Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:44:22+00:00 2026-06-08T01:44:22+00:00

I have a Spring MVC application (using 3.0.5 version), and need to bind to

  • 0

I have a Spring MVC application (using 3.0.5 version), and need to bind to Active Directory using Spring LDAP for simply and only authenticating user’s credentials. The application is hosted on a Linux server, so I need a cross-platform solution. And the application does not use Spring Security.

What is an effective way to implement user authentication in this setup? Active Directory supports FastBind control (id=1.2.840.113556.1.4.1781), so I would like to leverage that since all I need is validation of the input credentials and need no other information back from AD.

Thanks!

Update (7/16/2012): I will continue to update my question with details of the resolution.

Based on the answer from @ig0774 I wrote the following connection control class:

package com.company.authentication;

import javax.naming.ldap.Control;

public class FastBindConnectionControl implements Control {

    @Override
    public String getID() {
        return "1.2.840.113556.1.4.1781";
    }

    @Override
    public boolean isCritical() {
        return true;
    }

    @Override
    public byte[] getEncodedValue() {
        return null;
    }
}

Then, I extended AbstractContextSource, using the FastBind connection-control class:

package com.company.authentication;

import java.util.Hashtable;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.ldap.Control;
import javax.naming.ldap.InitialLdapContext;
import org.springframework.ldap.core.support.AbstractContextSource;

public class FastBindActiveDirectoryContextSource extends AbstractContextSource {

    @Override
    protected DirContext getDirContextInstance(Hashtable env) throws NamingException {
        return new InitialLdapContext(env, new Control[] { new FastBindConnectionControl() });
    }
}

Finally, a service class to encapsulate the authentication mechanism:

package com.company.authentication;

import javax.naming.AuthenticationException;
import javax.naming.directory.DirContext;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.support.LdapUtils;

public class ActiveDirectoryAuthService implements IAuthenticate {

    private ContextSource contextSource;
    public void setContextSource(ContextSource contextSource) {
        this.contextSource = contextSource;
    }

    @Override
    public boolean authenticate(final String login, String password) {
        try {
            DirContext ctx = contextSource.getContext(login, password);
            LdapUtils.closeContext(ctx);
            return true;
        }
        catch (Exception e) {
            return false;
        }
    }
}

In my Spring application context configuration file, I added the following:

<bean id="ADContextSource" class="com.company.authentication.FastBindActiveDirectoryContextSource">
    <property name="url" value="ldaps://x.x.x.x:636" />
</bean>

<bean id="userAuthenticationService" class="com.company.authentication.ActiveDirectoryAuthService">
    <property name="contextSource" ref="ADContextSource" />
</bean>

Finally, userAuthenticationService bean is injected into the client class, say a login controller.

package com.company.web;

import com.company.authentication;

@Controller
public class LoginController {

    @Autowired
    private IAuthenticate userAuthenticationService;

    public String authenticateUser(String login, String password) {
      if (this.userAuthenticationService.authenticate(login, password)) {
          return "welcome";
      }
      else {
        return "login";
      }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:44:23+00:00Added an answer on June 8, 2026 at 1:44 am

    Implementing the FastBind control in JNDI is pretty straight-forward as discussed in this OTN forum post.

    Basically, you create a new Control class for the FastBind control:

    class FastBindConnectionControl implements Control {
        public byte[] getEncodedValue() {
                return null;
        }
        public String getID() {
            return "1.2.840.113556.1.4.1781";
        }
        public boolean isCritical() {
            return true;
        }
    }
    

    And then use that to create your ldap context (error handling and everything else ignored):

    LdapContext ctx = new InitialLdapContext(env, new Control[] {new FastBindConnectionControl()});
    

    Ideally, this would be easy to plug into Spring-LDAP which is a wrapper around the JNDI API for LDAP; however, it looks as though the interface for the built-in LdapContextSource does not accept a parameter to deal with connection controls, so you’ll apparently need to create your own sub-class of AbstractContextSource to handle that, which looks like it should be straight-forward enough:

    class FastBindLdapContextSource extends AbstractContextSource {
        protected DirContext getDirContextInstance(Hashtable env) {
            return new InitialLdapContext(env, new Control[] {new FastBindConnectionControl()});
        }
    }
    

    You would then just need to replace your current LdapContextSource with an instance of FastBindLdapContextSource.

    Note, however, that this context source can only be used for BIND operations. As noted in the MSDN document I linked to in a comment to Terry Gardner:

    Only simple binds are accepted on a connection in this mode. Because no group evaluation is done the connection is always handled as if no bind had occurred for the purposes of all other LDAP operations.

    Which means that you’re potentially looking at maintaining two types of LDAP contexts, one to do binds and one to actually perform any look-ups you may need to do.


    Looking at the source code for LdapTemplate, I see the authenticate method looks like it does a bit more than just a simple bind. More specifically, it does a search for the user and then attempts the bind. Since, if you’re using a context with FastBind enabled you’re unlikely to be able to perform a search (usually AD doesn’t permit searches on anonymous connections). Basically, that means you probably have to avoid LdapTemplate.

    However, assuming you get a reference to your ADContextSource bean, it should be simple enough to do something like

    boolean authenticate(String username, String password) {
        try {
            DirContext ctx = contextSource.getContext(username, password);
            LdapUtils.closeContext(ctx);
            return true;
        } catch (Exception e) {
            // note: this means an exception was thrown by #getContext() above
            return false;
        }
    }
    

    Which fairly closely mimics what LdapTemplate would do anyways (the only things that are missing is the AuthenticatedLdapEntryContextCallback, which isn’t of any value in this scenario, and the AuthenticationErrorCallback, which could easily be added in if you want that behavior).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using spring mvc in my application,when i created user i have to
I have a web application and im using spring mvc. I need to allow
I'm creating a web application using spring mvc. I have started to incorporate the
I have a spring MVC application using JSP as my view technologies with Jquery
I'm trying to make this 2-player web game application using Spring MVC. I have
We have a Spring web application created using Spring MVC 3.0 In the same
I have a simple Spring MVC application that looks up some user details from
I have a spring mvc application and I am rendering some pdfs using classes
I have a Spring MVC based Web Application with Hibernate. Following is the directory
I have Roo-generated Spring MVC application connected to PostgreSQL using Hibernate. I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.