Announcement Announcement Module
Collapse
No announcement yet.
Incorrect login counter. Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Incorrect login counter.

    Hi, could anyone help me how to execute SQL query on incorrect login action? Or even better on succesfull login action to store IP address and date/time of last action.

    In my app I am using:
    securityEnforcementFilter
    -- authenticationManager
    -- -- daoAuthenticationProvider
    -- -- -- jdbcAuthenticationDao
    -- -- anonymousAuthenticationProvider
    Any help will be very appreciated.

    Thanks in advance.

  • #2
    Acegi publishs a number of events. You can tap into them as you would any Spring event.

    Simply create a class that implements ApplicationListener, as follows;

    Code:
    package app.events;
    
    import net.sf.acegisecurity.providers.dao.event.AuthenticationSuccessEvent;
    import org.springframework.context.ApplicationListener;
    import org.springframework.context.ApplicationEvent;
    
    public class SuccessfulLoginEvent implements ApplicationListener {
    
        private MonitorDao monitorDao;
    
        public MonitorDao getMonitorDao() {
            return monitorDao;
        }
    
        public void setMonitorDao(MonitorDao monitorDao) {
            this.monitorDao = monitorDao;
        }
    
        public void onApplicationEvent(ApplicationEvent event) {
               if (event instanceof AuthenticationSuccessEvent) {
                   AuthenticationSuccessEvent successEvent = (AuthenticationSuccessEvent) event;
                   monitorDao.write(successEvent.getUser());
            }
        }
    }
    In the above example I use a DAO to record the event. You would implement your DAO as a SQL.

    After that, the only other thing you need to do is register the listener in your application context.

    Code:
        <bean id="successflLoginEvent" class="app.events.SuccessfulLoginEvent">
            <property name="monitorDao">
                <ref bean="monitorDao"/>
            </property>
        </bean>
    Spring looks for anything that implements ApplicationListener when it loads up the context. It will then fire it whenever is "hears" an event

    Comment

    Working...
    X