Bug 724795 (BRMS-635) - JCR session doesn't contain the current user when ModeShape is used
Summary: JCR session doesn't contain the current user when ModeShape is used
Keywords:
Status: ASSIGNED
Alias: BRMS-635
Product: JBoss Enterprise BRMS Platform 5
Classification: JBoss
Component: BRM (Guvnor), Modeshape
Version: BRMS 5.2.0-Dev1
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: ER1
: BRMS 5.3.0.GA
Assignee: manstis
QA Contact: Jiri Locker
URL: http://jira.jboss.org/jira/browse/BRM...
Whiteboard:
: BRMS-572 (view as bug list)
Depends On:
Blocks: BRMS-572, BRMS-572
TreeView+ depends on / blocked
 
Reported: 2011-07-12 16:37 UTC by Jiri Locker
Modified: 2023-05-15 19:53 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
When using JAAS authentication with ModeShape and no credentials are supplied, ModeShape's Repository.login(...) methods result in a session that does not contain the proper user ID. <!-- This issue was resolved by adjusted the JAAS authentication provider to work within J2EE containers. -->
Clone Of:
Environment:
Last Closed:
Type: Bug
Embargoed:


Attachments (Terms of Use)
patch to set the security context (3.51 KB, text/plain)
2011-09-27 18:34 UTC, Kurt Stam
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker BRMS-635 0 Critical Closed JCR session doesn't containt the current user when ModeShape is used 2018-12-11 14:18:06 UTC
Red Hat Issue Tracker MODE-1270 0 Blocker Closed ModeShape session does not have username JAAS API does not return Subject when used within J2EE applications 2018-12-11 14:18:06 UTC

Description Jiri Locker 2011-07-12 16:37:24 UTC
securitylevel_name: Public

As a result no information about user is stored in the repository (created by, last updated by). Role-based authorization seems to be working, though.

Comment 1 Randall Hauch 2011-07-20 13:48:44 UTC
What exactly is missing or not being set? Examples and concrete data please. What does 'session.getUserID()' return?

Also, please confirm that the ModeShape repository configuration's "useAnonymousAccessOnFailedLogin" repository option is not being set to 'true' (the default is 'false') or is explicitly set to 'false'.

Finally, if the user is indeed authenticating, due to the above discussion, this may mean that users are not successfully authenticating with JAAS, and if the correct username/password are being used then the JAAS/ModeShape configuration may not be correct.

Comment 2 Randall Hauch 2011-07-20 13:48:59 UTC
Link: Added: This issue is related to MODE-1222


Comment 3 Randall Hauch 2011-07-20 14:09:23 UTC
Link: Removed: This issue is related to MODE-1222 


Comment 4 Jiri Locker 2011-07-25 12:37:13 UTC
Not sure if this helps, but 'session.getUserID()' returns string '<anonymous>' (without the quotes).

Comment 5 Randall Hauch 2011-07-25 16:21:47 UTC
That definitely means the user is being logged in as anonymous. So if the BRMS code is explicitly doing this (by creating sessions without credentials), then this is either a bug in BRMS and needs to be changed, or it is working as coded. :-)

If BRMS is creating sessions with credentials, then ModeShape is not able to authenticate the credentials using JAAS. Either the credentials are wrong (e.g., the JAAS files do not contain the right information), or JAAS is improperly configured and ModeShape is not able to use JAAS to authenticate any credentials. Either way, this is a BRMS issue and not a ModeShape issue.

Comment 6 Randall Hauch 2011-08-01 15:13:07 UTC
I'm assigning to Kurt, as this is Guvnor/BRMS issue and not a ModeShape issue. I hope that's right.

Comment 7 Jiri Locker 2011-08-09 08:59:35 UTC
Might be related to bug 724683.

Comment 8 lcarlon 2011-08-18 05:29:38 UTC
I've listed this as not needing a release note (the issue appears to be between internal development versions).

Let me know if I got it wrong. Change the technical_note flag to '?' to indicated a release note is required.

Thanks
- Lee

Comment 9 Geoffrey De Smet 2011-09-08 12:20:47 UTC
The problem is in org.drools.guvnor.server.repository.RepositoryStartupService#create():
it always logs in with a static admin user.

For guvnor 5.4, which will clean up the repository boot mess and use weld-seam3, we can fix this decently. 5.2 is a different story...

