This content has been marked as final.
Show 3 replies
-
1. Re: Static method to get the current user id (container managed)
dlofthouse Sep 17, 2018 6:13 AM (in response to bigcar)Which application server version are you using? Also is your deployment secured using WildFly Elytron or PicketBox?
-
2. Re: Static method to get the current user id (container managed)
bigcar Sep 17, 2018 9:54 PM (in response to dlofthouse)I am using EAP 6.4
Thanks!
-
3. Re: Static method to get the current user id (container managed)
bigcar Sep 18, 2018 3:15 PM (in response to bigcar)public static String getUserName() {
SecurityContext sc = SecurityContextAssociation.getSecurityContext();
if (sc != null) {
SubjectInfo si = sc.getSubjectInfo();
if (si != null) {
Subject sub = si.getAuthenticatedSubject();
if (sub != null) {
Principal[] ps = sub.getPrincipals().toArray(new Principal[0]);
return ps.length > 0 ? ps[0].getName() : null;
}
}
}
return null;
}