You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Matthew Broadhead <ma...@nbmlaw.co.uk> on 2018/05/07 15:10:48 UTC

cdi execute code on session start

what is the best way to run code when a session is first created?  i 
thought maybe a @PostConstruct inside a @Named @SessionScoped but it 
doesn't trigger.

Re: cdi execute code on session start

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Le mar. 8 mai 2018 10:50, Matthew Broadhead <ma...@nbmlaw.co.uk>
a écrit :

> @WebListener works fine
>
> public void processSessionScopedInit(@Observes
> @Initialized(SessionScoped.class) HttpSession payload) {} caused an
> infinite loop in the code.  i can send you a stack trace but it grows so
> long it is hard to find the initial cause
>


Put a breakpoint ;)

>
> however i have not fixed my problem because
> KeycloakPrincipal<KeycloakSecurityContext> is not available at session
> start.  The session starts before the redirect to the login page.
>
> is there any way to execute code just after a user signs in?  i am just
> trying to log username and ip for security purposes
>

Depends your login mecanism, maybe have a look on keycloak side



>
> On 07/05/18 18:18, Romain Manni-Bucau wrote:
> > @WebListener on a HttpSessionListener?
> >
> > otherwise @Observes @Initialiazed(SessionScoped.class) in the cdi bean
> >
> >
> > Romain Manni-Bucau
> > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > <https://rmannibucau.metawerx.net/> | Old Blog
> > <http://rmannibucau.wordpress.com> | Github <
> https://github.com/rmannibucau> |
> > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
> > <
> https://www.packtpub.com/application-development/java-ee-8-high-performance
> >
> >
> > 2018-05-07 17:10 GMT+02:00 Matthew Broadhead <
> matthew.broadhead@nbmlaw.co.uk
> >> :
> >> what is the best way to run code when a session is first created?  i
> >> thought maybe a @PostConstruct inside a @Named @SessionScoped but it
> >> doesn't trigger.
> >>
>
>

Re: cdi execute code on session start

Posted by Matthew Broadhead <ma...@nbmlaw.co.uk>.
@WebListener works fine

public void processSessionScopedInit(@Observes 
@Initialized(SessionScoped.class) HttpSession payload) {} caused an 
infinite loop in the code.  i can send you a stack trace but it grows so 
long it is hard to find the initial cause

however i have not fixed my problem because 
KeycloakPrincipal<KeycloakSecurityContext> is not available at session 
start.  The session starts before the redirect to the login page.

is there any way to execute code just after a user signs in?  i am just 
trying to log username and ip for security purposes


On 07/05/18 18:18, Romain Manni-Bucau wrote:
> @WebListener on a HttpSessionListener?
>
> otherwise @Observes @Initialiazed(SessionScoped.class) in the cdi bean
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://rmannibucau.metawerx.net/> | Old Blog
> <http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
> <https://www.packtpub.com/application-development/java-ee-8-high-performance>
>
> 2018-05-07 17:10 GMT+02:00 Matthew Broadhead <matthew.broadhead@nbmlaw.co.uk
>> :
>> what is the best way to run code when a session is first created?  i
>> thought maybe a @PostConstruct inside a @Named @SessionScoped but it
>> doesn't trigger.
>>


Re: cdi execute code on session start

Posted by Romain Manni-Bucau <rm...@gmail.com>.
@WebListener on a HttpSessionListener?

otherwise @Observes @Initialiazed(SessionScoped.class) in the cdi bean


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>

2018-05-07 17:10 GMT+02:00 Matthew Broadhead <matthew.broadhead@nbmlaw.co.uk
>:

> what is the best way to run code when a session is first created?  i
> thought maybe a @PostConstruct inside a @Named @SessionScoped but it
> doesn't trigger.
>