Comment 10 Prakash Aradhya 2011-09-08 21:16:30 UTC
I would not think this a blocking bug.  It would be good to get it cleaned for 5.2, but given where it is not critical for the release

Comment 11 Geoffrey De Smet 2011-09-09 09:35:54 UTC
My previous comment is wrong: that's just the setup session. RulesRepositoryManager does seem to log it in with the current username, but there's a fallback mechanism.

Either way, I 'll take this requirement along for the 5.4 boot cleanup.

Comment 12 Lukáš Petrovický 2011-09-09 10:05:21 UTC
Lee, since we're not fixing this for 5.2, would you make sure that it is mentioned in the relase notes?

Comment 13 lcarlon 2011-09-12 01:10:25 UTC
Thanks Lukáš,

Will do.

Comment 14 Geoffrey De Smet 2011-09-15 12:02:22 UTC
Lukas, Lee: In 5.2, has anyone tried with the jaasConfigName set correctly in the components.xml as specified in the manual?

"To use JAAS and the modeshape policy comment out the defaultAuthenticator section and uncomment
    the jaas-configuration section, and change the policy name from 'other' to 'modeshape'"

Not sure if it's related, but it could be.

Comment 15 Jiri Locker 2011-09-15 13:44:40 UTC
I've just tried that and it didn't help.

Comment 16 Kurt Stam 2011-09-20 15:09:22 UTC
The Guvnor login uses the Seam logon code:

Relevant code:

Identity.instance().getCredentials().setUsername( userName );
Identity.instance().getCredentials().setPassword( password );

try {
   Identity.instance().authenticate();
} catch ( LoginException e ) {
    log.error( "Unable to login.", e );
    return false;
} 

And Seam sets the Subject in Seam context, this works fine:

Subject subject = Identity.instance().getSubject(); 

However ModeShape (in https://github.com/ModeShape/modeshape/blob/master/modeshape-jcr/src/main/java/org/modeshape/jcr/security/JaasProvider.java) does this

Subject subject = Subject.getSubject(AccessController.getContext());

And this is *not* set. 

Anil says: "Subject.getSubject()  is a JDK construct that does not hold well inside Java EE.  The need will be to support call paths with Subject.doAS calls  to actually get the subject. I am unsure if all app servers support this construct. If Modeshape is EE container agnostic, then maybe they need some app server bridges or such to get the subject."

Also note that according to Shane Seam 3 is using PicketLink: "This isn't supported in Seam either - the Subject is simply used as a holder for session-scoped user state.  In Seam 3 it's actually been removed, in favour of the User API classes in PicketLink.  Is that the only way that the Subject may be set in Modeshape?  (I've actually been using Modeshape for a Seam-based project, but haven't had to write any security-related code as yet)." 

With this info it looks like ModeShape will need to add ways to grab the Subject so that it can obtain the username from it (to set in the JCRSession).
 
Hopefully Randall will comment on this matter.

--Kurt

Comment 17 Randall Hauch 2011-09-22 03:18:07 UTC
The fact that the standard Java API to access the Subject from the JAAS LoginContext does *not* work within J2EE and the app server is very troubling, but apparently this is a problem that is well-known in J2EE circles (of which I am clearly not a member).

According to Kurt, the Guvnor code obtains the Subject from the Seam context. If this is true (and acceptable), perhaps the easiest way to fix this is to enhance ModeShape to define an additional JCR Credentials class that allows this Subject to be passed into ModeShape. This new Credentials class should then be used in J2EE applications that use ModeShape with JAAS security.

I still have not heard back from Anil or Shane as to the "proper" way to grab the Subject. If there's no other way than the Seam context, we may have to add the new Credentials implementation.

Comment 18 Randall Hauch 2011-09-22 03:19:17 UTC
I don't see a way to add a link to a JIRA issue, but I've created https://issues.jboss.org/browse/MODE-1270 to track this issue in ModeShape. It is currently prioritized as a blocker.

Comment 19 Randall Hauch 2011-09-22 03:20:12 UTC
I don't see a way to add a link to a JIRA issue, but I've created https://issues.jboss.org/browse/MODE-1270 to track this issue in ModeShape. It is currently prioritized as a blocker.

Comment 20 Randall Hauch 2011-09-22 13:28:09 UTC
Anil got back to me with the suggestion:

1) Add a 'provided' dependency on:

