use of org.xwiki.model.reference.WikiReference 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 org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class XWikiAttachment method loadAttachmentContent.
public void loadAttachmentContent(XWikiContext xcontext) throws XWikiException {
if (this.content == null) {
WikiReference currentWiki = xcontext.getWikiReference();
try {
// Make sure we work on the attachment's wiki
WikiReference attachmentWiki = getReference().getDocumentReference().getWikiReference();
if (attachmentWiki != null) {
xcontext.setWikiReference(attachmentWiki);
}
try {
XWikiAttachmentStoreInterface store = getAttachmentContentStore(xcontext);
store.loadAttachmentContent(this, xcontext, true);
} catch (ComponentLookupException e) {
throw new XWikiException("Failed to find store for attachment [" + getReference() + "]", e);
}
} finally {
if (currentWiki != null) {
xcontext.setWikiReference(currentWiki);
}
}
}
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class AbstractMandatoryDocumentInitializer method initialize.
@Override
public void initialize() throws InitializationException {
// If a local reference was specified but isMainWikiOnly() is true, then convert to a main wiki reference.
if (this.reference != null && this.reference.extractReference(EntityType.WIKI) == null && isMainWikiOnly()) {
synchronized (this) {
if (this.reference.extractReference(EntityType.WIKI) == null) {
// Convert to main wiki reference
EntityReference mainWikiEntityReference = this.resolver.resolve(this.reference, new WikiReference(this.wikiDescriptorManager.getMainWikiId()));
this.reference = mainWikiEntityReference;
}
}
}
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class XWikiAction method handleRedirectObject.
/**
* Redirect the user to an other location if the document holds an XWiki.RedirectClass instance (used when a
* document is moved).
*
* @param context the XWiki context
* @return either or not a redirection have been sent
* @throws XWikiException if error occurs
* @since 8.0RC1
* @since 7.4.2
*/
protected boolean handleRedirectObject(XWikiContext context) throws XWikiException {
WikiReference wikiReference = context.getWikiReference();
// Look if the document has a redirect object
XWikiDocument doc = context.getDoc();
BaseObject redirectObj = doc.getXObject(new DocumentReference("RedirectClass", new SpaceReference("XWiki", wikiReference)));
if (redirectObj == null) {
return false;
}
// Get the location
String location = redirectObj.getStringValue("location");
if (StringUtils.isBlank(location)) {
return false;
}
// Resolve the location to get a reference
DocumentReferenceResolver<String> resolver = Utils.getComponent(DocumentReferenceResolver.TYPE_STRING);
EntityReference locationReference = resolver.resolve(location, wikiReference);
// Get the type of the current target
ResourceReference resourceReference = Utils.getComponent(ResourceReferenceManager.class).getResourceReference();
EntityResourceReference entityResource = (EntityResourceReference) resourceReference;
EntityReference entityReference = entityResource.getEntityReference();
// If the entity is inside a document, compute the new entity with the new document part.
if (entityReference.getType().ordinal() > EntityType.DOCUMENT.ordinal()) {
EntityReference parentDocument = entityReference.extractReference(EntityType.DOCUMENT);
locationReference = entityReference.replaceParent(parentDocument, locationReference);
}
// Get the URL corresponding to the location
// Note: the anchor part is lost in the process, because it is not sent to the server
// (see: http://stackoverflow.com/a/4276491)
String url = context.getWiki().getURL(locationReference, context.getAction(), context.getRequest().getQueryString(), null, context);
// Send the redirection
try {
context.getResponse().sendRedirect(url);
} catch (IOException e) {
throw new XWikiException("Failed to redirect.", e);
}
return true;
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class XWikiTest method testGetDocumentWithEntityReference.
public void testGetDocumentWithEntityReference() throws Exception {
Mock mockStore = registerMockComponent(XWikiStoreInterface.class);
this.xwiki.setStore((XWikiStoreInterface) mockStore.proxy());
mockStore.expects(atLeastOnce()).method("loadXWikiDoc").with(NOT_NULL, same(getContext())).will(new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
return invocation.parameterValues.get(0);
}
});
DocumentReference documentReference = new DocumentReference("wiki", "Main", "WebHome");
WikiDescriptor mockWikiDescriptor = new WikiDescriptor("wiki", "wiki");
mockWikiDescriptor.setMainPageReference(documentReference);
this.mockWikiDescriptorManager.stubs().method("getById").with(same("wiki")).will(returnValue(mockWikiDescriptor));
assertEquals(documentReference, this.xwiki.getDocument(new WikiReference("wiki"), getContext()).getDocumentReference());
assertEquals(documentReference, this.xwiki.getDocument(new ObjectReference("object", documentReference), getContext()).getDocumentReference());
}
Aggregations