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

  • SEARCH
  • Home
  • 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 5964153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:22:49+00:00 2026-05-22T19:22:49+00:00

I’m new to Spring Security. In my application authentication is done through Ldap .After

  • 0

I’m new to Spring Security. In my application authentication is done through Ldap.After Ldap authentication I want to handle failure and success events on login. I want to track login count in database for locking functionality.
any body knows how to achieve this?

  • 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-05-22T19:22:50+00:00Added an answer on May 22, 2026 at 7:22 pm

    Authentication is done by LDAP but you want to lock the ldap user after he logged in.

    If you use spring 2.5 you can make your custom implementation of a InitializingBean and check if principal is a LDAP user:

    public abstract class EventListener implements InitializingBean {
    
    Log log = LogFactory.getLog(this.getClass());
    
    EventDispatcher eventDispatcher;
    
    // Spring will call this method after auto-
    // wiring is complete.
    public void afterPropertiesSet() throws Exception {
        // let us register this instance with
        // event dispatcher
        eventDispatcher.registerListener(this);
    }
    
    /**
     * Implementation of this method checks whether the given event can be
     * handled in this class. This method will be called by the event
     * dispatcher.
     * 
     * @param event
     *            the event to handle
     * @return true if the implementing subclass can handle the event
     */
    public abstract boolean canHandle(Object event);
    
    /**
     * This method is executed by the event dispatcher with the event object.
     * 
     * @param event
     *            the event to handle
     */
    public abstract void handle(Object event);
    
    public void setEventDispatcher(EventDispatcher eventDispatcher) {
        this.eventDispatcher = eventDispatcher;
    }
    }
    

    And next implement this custom handle on your loginFailureEventListener (map this listener in your xml)

            public class LoginSuccessEventlistener extends EventListener {  
    
        @Override  
        public boolean canHandle(Object event) {  
            return event instanceof AuthenticationFailureBadCredentialsEvent;
        }  
    
        @Override  
        public void handle(Object event) {
    AuthenticationFailureBadCredentialsEvent loginFailureEvent = (AuthenticationFailureBadCredentialsEvent) event;
            Object name = loginFailureEvent.getAuthentication().getPrincipal();
    
            if(principal instanceof org.springframework.security.userdetails.ldap.LdapUserDetailsImpl){
                out.("LDAPUser: " + user.getUsername() + " failed login");
    //do you thing here
            }
        }    
    }
    

    binding in XML:

    <b:bean id="loginFailureEventListener" class="com.foo.bar.support.event.LoginFailureEventListener">
        <b:property name="eventDispatcher" ref="eventDispatcher"/>
    </b:bean>
    

    EDIT:
    You can extend AuthenticationProcessingFilter and override the onUnsuccessfulAuthentication method:

    public class CustomAuthenticationProcessingFilter extends AuthenticationProcessingFilter {
        private LoginDao loginDao;
    
        @Override
        protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException {
            super.onSuccessfulAuthentication(request, response, authResult);    
            request.getSession().setAttribute("wrong", -1); 
        }
    
        protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
            super.onUnsuccessfulAuthentication(request, response, authException);
            String username = (String) authException.getAuthentication().getPrincipal();
            if(username.length() > 0){
                Login login = loginDao.read(username);
                if(login != null){
                    request.getSession().setAttribute("wrong", login.getFailedLoginAttempts());
                    request.getSession().setAttribute("attempts", Login.MAX_FAILED_LOGIN_ATTEMPTS);
                }else{
                    request.getSession().setAttribute("wrong", 100);
                }
            }else{
                request.getSession().setAttribute("wrong", -1);
            }
        }
    
        public void setLoginDao(LoginDao loginDao) {
            this.loginDao = loginDao;
        }
    }
    

    Binning in XML:

    <!-- Custom AuthenticationProcessingFilter with Callbacks -->
    <authentication-manager alias="authenticationManagerAlias"/>
    <b:bean id="authenticationProcessingFilter" name="authenticationProcessingFilter" class="com.foo.bat.support.event.CustomAuthenticationProcessingFilter"> 
        <b:property name="authenticationManager" ref="authenticationManagerAlias"/>
        <b:property name="authenticationFailureUrl" value="/login.do"/>
        <b:property name="filterProcessesUrl" value="/j_spring_security_check"/>
        <b:property name="defaultTargetUrl" value="/index.html"/>
        <!-- loginDao is a HibernateDao that reads logins an write wrong attempts to DB -->
        <b:property name="loginDao"><b:ref bean="loginDao"/></b:property>
        <custom-filter position="AUTHENTICATION_PROCESSING_FILTER" />          
    </b:bean>
    

    Now you can put this filter in your filterChainProxy

    Look here for inspiration
    http://www.harinair.com/2010/02/spring-acegi-security-account-lockout/

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I want to construct a data frame in an Rcpp function, but when I
I am using Paperclip to handle profile photo uploads in my app. They upload

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.