Spring-Security: Call method after authentication

后端 未结 7 1340
一整个雨季
一整个雨季 2021-02-01 04:52

I\'d like to track when users are logging in to my application. I have some code that I would like to execute right after the user is authenticated. The problem is, I can\'t fig

7条回答
  •  臣服心动
    2021-02-01 05:20

    Just write your own SpringSecurityFilter and add it to the filter chain right after your authentication provider is called.

    package my.code;
    
    public class AuditFilter extends SpringSecurityFilter {
    
       public void doFilterHttp(...) throws ... {
          {application code to run before request is processed}
          chain.doFilter(...);
          {application code to run after request has fully processed} 
       }
    }
    

    Then in your configuration XML (wherever you setup the Security Filter chain) add a line like this:

      <-- you can change the position
    
    

提交回复
热议问题