[keycloak-user] Keycloak - Spring-Security-adapter: Call method after authentication

Thomas Darimont thomas.darimont at googlemail.com
Wed Apr 20 03:53:11 EDT 2016


Hello,

AFAIK Spring Security fires a AuthenticationSuccessEvent after a successful
login - so you should be able to register a listener for this event e.g.:

 @Service
    public class UserService implements

 ApplicationListener<AuthenticationSuccessEvent> {
        ...

        public onApplicationEvent(AuthenticationSuccessEvent event) {
           String userName = ((UserDetails) event.getAuthentication().

getPrincipal()).getUsername();
           User user = this.userDao.findByLogin(userName);
           user.setLastLoginDate(new Date());
        }
   }



Cheers,
Thomas

2016-04-20 9:17 GMT+02:00 Daniele Capasso Barbato <
daniele.capasso at dnshosting.it>:

> I develop a rest based api application with spring security and keycloak.
> I'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)
>
> How can I execute custom code when users are login in the right way?
>
> Thanx
>
>
>
>
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160420/7c7afb8e/attachment-0001.html 


More information about the keycloak-user mailing list