Bug 841625

Summary: subject argument is removed from SubjectManager.findSubjectsByCriteria() which doesn't allow to use the method for specific (logged) in user
Product: [Other] RHQ Project Reporter: Armine Hovsepyan <ahovsepy>
Component: CLIAssignee: RHQ Project Maintainer <rhq-maint>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: urgent Docs Contact:
Priority: high    
Version: 4.5CC: hrupp, lkrejci, mfoley
Target Milestone: ---   
Target Release: RHQ 4.10   
Hardware: x86_64   
OS: Linux   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-04-23 08:29:42 EDT Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Armine Hovsepyan 2012-07-19 11:45:07 EDT
Description of problem:
subject argument is removed from SubjectManager.findSubjectsByCriteria() which doesn't allow to use the method for newly logged in user

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Log in with rhqadmin from cli
2. create test role and testuser with some permissions
3. Call SubjectManager.login() for testuser and save the subject
4. Call SubjectManager.findSubjectsByCriteria() with saved subject
Actual results:
org.mozilla.javascript.EvaluatorException: Can't find method $Proxy29.findSubjectsByCriteria(org.rhq.core.domain.auth.Subject,org.rhq.core.domain.criteria.SubjectCriteria). (<Unknown source>#166)

Expected results:
It is possible to get all resources using the newly loged in user

Additional info:
it is needed for permissions testing.
please ping me for the whole test case.
Comment 1 Lukas Krejci 2012-07-19 12:07:18 EDT
This is not specific to the SubjectManager.findSubjectByCriteria method.

When we are generating our scripting API, we generated new methods from the remote API methods by removing the first "Subject" parameter from them and then at runtime supplating that argument with the currently logged in user.

I.e. SubjectManager.findSubjectByCriteria(criteria) would be translated automagically into SubjectManager.findSubjectByCriteria(subject, criteria) where "subject" is the currently logged in user in the CLI.

Now in the past we actually kept the original methods (i.e. the ones with Subject as their first parameter) in the scripting API and only added the new "simplified" methods. We then explicitly *hid* the original methods from code completion so that the user didn't have an idea about their existence.

After the refactoring brought forth to support the script modularity, the original methods are no longer available on the scripting APIs and the code completion doesn't have to "hide" anything.

But for the script to be able to act as two users simultaneously is potentially useful feature - as Armine showed.

I am not fond of bringing the original methods back and adding the "special handling" back to the code completion - that is (and always has been) just an ugly hack.

So my proposal is (after getting this idea from Jay) to introduce a new property on the "rhq" implicit object called "subjectOverride".

When this property would be null, the currently logged in user would be used to do the remote calls. If the property would not be null, the subject assigned to this property would be used to do the remote calls regardless of the current logged in user for all the remote API calls.

So in the above example one would:

cli> rhq.login("rhqadmin", password)
cli> .... create test role and testuser with some permissions
cli> var testUserSubject = SubjectManager.login("testuser", password)
cli> rhq.subjectOverride = testUserSubject
cli> SubjectManager.findSubjectsByCriteria(crit)

this would call the last line with the testUserSubject as the subject.
Comment 2 Mike Foley 2012-07-20 13:47:41 EDT
targetting for RH 4.5.  existing scripts need to continue to work after the fix.  

based on lukas' comments it is not related to JON.
Comment 3 Mike Foley 2013-11-21 13:08:24 EST
This bug blocks about 15 automated CLI tests which have needed to be disabled because of this bug.  so because these tests are not running, the automation which is not running could be masking additional issues which are not currently being detected.  

increasing the priority and targetting for an RHQ release
Comment 4 Mike Foley 2013-11-21 13:26:21 EST
is this a breaking change for existing CLI scripts that customers may have in JON 3.2?
Comment 5 Lukas Krejci 2013-11-21 13:29:55 EST
The automation scripts were exploiting an undocumented behavior of the previous implementation of the CLI remoting.

This has been chagend to strictly conform to the documented behavior and the undocumented methods are no longer available.
Comment 6 Heiko W. Rupp 2013-12-09 04:57:24 EST
After Lukas' last comment I think this is solved and could be closed?
Comment 7 Armine Hovsepyan 2013-12-09 08:15:46 EST
@Libor Zoubek added updated existing tests  to run those without a need of subject param. Taking into account comment from Lukas, we can close this bug as "won't fix" or "not a bug".
Comment 8 Heiko W. Rupp 2014-04-23 08:29:42 EDT
Bulk closing of 4.10 issues.

If an issue is not solved for you, please open a new BZ (or clone the existing one) with a version designator of 4.10.