use of com.xpn.xwiki.user.api.XWikiUser 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.user.api.XWikiUser in project xwiki-platform by xwiki.
the class DefaultXWikiContextInitializer method authenticate.
private void authenticate(XWikiContext xcontext) throws XWikiException {
// By default set guest as the user that is sending the request.
xcontext.setUserReference(null);
XWikiUser xwikiUser = xcontext.getWiki().checkAuth(xcontext);
if (xwikiUser != null) {
SpaceReference defaultUserSpace = new SpaceReference(XWiki.SYSTEM_SPACE, new WikiReference(xcontext.getWikiId()));
DocumentReference userReference = this.explicitResolver.resolve(xwikiUser.getUser(), defaultUserSpace);
xcontext.setUserReference(XWikiRightService.GUEST_USER.equals(userReference.getName()) ? null : userReference);
this.logger.debug("Authenticated as [{}].", xwikiUser.getUser());
}
}
use of com.xpn.xwiki.user.api.XWikiUser in project xwiki-platform by xwiki.
the class UserTest method testGetEmail.
public void testGetEmail() throws Exception {
Mock mockXWiki = mock(XWiki.class);
getContext().setWiki((XWiki) mockXWiki.proxy());
XWikiDocument doc = new XWikiDocument(new DocumentReference("xwiki", "XWiki", "Admin"));
BaseClass userClass = new BaseClass();
userClass.addTextField("email", "email address", 20);
mockXWiki.stubs().method("getXClass").will(returnValue(userClass));
BaseObject userObj = doc.newXObject(new DocumentReference("xwiki", "XWiki", "XWikiUsers"), getContext());
userObj.setStringValue("email", "admin@mail.com");
mockXWiki.stubs().method("getDocument").will(returnValue(doc));
User u = new User(null, null);
assertNull(u.getEmail());
XWikiUser xu = new XWikiUser("XWiki.Admin");
u = new User(xu, getContext());
assertEquals("admin@mail.com", u.getEmail());
}
use of com.xpn.xwiki.user.api.XWikiUser in project xwiki-platform by xwiki.
the class XWikiContextTest method testAnonymousUser.
@Test
public void testAnonymousUser() {
getContext().setMainXWiki("wiki");
getContext().setWikiId("wiki");
getContext().setUserReference(null);
Assert.assertNull(getContext().getUserReference());
Assert.assertEquals("XWiki.XWikiGuest", getContext().getUser());
Assert.assertEquals("XWiki.XWikiGuest", getContext().getLocalUser());
Assert.assertNull(getContext().getXWikiUser());
getContext().setWikiId("wiki2");
Assert.assertNull(getContext().getUserReference());
Assert.assertEquals("XWiki.XWikiGuest", getContext().getUser());
Assert.assertEquals("XWiki.XWikiGuest", getContext().getLocalUser());
Assert.assertNull(getContext().getXWikiUser());
getContext().setUser(XWikiRightService.GUEST_USER_FULLNAME);
Assert.assertEquals(new XWikiUser(XWikiRightService.GUEST_USER_FULLNAME), getContext().getXWikiUser());
Assert.assertNull(getContext().getUserReference());
getContext().setUser(XWikiRightService.GUEST_USER);
Assert.assertEquals(new XWikiUser(XWikiRightService.GUEST_USER), getContext().getXWikiUser());
Assert.assertNull(getContext().getUserReference());
}
use of com.xpn.xwiki.user.api.XWikiUser in project xwiki-platform by xwiki.
the class UserTest method testIsUserInGroupDoesNotThrowNPE.
/**
* Checks that XWIKI-2040 remains fixed.
*/
public void testIsUserInGroupDoesNotThrowNPE() {
User u = new User(null, null);
assertFalse(u.isUserInGroup("XWiki.InexistentGroupName"));
XWikiUser xu = new XWikiUser(null);
u = new User(xu, null);
assertFalse(u.isUserInGroup("XWiki.InexistentGroupName"));
XWikiContext c = new XWikiContext();
u = new User(xu, c);
assertFalse(u.isUserInGroup("XWiki.InexistentGroupName"));
}
Aggregations