<div dir="ltr">Hello,<div><br></div><div>AFAIK Spring Security fires a AuthenticationSuccessEvent after a successful login - so you should be able to register a listener for this event e.g.:</div><div><br></div><div><div> @Service</div><div>    public class UserService implements</div><div>                             ApplicationListener&lt;AuthenticationSuccessEvent&gt; {</div><div>        ...</div><div><br></div><div>        public onApplicationEvent(AuthenticationSuccessEvent event) {</div><div>           String userName = ((UserDetails) event.getAuthentication().</div><div>                                                  getPrincipal()).getUsername();</div><div>           User user = this.userDao.findByLogin(userName);</div><div>           user.setLastLoginDate(new Date());</div><div>        }</div><div>   }</div></div><div><br></div><div><br></div><div><br></div><div>Cheers,</div><div>Thomas</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-04-20 9:17 GMT+02:00 Daniele Capasso Barbato <span dir="ltr">&lt;<a href="mailto:daniele.capasso@dnshosting.it" target="_blank">daniele.capasso@dnshosting.it</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  

    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <p><span style="color:rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-serif;font-size:15px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:19.5px;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none;background-color:rgb(255,255,255)">I develop a
        rest based api application with spring security and keycloak.
        I&#39;d like to execute custom code when users are log in in to my
        application in any rest controller, I try with my filter putting
        in the last position of filter chain, but the KeycloakPrincipal
        in the request is null (seems that Keycloak value was set after
        that)<br>
      </span></p>
    <p><span style="color:rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-serif;font-size:15px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:19.5px;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none;background-color:rgb(255,255,255)">How can I </span><span>execute
        custom code when users are login in the right way?<br>
      </span></p>
    <p><span style="color:rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-serif;font-size:15px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:19.5px;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none;background-color:rgb(255,255,255)">Thanx<br>
      </span></p>
    <p><span style="color:rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-serif;font-size:15px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:19.5px;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none;background-color:rgb(255,255,255)"><br>
      </span></p>
    <p><span style="color:rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-serif;font-size:15px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:19.5px;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none;background-color:rgb(255,255,255)"><br>
      </span></p>
  </div>

<br>_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br></blockquote></div><br></div>