<dependency>
<groupId>org.jboss.spec.javax.security.jacc</groupId>
<artifactId>jboss-jacc-api_1.4_spec</artifactId>
<version>1.0.0.Final</version>
<scope>provided</scope>
</dependency>

2) Change the ModeShape JAAS authorization provider implementation to look for the Subject as it currently does, but if it is null (as is the case when deployed into a J2EE container like JBoss AS/EAP) then try to use the JACC API (if it is available; thus the 'provided' dependency scope) to access the Subject. According to Anil, the following "is a JACC mandated construct.  JACC is part of all EE4+ app servers.  We support this in JBAS. Guessing other app servers do too.  Most of AS customers use this construct."

import javax.security.auth.Subject;
import javax.security.jacc.PolicyContext;
import javax.security.jacc.PolicyContextException;

/** The JACC PolicyContext key for the current Subject */
private static final String SUBJECT_CONTEXT_KEY = "javax.security.auth.Subject.container";
Subject caller = (Subject) PolicyContext.getContext(SUBJECT_CONTEXT_KEY);

Comment 21 Kurt Stam 2011-09-27 18:30:51 UTC
Added the fix to the master:
https://github.com/droolsjbpm/guvnor/commit/629534cc70d8600e47228ca1144a69cc2cea6823#commitcomment-614859

This also required an update from ModeShape, so that it reads the JBoss Security context. Randall, maybe you add the link to your commit?

Comment 22 Kurt Stam 2011-09-27 18:34:06 UTC
Created attachment 525187 [details]
patch to set the security context

patch has been committed to the guvnor master branch

Comment 23 Randall Hauch 2011-09-27 18:42:37 UTC
The ModeShape change was already committed to the '2.5.x' branch, which is being used by SOA-P and BRMS, and to the 'master' branch. For details, see MODE-1270. These are the changes that were made to find the JAAS Subject using the JACC API when running within a J2EE container: https://github.com/ModeShape/modeshape/pull/198

Comment 24 Randall Hauch 2011-09-27 18:44:31 UTC
BTW, the above reference pull-request was committed on the '2.5.x' branch with this commit: https://github.com/ModeShape/modeshape/commit/64bbca4b72024b3f9009eae7bb4f75d0808317cb

Comment 25 Lukáš Petrovický 2011-09-30 08:57:49 UTC
VERIFIED on JBoss containers. It will not work with neither EWS and WAS.

Comment 26 lcarlon 2011-10-03 23:49:42 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
When using JAAS authentication and no credentials were supplied, ModeShape's Repository.login(...) methods resulted in a session that did not contain the proper user ID. This issue was resolved by adjusted the JAAS authentication  provider to work within J2EE containers.

Comment 27 Jiri Locker 2011-10-04 15:33:26 UTC
Ignore comment 25, some configuration steps were missed when verifying the fix manually and Guvnor was still running with Jackrabbit repository. Therefore, it appeared as the bug had gone.

Automated tests revealed the bug is still present. Reopening this one. The technical note should be updated.

Comment 28 Kurt Stam 2011-10-04 15:36:41 UTC
Jiri, I was asked to commit the fix to the guvnor trunk only. So unless you are building with the trunk it will still be broken.

Comment 29 lcarlon 2011-10-05 04:11:16 UTC
    Technical note updated. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    Diffed Contents:
@@ -1 +1 @@
-When using JAAS authentication and no credentials were supplied, ModeShape's Repository.login(...) methods resulted in a session that did not contain the proper user ID. This issue was resolved by adjusted the JAAS authentication  provider to work within J2EE containers.+When using JAAS authentication and no credentials are supplied, ModeShape's Repository.login(...) methods result in a session that does not contain the proper user ID. <!-- This issue was resolved by adjusted the JAAS authentication  provider to work within J2EE containers. -->

Comment 30 Jiri Locker 2012-03-07 12:41:37 UTC
This issue still occurs in BRMS 5.3.0 ERx releases. Maybe the fix has not made it to the current Guvnor branch?

Comment 31 Petr Široký 2012-03-21 12:21:26 UTC
*** Bug 724683 has been marked as a duplicate of this bug. ***

Comment 33 JBoss JIRA Server 2013-10-24 09:20:26 UTC
Randall Hauch <rhauch> updated the status of jira MODE-1270 to Closed


Note You need to log in before you can comment on or make changes to this bug.