Retrieving Elytron SecurityContext with JNDI

161 views
Skip to first unread message

Mansour Al Akeel

unread,
Oct 17, 2023, 3:56:00 PM10/17/23
to WildFly
Hello,
We have spring application, running in wildfly. I am investigating the possibility of using  elytron with spring.
Ultimately I would like to retrieve the securityContext/Security Prinicipal in spring. If this can be done with JNDI then this is a good starting point.

Thank you.


Diana Krepinska

unread,
Oct 26, 2023, 2:37:24 PM10/26/23
to WildFly
Hi Mansour, the security context can be injected with an annotation and you can obtain a principal from it https://jakarta.ee/specifications/security/2.0/apidocs/jakarta/security/enterprise/securitycontext#getCallerPrincipal()

Mansour Al Akeel

unread,
Oct 27, 2023, 7:08:46 PM10/27/23
to WildFly

Hello Diana,

Unfortunately, this did not work. I am not sure what annotations to use. In all cases either of them is injecting nothing, and the reference is null.

@Context and @Inject does not inject anything.
@Resource, is the SecurityContext considered a resource ? In either cases, this was not attainable.



If I can retrieve a reference to Elytron, then I might be able to make it available through Spring. But this did not work.

Diana Krepinska

unread,
Oct 31, 2023, 8:11:56 AM10/31/23
to WildFly
Hi Mansour,

I am not sure about spring, but obtaining of SecurityContext can be seen in wildfly quickstarts, for example: https://github.com/wildfly/quickstart/blob/main/ee-security/src/main/java/org/jboss/as/quickstarts/ee_security/SecuredServlet.java and in elytron-examples: https://github.com/wildfly-security-incubator/elytron-examples . Make sure your app is secured when using these annotations
Reply all
Reply to author
Forward
0 new messages