Hello Makkus, Regarding my last post, have you tried to change
@Inject private Principal principal; By @Resource private Principal principal; ? Does it work or not ? Best Regards. -----Original Message----- From: Richard Monson-Haefel [mailto:[email protected]] Sent: mardi 15 octobre 2019 14:53 To: [email protected] Subject: Re: Re: CDI Principal injection: object is not an instance of declaring class Great find, Francois! The article does use the @Resource annotation so maybe that its the way to go, Marco. On Tue, Oct 15, 2019 at 7:43 AM COURTAULT Francois < [email protected]> wrote: > Hello, > > May I make a comment on this. > Looking at > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.oracle.com%2Fjavaee%2F7%2Ftutorial%2Fcdi-adv004.htm&data=02%7C01%7CFrancois.COURTAULT%40gemalto.com%7C60ec44c959ff44cb1d6b08d7516eaaec%7C37d0a9db7c464096bfe31add5b495d6d%7C0%7C0%7C637067408064770254&sdata=nmvNDjfX48kLOiEEhitzD9glvxZ8sd%2B5K%2FHmYaWbFss%3D&reserved=0, > it > looks like you can't inject a Principal using @Inject annotation, right? > But using @Resource annotation, you are able to get the Principal. > > So in your previous code: > @Named > @RequestScoped > public class PrincipalTest { > > @Inject-> change @Inject by @Resource, does it work ? > private Principal principal; > > public String userName(){ > return principal.getName(); > } > } > > Best Regards. > > -----Original Message----- > From: Richard Monson-Haefel [mailto:[email protected]] > Sent: mardi 15 octobre 2019 13:42 > To: [email protected] > Subject: Re: Re: CDI Principal injection: object is not an instance of > declaring class > > Hi Markus, > > Do you want to try your hand at a doing a Pull-Request so you can get > your first commit on TomEE? I can help you with that. It's actually > pretty easy to do. > > Richard > > On Tue, Oct 15, 2019 at 6:36 AM makkus <[email protected]> wrote: > > > Hi Richard, > > > > I have attached the source files here: > > > > leak2.zip < > > https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Ftom > > ee > > -openejb.979440.n4.nabble.com%2Ffile%2Ft376354%2Fleak2.zip&data= > > 02 > > %7C01%7CFrancois.COURTAULT%40gemalto.com%7Ca4f5d66df05546eb376e08d75 > > 16 > > 4be4b%7C37d0a9db7c464096bfe31add5b495d6d%7C0%7C1%7C63706736543719036 > > 0& > > amp;sdata=IxxcqUuO7L1CStvRUS0HCU3zs9PgIa%2FKxG8ziESdPDs%3D&reser > > ve > > d=0> > > > > Maybe it is worth a note that the injection of SecurityContext still > works. > > So as a workaround the following will do the Job: > > > > @Context > > private SecurityContext securityCtx; > > > > public String userName(){ > > return securityCtx.getUserPrincipal().getName(); > > } > > > > Thanks for investigating this! > > Marcus > > > > > > > > > > -- > > Sent from: > > https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Ftom > > ee > > -openejb.979440.n4.nabble.com%2FTomEE-Users-f979441.html&data=02 > > %7 > > C01%7CFrancois.COURTAULT%40gemalto.com%7Ca4f5d66df05546eb376e08d7516 > > 4b > > e4b%7C37d0a9db7c464096bfe31add5b495d6d%7C0%7C1%7C637067365437190360& > > am > > p;sdata=eiF1kL6x7QMtJgEgINI%2BEzdJ5zgrh0Vyqqyr0yhCRho%3D&reserve > > d= > > 0 > > > > > -- > Richard Monson-Haefel > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftwit > ter.com%2Frmonson&data=02%7C01%7CFrancois.COURTAULT%40gemalto.com% > 7C60ec44c959ff44cb1d6b08d7516eaaec%7C37d0a9db7c464096bfe31add5b495d6d% > 7C0%7C0%7C637067408064770254&sdata=UVtPlK6gqBrpTAJQx8w2hoLZWZdTKhX > X%2FWoU1Vah1mY%3D&reserved=0 > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww. > linkedin.com%2Fin%2Fmonsonhaefel%2F&data=02%7C01%7CFrancois.COURTA > ULT%40gemalto.com%7C60ec44c959ff44cb1d6b08d7516eaaec%7C37d0a9db7c46409 > 6bfe31add5b495d6d%7C0%7C0%7C637067408064770254&sdata=B284Ow7dFdy%2 > Fe7hbC%2Bk7H%2FETjXGvCfq%2BgnaNKeIDCqY%3D&reserved=0 > ________________________________ > This message and any attachments are intended solely for the > addressees and may contain confidential information. Any unauthorized > use or disclosure, either whole or partial, is prohibited. > E-mails are susceptible to alteration. Our company shall not be liable > for the message if altered, changed or falsified. If you are not the > intended recipient of this message, please delete it and notify the sender. > Although all reasonable efforts have been made to keep this > transmission free from viruses, the sender will not be liable for > damages caused by a transmitted virus. > -- Richard Monson-Haefel https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftwitter.com%2Frmonson&data=02%7C01%7CFrancois.COURTAULT%40gemalto.com%7C60ec44c959ff44cb1d6b08d7516eaaec%7C37d0a9db7c464096bfe31add5b495d6d%7C0%7C0%7C637067408064770254&sdata=UVtPlK6gqBrpTAJQx8w2hoLZWZdTKhXX%2FWoU1Vah1mY%3D&reserved=0 https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.linkedin.com%2Fin%2Fmonsonhaefel%2F&data=02%7C01%7CFrancois.COURTAULT%40gemalto.com%7C60ec44c959ff44cb1d6b08d7516eaaec%7C37d0a9db7c464096bfe31add5b495d6d%7C0%7C0%7C637067408064770254&sdata=B284Ow7dFdy%2Fe7hbC%2Bk7H%2FETjXGvCfq%2BgnaNKeIDCqY%3D&reserved=0 ________________________________ This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized use or disclosure, either whole or partial, is prohibited. E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender. Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.
