Jaspic module not propagating principal to local EJB in JBoss 7.4

倖福魔咒の 提交于 2019-12-04 17:17:58

Propagating the authenticated identity from Servlet to EJB is unfortunately a never ending story with JBoss, despite the best efforts of the JBoss engineers.

There were some 6 individual bugs that had to be fixed so you could even get to the point where you are now in JBoss AS 7.4 (JBoss EAP 6.3 I assume), and there are a couple of bugs after this.

This particular bug is https://issues.jboss.org/browse/SECURITY-745 and was filed almost 2 years ago, but still open for the AS 7/EAP 6 branch. This one came right after https://issues.jboss.org/browse/SECURITY-744, which is listed as open but I think it's actually fixed.

The WF 8/EAP 7 branch doesn't have this bug, but both branches do suffer from https://issues.jboss.org/browse/SECURITY-746 and https://issues.jboss.org/browse/SECURITY-876

So it's a known bug in JBoss. If you want to get it solved my advice would be to contact JBoss about it.

An alternative workaround which I used for the AS 7 branch is providing my own modified org.jboss.as.web.security.jaspi.WebJASPIAuthenticator implementation, but then you'll run right away into SECURITY-746, so you need the custom be.mycompany.api.authentication.jaspi.MycompanyAuthModule module that you used anyway.

At last, it seems Red Hat fixed the bug. I got an official patch that works well in JBoss EAP 6.4.3.

For those interested, my support case number was 01440434, and the patch file name was

Googling for it leads me to https://bugzilla.redhat.com/show_bug.cgi?id=1243553 and https://github.com/wildfly/wildfly/pull/7469/files

They also talk about https://github.com/jbossas/jboss-eap/pull/2480 but I get a 404 on this.

Didn't try it in Wildfly, but I like the simplicity of this fix.

There are still cases that seem to be broken though (e.g. @RolesAllowed doesn't seem to work), but I'll open new support cases for that, as I didn't ask specifically for this in my first support case.

(LATEST NEWS: see my other answer for a "definitive" solution).

UPDATE:

Got a test patch from RedHat and it works :-)

I'll update this answer when more information is available.

UPDATE 2: RedHat says that the patch should be in 7.3.3... But it's not complete in my opinion (found another use case where this does not work). (support case 01440434)

UPDATE 3: besides the working patch, I alternatively had a workaround in my authentication module that made it work for JAX-RS and EJB:

        // TODO: remove this when fixed in JBoss - WORKAROUND to get authentication to propagate to EJBs
        SecurityContext oldContext = SecurityContextAssociation.getSecurityContext();
        SubjectInfo subjectInfo = oldContext.getSubjectInfo();
        subjectInfo.setAuthenticatedSubject(serviceSubject);
        SecurityContextAssociation.setPrincipal(degroofPrincipal);
        serviceSubject.getPrincipals().add(degroofPrincipal);

... but for whatever reason, it doesn't work in a JSF context.

See Arjan Tijms's provided link, https://github.com/javaeekickoff/jboss-as-jaspic-patch/tree/master/src/main/java/patch/jboss . This does work with a few changes for 7.4 (removing logging, finding the right jars, some custom changes to get it to compile).

I can share this if necessary, but I just opened support case 01494061 at RedHat for that. Hope they will eventually patch it...


Red Hat's answer for now:

Hi ---,

Yes, I think information Arjan Tijms provided is correct. For the principal to be propagated to the ejb layer, it must be put into the subject. This works with the approach shown in [1]. However, it works because the HTTPBasicServerAuthModule defers to JAAS/JBossWebRealm to handle the authentication. This setups up the subject so that it will propagate the principal to the ejb layer.

I am researching the suggested enhancements and discussing this with our engineers.

I will provide an update early next week.

Thanks,

[1] https://developer.jboss.org/wiki/JBossAS7EnablingJASPIAuthenticationForWebApplications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!