Hi Marius,
On 04/03/2011 13:43 PM, Marius Dumitru Florea wrote
Hi Marco,
On 04/01/2011 12:53 PM, Marco Antonio González wrote:
Hi All,
What I'm trying to get is:
User logs into XWiki through CAS Auth, I also have a webservice to get remote user
credentials (where a User can be in many Groups), and some rights > over that groups
(only membership), so what I want is to:
- Create a Space for each remote "Group" (named "remoteGroupSpaceX"),
- Create a Group in XWiki (named "remoteGroupX")
- Assign "edit" right to the "remoteGroupX" over
"remoteGroupSpaceX".
I already have created the Space (/xwiki/bin/view/remoteGroupSpace/), the Group
(XWiki.remoteGroupX) and what I'm trying to get is the XWikiRights from the
remoteGroup, but I can't find where can I get the XWikiRights object.
I tried to duplicate (through XWikiDocument.duplicate(EntityReference) method) an
existing group (XWikiAdminGroup) and search where is the XWikiRight object, and then
change the "levels" field to "edit", and saving the remoteGroup with
the modified rights, but the Edit button is still there.
Here's a sample of my code:
private void assignRights(String spaceName, String groupName, String rights, XWikiContext
context) throws XWikiException {
// Prepare EntityReferences
WikiReference wikiRef = new WikiReference("XWiki");
Are you sure you have a wiki named "XWiki"? The main wiki is called by
default "xwiki" (lower case). Anyway, you should avoid hard-coding the
name of the main wiki. You should write instead:
Yes, you are right, I "simplified" the code a bit for easier understanding and
made the caps mistake. The current main wiki is 'xwiki' and I get it from
context.getDatabase() method.
context.getMainXWiki() --> for main wiki or,
context.getDatabase() --> for current wiki.
SpaceReference xwikiSpaceRef = new
SpaceReference("XWiki", wikiRef);
SpaceReference remoteSpaceRef = new SpaceReference(spaceName, wikiRef);
DocumentReference refGroup = new DocumentReference(new EntityReference(groupName,
EntityType.DOCUMENT, xwikiSpaceRef));
DocumentReference refRights = new DocumentReference(new
EntityReference("XWikiRights", EntityType.DOCUMENT, remoteSpaceRef));
The above 5 lines are equivalent to this:
DocumentReference refGroup = new
DocumentReference(context.getDatabase(), "XWiki", groupName);
DocumentReference refRights = new
DocumentReference(context.getDatabase(), spaceName, "XWikiRights");
Thanks for the tip!
// Get the XWikiDocument relative to the Group
XWikiDocument docGroup = context.getWiki().getDocument(refGroup, context);
// Get the XWikiRights from the Group
BaseObject groupRights = docGroup.getXObject(refRights);
// Modify rights
groupRights.set("levels", rights, context);
context.getWiki().saveDocument(docGroup, context);
I see 2 mistakes here:
(1) You assume that space level rights are saved on the group document.
You should edit the group document using the object editor and see what
objects it has attached. XWikiRights objects don't have any information
about the target entity (page/space/wiki) because the target entity is
determined based on the document where XWikiRights objects are attached.
So for space rights you should look at the objects attached to
<SpaceName>.WebPreferences page.
On my <SpaceName>.WebPreferences, I only get a XWiki.XWikiGlobalRights object, so I
proceed to change the "levels" field, but anything changes whatever value I put
on it.
(2) In order to retrieve an object from a document you need the class
name/reference, which is the same no matter where the objects are
attached. The class reference fro XWikiRights is xwiki:XWiki.XWikiRights
not xwiki:<SpaceName>.XWikiRights . Now, if I go to the space
administration and edit the user/group rights I get
XWiki.XWikiGlobalRights objects attached to <SpaceName>.WebPreference so
you should use this class instead of XWikiRights.
I would start with this code (which I haven't tested):
----------8<----------
DocumentReference rightsClassRef = new
DocumentReference(context.getMainWiki(), "XWiki",
"XWikiGlobalRights");
context.getMainWiki() must be context.getMainXWiki().
DocumentReference spacePrefsRef = new
DocumentReference(context.getDatabase(), spaceName, "WebPreferences");
// Get the space preferences page, where space level rights are saved.
XWikiDocument spacePrefs = context.getWiki().getDocument(spacePrefsRef,
context);
// Get the XWikiGlobalRights from the space preferences page.
BaseObject spaceRights = spacePrefs.getXObject(rightsClassRef);
// Modify space rights.
spaceRights.set("levels", rights, context);
spaceRights.set("groups", groupName, context);
// Set "1" to allow <rights>, or "0" to deny them.
spaceRights.set("allow", "1", context);
context.getWiki().saveDocument(spacePrefs, context);
---------->8----------
Inspecting the spaceRights.getXObjects(rightsClassRef) I get a treeMap that has one item
for each right, I'll continue testing how to mix allow/deny rights at the same time,
for example allow "edit" and deny "admin".
Thank you,
Hope this helps,
Marius
}
Where:
String spaceName = "remoteGroupSpaceX";
String groupName = "remoteGroupX";
String rights = "edit";
I know about relation between XWikiGlobalRights and XWikiRights and also about rights
priority (Page> Space> Wiki / page.XWikiRights> space.XWikiRights>
wiki.XWikiGlobalRights).
So my plan is:
Everybody has "view" (XWiki.XWikiAllUsers) right in the whole wiki, and only
members of each "remoteGroupX" has "edit" right over their own space
"remoteGroupSpaceX".
I'm a little bit lost with this and I hope any help.
Thank you,
Marco A. Gonzalez
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs