Thank you very much for your help Stephen. It's been really helpful. I looked at the plugin and this is how they capture the current user and authenticate him:
Cause.UserIdCause cause = getRootUserIdCause(item);
if (cause != null) {
User u = User.get(cause.getUserId(), false, Collections.emptyMap());
if (u == null) {
return Jenkins.ANONYMOUS;
}
return u.impersonate();
}
return null;
Then impersonate the user who started the build. That returns a org.acegisecurity.Authentication. It is progress.
It gives me the Jenkins user. But problem is I don't think it is the Web container user, and is even related to it. (That would mean a Jenkins admin could impersonate any user from the Realm and contact any other application, which doesn't make any sense).
My next question is:
- Do you think there is any way to get the Web Container user (Subject), knowing that it looks like the thread doesn't get the authentication (com.ibm.websphere.security.auth.WSSubject.getCallerSubject() returns null)
- Or do you think it is possible to convert the Jenkins Authentication to a Web Container Subject. I did create a Subject from the Jenkins Authentication (which is a Principal) but of course it didn't work since it is not related to the Web Container authentication and I had access forbidden. I doubt it because Jenkins can impersonate anyone, and maybe it will work only for the current user...
I don;t really know where to look next.
Thank you very much.