use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class DefaultRecordableEventDescriptorManager method getDescriptorsFromWiki.
private List<RecordableEventDescriptor> getDescriptorsFromWiki(String wikiId) throws ComponentLookupException {
Namespace namespace = new WikiNamespace(wikiId);
ComponentManager wikiComponentManager = componentManagerManager.getComponentManager(namespace.serialize(), false);
if (wikiComponentManager == null) {
return Collections.emptyList();
}
List<RecordableEventDescriptor> descriptors = new ArrayList<>();
descriptors.addAll(wikiComponentManager.getInstanceList(RecordableEventDescriptor.class));
descriptors.addAll(wikiComponentManager.getInstanceList(UntypedRecordableEventDescriptor.class));
return descriptors;
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class DefaultPresentationBuilder method buildPresentationXDOM.
/**
* Parses the given HTML text into an XDOM tree.
*
* @param html the HTML text to parse
* @param targetDocumentReference specifies the document where the presentation will be imported; we use the target
* document reference to get the syntax of the target document and to set the {@code BASE} meta data on
* the created XDOM
* @return a XDOM tree
* @throws OfficeImporterException if parsing the given HTML fails
*/
protected XDOM buildPresentationXDOM(String html, DocumentReference targetDocumentReference) throws OfficeImporterException {
try {
ComponentManager contextComponentManager = this.contextComponentManagerProvider.get();
String syntaxId = this.documentAccessBridge.getTranslatedDocumentInstance(targetDocumentReference).getSyntax().toIdString();
BlockRenderer renderer = contextComponentManager.getInstance(BlockRenderer.class, syntaxId);
Map<String, String> galleryParameters = Collections.emptyMap();
ExpandedMacroBlock gallery = new ExpandedMacroBlock("gallery", galleryParameters, renderer, false, contextComponentManager);
gallery.addChild(this.xhtmlParser.parse(new StringReader(html)));
XDOM xdom = new XDOM(Collections.singletonList((Block) gallery));
// Make sure (image) references are resolved relative to the target document reference.
xdom.getMetaData().addMetaData(MetaData.BASE, entityReferenceSerializer.serialize(targetDocumentReference));
return xdom;
} catch (Exception e) {
throw new OfficeImporterException("Failed to build presentation XDOM.", e);
}
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class XWikiAuthentication method authenticate.
@Override
public boolean authenticate(Request request, Response response) {
/*
* Browser authentication resource is a special resource that allows to trigger the authentication dialog box in
* web browsers
*/
if (request.getResourceRef().getPath().endsWith(BrowserAuthenticationResource.URI_PATTERN)) {
return super.authenticate(request, response);
}
ComponentManager componentManager = (ComponentManager) getContext().getAttributes().get(Constants.XWIKI_COMPONENT_MANAGER);
XWikiContext xwikiContext = Utils.getXWikiContext(componentManager);
XWiki xwiki = Utils.getXWiki(componentManager);
DocumentReferenceResolver<String> resolver;
EntityReferenceSerializer<String> serializer;
try {
resolver = componentManager.getInstance(DocumentReferenceResolver.TYPE_STRING, "current");
serializer = componentManager.getInstance(EntityReferenceSerializer.TYPE_STRING);
} catch (ComponentLookupException e1) {
return false;
}
/* By default set XWiki.Guest as the user that is sending the request. */
xwikiContext.setUserReference(null);
/*
* After performing the authentication we should add headers to the response to allow applications to verify if
* the authentication is still valid We are also adding the XWiki version at the same moment.
*/
Series<Header> responseHeaders = (Series<Header>) response.getAttributes().get(HeaderConstants.ATTRIBUTE_HEADERS);
if (responseHeaders == null) {
responseHeaders = new Series<>(Header.class);
response.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, responseHeaders);
}
responseHeaders.add("XWiki-User", serializer.serialize(xwikiContext.getUserReference()));
responseHeaders.add("XWiki-Version", xwikiContext.getWiki().getVersion());
// Try with standard XWiki auth
try {
XWikiUser xwikiUser = xwiki.checkAuth(xwikiContext);
if (xwikiUser != null) {
// Make sure the user is in the context
xwikiContext.setUserReference(resolver.resolve(xwikiUser.getUser()));
getLogger().fine(String.format("Authenticated as '%s'.", xwikiUser.getUser()));
// the user has changed so we need to reset the header
responseHeaders.set("XWiki-User", serializer.serialize(xwikiContext.getUserReference()));
return true;
}
} catch (XWikiException e) {
getLogger().log(Level.WARNING, "Exception occurred while authenticating.", e);
}
// Falback on restlet auth
return super.authenticate(request, response);
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class XWikiRestletJaxRsApplication method createInboundRoot.
@Override
public Restlet createInboundRoot() {
// Create the JAX-RS application and add it to the main Restlet JAX-RS application
add(this.jaxrsApplication);
// Create the root restlet. This basically sets up a chain: setup/cleanup filter -> authentication filter ->
// router
XWikiSetupCleanupFilter setupCleanupFilter = new XWikiSetupCleanupFilter();
XWikiAuthentication xwikiAuthentication = new XWikiAuthentication(getContext());
ComponentManager componentManager = (ComponentManager) getContext().getAttributes().get(Constants.XWIKI_COMPONENT_MANAGER);
xwikiAuthentication.setVerifier(new XWikiSecretVerifier(getContext(), componentManager));
// Create a router for adding resources
Router router = new Router();
router.attach(BrowserAuthenticationResource.URI_PATTERN, BrowserAuthenticationResource.class);
router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
// Add to the router the restlet generated by the JAX-RS application which takes care of dispatching requests to
// JAX-RS resources
Restlet jaxRsRoot = super.createInboundRoot();
// Add support for media query parameter for selecting the media type
getTunnelService().setEnabled(true);
getMetadataService().addCommonExtensions();
getTunnelService().setQueryTunnel(true);
router.attach(jaxRsRoot);
// Build the actual chain
setupCleanupFilter.setNext(xwikiAuthentication);
xwikiAuthentication.setNext(router);
// Return the setup/cleanup filter (the entry point for the chain) as the root restlet
return setupCleanupFilter;
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class ComponentsObjectFactory method getInstance.
@Override
public <T> T getInstance(Class<T> clazz) throws InstantiateException {
try {
ComponentManager componentManager = this.componentManagerProvider.get();
// Use the component manager to lookup the class. This ensure that injections are properly executed.
XWikiRestComponent component = componentManager.getInstance(XWikiRestComponent.class, clazz.getName());
// JAX-RS resources and providers must be declared as components whose hint is the FQN of the class
// implementing it. This is needed because of they are looked up using the FQN as the hint.
ComponentDescriptor<XWikiRestComponent> componentDescriptor = componentManager.getComponentDescriptor(XWikiRestComponent.class, clazz.getName());
// Retrieve the list of releasable components from the execution context. This is used to store component
// instances that need to be released at the end of the request.
ExecutionContext executionContext = this.execution.getContext();
List<XWikiRestComponent> releasableComponentReferences = (List<XWikiRestComponent>) executionContext.getProperty(Constants.RELEASABLE_COMPONENT_REFERENCES);
if (releasableComponentReferences == null) {
releasableComponentReferences = new ArrayList<>();
executionContext.setProperty(Constants.RELEASABLE_COMPONENT_REFERENCES, releasableComponentReferences);
}
// Only add the components that have a per-lookup instantiation strategy.
if (componentDescriptor.getInstantiationStrategy() == ComponentInstantiationStrategy.PER_LOOKUP) {
releasableComponentReferences.add(component);
}
// component hint to the actual fully qualified name of the Java class.
return (T) component;
} catch (ComponentLookupException e) {
throw new InstantiateException(e);
}
}
Aggregations