use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class XWikiRightServiceImplTest method testAdminAccessLevels.
public void testAdminAccessLevels() throws Exception {
getContext().setWikiId("xwiki");
final XWikiDocument doc = new XWikiDocument(new DocumentReference(getContext().getWikiId(), "Space", "Page"));
final XWikiDocument xwikiPreferences = new XWikiDocument(new DocumentReference(getContext().getWikiId(), "XWiki", "XWikiPreference"));
this.mockGroupService.stubs().method("getAllGroupsReferencesForMember").with(ANYTHING, ANYTHING, ANYTHING, ANYTHING).will(returnValue(Collections.emptyList()));
this.mockXWiki.stubs().method("getDocument").with(eq(doc.getFullName()), ANYTHING).will(returnValue(doc));
this.mockXWiki.stubs().method("getDocument").with(eq(doc.getPrefixedFullName()), ANYTHING).will(returnValue(doc));
this.mockXWiki.stubs().method("getDocument").with(eq(XWIKIPREFERENCES_REFERENCE), ANYTHING).will(returnValue(xwikiPreferences));
this.mockXWiki.stubs().method("getXWikiPreference").with(ANYTHING, ANYTHING, ANYTHING).will(returnValue("false"));
this.mockXWiki.stubs().method("getXWikiPreferenceAsInt").with(ANYTHING, ANYTHING, ANYTHING).will(returnValue(0));
this.mockXWiki.stubs().method("getSpacePreference").with(ANYTHING, ANYTHING, ANYTHING).will(returnValue("false"));
this.mockXWiki.stubs().method("getSpacePreferenceAsInt").with(ANYTHING, ANYTHING, ANYTHING).will(returnValue(0));
BaseObject preferencesObject = new BaseObject();
preferencesObject.setClassName("XWiki.XWikiGlobalRights");
preferencesObject.setStringValue("levels", "admin");
preferencesObject.setIntValue("allow", 1);
preferencesObject.setStringValue("users", getContext().getWikiId() + ":XWiki.Admin");
xwikiPreferences.addXObject(preferencesObject);
assertAccessLevelForAdminUser("login", doc, true);
assertAccessLevelForAdminUser("register", doc, true);
assertAccessLevelForAdminUser("view", doc, true);
assertAccessLevelForAdminUser("edit", doc, true);
assertAccessLevelForAdminUser("delete", doc, true);
assertAccessLevelForAdminUser("admin", doc, true);
assertAccessLevelForAdminUser("programming", doc, true);
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class XWikiRightServiceImplTest method testHasAccessLevelWhithGuestUser.
public void testHasAccessLevelWhithGuestUser() throws XWikiException {
final XWikiDocument doc = new XWikiDocument(new DocumentReference("wiki2", "Space", "Page"));
final XWikiDocument preferences = new XWikiDocument(new DocumentReference("wiki2", "XWiki", "XWikiPreference"));
BaseObject preferencesObject = new BaseObject();
preferencesObject.setClassName("XWiki.XWikiGlobalRights");
preferencesObject.setStringValue("levels", "view");
preferencesObject.setIntValue("allow", 1);
preferences.addXObject(preferencesObject);
this.mockXWiki.stubs().method("getDocument").with(eq(XWIKIPREFERENCES_REFERENCE), ANYTHING).will(new CustomStub("Implements XWiki.getDocument") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
if (!getContext().getWikiId().equals("wiki2")) {
new XWikiDocument(new DocumentReference(getContext().getWikiId(), "XWiki", "XWikiPreference"));
}
return preferences;
}
});
this.mockXWiki.stubs().method("getDocument").with(eq(doc.getPrefixedFullName()), ANYTHING).will(returnValue(doc));
this.mockXWiki.stubs().method("getXWikiPreference").with(eq("authenticate_view"), ANYTHING, ANYTHING).will(returnValue("false"));
this.mockXWiki.stubs().method("getXWikiPreferenceAsInt").with(eq("authenticate_view"), ANYTHING, ANYTHING).will(returnValue(0));
this.mockXWiki.stubs().method("getSpacePreference").with(eq("authenticate_view"), ANYTHING, ANYTHING).will(returnValue("false"));
this.mockXWiki.stubs().method("getSpacePreferenceAsInt").with(eq("authenticate_view"), ANYTHING, ANYTHING).will(returnValue(0));
this.mockGroupService.stubs().method("getAllGroupsReferencesForMember").with(eq(new DocumentReference("xwiki", "XWiki", XWikiRightService.GUEST_USER)), ANYTHING, ANYTHING, ANYTHING).will(returnValue(Collections.emptyList()));
this.mockGroupService.stubs().method("getAllGroupsReferencesForMember").with(eq(new DocumentReference("wiki2", "XWiki", XWikiRightService.GUEST_USER)), ANYTHING, ANYTHING, ANYTHING).will(returnValue(Collections.emptyList()));
getContext().setWikiId("wiki");
assertFalse("Guest has wiew right on the document", this.rightService.hasAccessLevel("view", XWikiRightService.GUEST_USER_FULLNAME, doc.getPrefixedFullName(), true, getContext()));
// direct user rights
preferencesObject.setStringValue("users", XWikiRightService.GUEST_USER_FULLNAME);
getContext().setWikiId("wiki");
assertTrue("Guest does not have right on the document when tested from another wiki", this.rightService.hasAccessLevel("view", XWikiRightService.GUEST_USER_FULLNAME, doc.getPrefixedFullName(), true, getContext()));
getContext().setWikiId(doc.getDatabase());
assertTrue("Guest does not have right on the document when tested from the document wiki", this.rightService.hasAccessLevel("view", XWikiRightService.GUEST_USER_FULLNAME, doc.getPrefixedFullName(), true, getContext()));
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class XWikiRightServiceImplTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
this.rightService = new XWikiRightServiceImpl();
this.mockGroupService = mock(XWikiGroupService.class, new Class[] {}, new Object[] {});
this.mockXWiki = mock(XWiki.class);
this.mockXWiki.stubs().method("getGroupService").will(returnValue(this.mockGroupService.proxy()));
this.mockXWiki.stubs().method("isReadOnly").will(returnValue(false));
this.mockXWiki.stubs().method("getWikiOwner").will(returnValue(null));
this.mockXWiki.stubs().method("getMaxRecursiveSpaceChecks").will(returnValue(0));
this.mockXWiki.stubs().method("getDocument").with(ANYTHING, eq("WebPreferences"), ANYTHING).will(new CustomStub("Implements XWiki.getDocument") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
return new XWikiDocument(new DocumentReference(getContext().getWikiId(), (String) invocation.parameterValues.get(0), "WebPreferences"));
}
});
// Called from MessageToolVelocityContextInitializer.
this.mockXWiki.stubs().method("prepareResources");
getContext().setWiki((XWiki) this.mockXWiki.proxy());
this.user = new XWikiDocument(new DocumentReference("wiki", "XWiki", "user"));
this.user.setNew(false);
getContext().setWikiId(this.user.getWikiName());
BaseObject userObject = new BaseObject();
userObject.setClassName("XWiki.XWikiUser");
this.user.addXObject(userObject);
this.mockXWiki.stubs().method("getDocument").with(eq(this.user.getPrefixedFullName()), ANYTHING).will(returnValue(this.user));
this.group = new XWikiDocument(new DocumentReference("wiki", "XWiki", "group"));
this.group.setNew(false);
getContext().setWikiId(this.group.getWikiName());
BaseObject groupObject = new BaseObject();
groupObject.setClassName("XWiki.XWikiGroups");
groupObject.setStringValue("member", this.user.getFullName());
this.group.addXObject(groupObject);
this.mockXWiki.stubs().method("getDocument").with(eq(this.group.getPrefixedFullName()), ANYTHING).will(returnValue(this.group));
this.group2 = new XWikiDocument(new DocumentReference("wiki2", "XWiki", "group2"));
this.group2.setNew(false);
getContext().setWikiId(this.group2.getWikiName());
BaseObject group2Object = new BaseObject();
group2Object.setClassName("XWiki.XWikiGroups");
group2Object.setStringValue("member", this.user.getPrefixedFullName());
this.group2.addXObject(groupObject);
this.mockXWiki.stubs().method("getDocument").with(eq(this.group2.getPrefixedFullName()), ANYTHING).will(returnValue(this.group2));
this.mockGroupService.stubs().method("getAllGroupsReferencesForMember").with(eq(this.user.getDocumentReference()), ANYTHING, ANYTHING, ANYTHING).will(new CustomStub("Implements XWikiGroupService.getAllGroupsReferencesForMember") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
XWikiContext context = (XWikiContext) invocation.parameterValues.get(3);
if (context.getWikiId().equals(group.getWikiName())) {
return Collections.singleton(group.getDocumentReference());
} else if (context.getWikiId().equals(group2.getWikiName())) {
return Collections.singleton(group2.getDocumentReference());
} else {
return Collections.emptyList();
}
}
});
this.mockGroupService.stubs().method("getAllGroupsReferencesForMember").with(eq(this.group.getDocumentReference()), ANYTHING, ANYTHING, ANYTHING).will(returnValue(Collections.emptyList()));
this.mockGroupService.stubs().method("getAllGroupsReferencesForMember").with(eq(this.group2.getDocumentReference()), ANYTHING, ANYTHING, ANYTHING).will(returnValue(Collections.emptyList()));
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class XWikiRightServiceImplTest method testDeniesAccessLevelForCreateIfDocumentDeniesEdit.
// This is currently a proof-of-behavior test to show that if a document prevents you from editing
// it, calling hasAccessLevel('create') on that document will also fail.
// Changing this behavior is proposed here: http://lists.xwiki.org/pipermail/devs/2013-March/053802.html
// See also: https://jira.xwiki.org/browse/XWIKI-8892
public void testDeniesAccessLevelForCreateIfDocumentDeniesEdit() throws Exception {
getContext().setWikiId(this.user.getWikiName());
final XWikiDocument doc = new XWikiDocument(new DocumentReference(this.user.getWikiName(), "Space", "Page"));
// Set the creator to be the user we test against since creator should get delete rights
BaseObject xo = new BaseObject();
xo.setClassName("XWiki.XWikiRights");
xo.setStringValue("levels", "edit");
xo.setStringValue("users", user.getFullName());
xo.setIntValue("allow", 0);
doc.addXObject(xo);
DocumentReference dr = new DocumentReference(this.user.getWikiName(), "XWiki", "XWikiPreferences");
this.mockXWiki.stubs().method("getDocument").with(isA(EntityReference.class), ANYTHING).will(returnValue(new XWikiDocument(new DocumentReference(dr))));
this.mockXWiki.stubs().method("getDocument").with(eq(doc.getPrefixedFullName()), ANYTHING).will(returnValue(doc));
this.mockXWiki.stubs().method("getXWikiPreference").with(eq("authenticate_edit"), ANYTHING, ANYTHING).will(returnValue(""));
this.mockXWiki.stubs().method("getXWikiPreferenceAsInt").with(eq("authenticate_edit"), ANYTHING, ANYTHING).will(returnValue(0));
this.mockXWiki.stubs().method("getSpacePreference").with(eq("authenticate_edit"), ANYTHING, ANYTHING).will(returnValue(""));
this.mockXWiki.stubs().method("getSpacePreferenceAsInt").with(eq("authenticate_edit"), ANYTHING, ANYTHING).will(returnValue(0));
this.mockXWiki.stubs().method("checkAuth").with(ANYTHING).will(returnValue(new XWikiUser(this.user.getFullName())));
this.mockXWiki.stubs().method("getRightService").will(returnValue(this.rightService));
assertFalse("Should not have edit permission on document if it is denied at a document level", this.rightService.checkAccess("edit", doc, getContext()));
assertFalse("Should not have create permission on document if it is denied at a document level", this.rightService.checkAccess("create", doc, getContext()));
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class CurrentUserPropertyResourceImpl method buildResponse.
private Response buildResponse(XWikiDocument document, String propertyName, XWikiContext xcontext) {
BaseObject baseObject = document.getXObject(USER_REFERENCE);
Object object = this.factory.toRestObject(this.uriInfo.getBaseUri(), new Document(document, xcontext), baseObject, false, false);
for (Property p : object.getProperties()) {
if (p.getName().equals(propertyName)) {
return Response.status(Status.ACCEPTED).entity(p).build();
}
}
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
}
Aggregations