use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class ConfiguredReputationAlgorithmProvider method get.
/**
* Retrieve an instance of the desired ReputationAlorithm (default/simple/custom).
*
* @param documentRef documentRef the document to which the ratings are associated to
* @return the reputation algorithm selected by looking at the current configuration settings
*/
@Override
public ReputationAlgorithm get(DocumentReference documentRef) {
String defaultAlgorithmHint = "default";
String reputationAlgorithmHint = getXWiki().Param(RatingsManager.RATINGS_CONFIG_PARAM_PREFIX + RatingsManager.RATINGS_CONFIG_FIELDNAME_REPUTATIONALGORITHM_HINT, defaultAlgorithmHint);
try {
XWikiDocument configurationDocument = ratingsConfiguration.getConfigurationDocument(documentRef);
if (configurationDocument != null && !configurationDocument.isNew() && configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE) != null) {
BaseProperty prop = (BaseProperty) configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE).get(RatingsManager.RATINGS_CONFIG_CLASS_FIELDNAME_REPUTATION_ALGORITHM_HINT);
String hint = (prop == null) ? null : (String) prop.getValue();
if (hint == "custom") {
prop = (BaseProperty) configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE).get(RatingsManager.RATINGS_CONFIG_CLASS_FIELDNAME_REPUTATION_CUSTOM_ALGORITHM);
hint = (prop == null) ? null : (String) prop.getValue();
}
reputationAlgorithmHint = (hint == null) ? reputationAlgorithmHint : hint;
}
} catch (Exception e) {
logger.error("Cannot read reputation algorithm config", e);
}
// if the reputation algorithm hint is a page let's try to get the instance from groovy
if (reputationAlgorithmHint.contains(".")) {
try {
ReputationAlgorithmGroovy reputationInstance = (ReputationAlgorithmGroovy) getXWiki().parseGroovyFromPage(reputationAlgorithmHint, getXWikiContext());
if (reputationInstance != null) {
reputationInstance.setComponentManager(componentManager);
reputationInstance.setExecution(execution);
reputationInstance.setXWikiContext(getXWikiContext());
reputationInstance.setRatingsManager(ratingsManagerProvider.get(documentRef));
return reputationInstance;
}
} catch (Throwable e) {
logger.error("Cannot instanciate Reputation algorithm from page " + reputationAlgorithmHint, e);
}
}
try {
return componentManager.getInstance(ReputationAlgorithm.class, reputationAlgorithmHint);
} catch (ComponentLookupException e) {
// TODO Auto-generated catch block
logger.error("Error loading ratings manager component for hint " + reputationAlgorithmHint, e);
try {
return componentManager.getInstance(ReputationAlgorithm.class, defaultAlgorithmHint);
} catch (ComponentLookupException e1) {
return null;
}
}
}
use of org.xwiki.component.manager.ComponentLookupException 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.ComponentLookupException in project xwiki-platform by xwiki.
the class ResourceReferenceHandlerServlet method cleanupComponents.
private void cleanupComponents() throws ServletException {
Container container;
try {
container = this.rootComponentManager.getInstance(Container.class);
} catch (ComponentLookupException e) {
throw new ServletException("Failed to locate a Container component", e);
}
Execution execution;
try {
execution = this.rootComponentManager.getInstance(Execution.class);
} catch (ComponentLookupException e) {
throw new ServletException("Failed to locate a Execution component", e);
}
// We must ensure we clean the ThreadLocal variables located in the Container and Execution components as
// otherwise we will have a potential memory leak.
container.removeRequest();
container.removeResponse();
container.removeSession();
execution.removeContext();
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class ResourceReferenceHandlerServlet method handleResourceReference.
private void handleResourceReference(ResourceReference resourceReference) throws ServletException {
ResourceReferenceHandlerManager<?> resourceReferenceHandlerManager;
try {
Type role = new DefaultParameterizedType(null, ResourceReferenceHandlerManager.class, ResourceType.class);
resourceReferenceHandlerManager = this.rootComponentManager.getInstance(role);
} catch (ComponentLookupException e) {
// Should not happen since a Resource Reference Handler should always exist on the system.
throw new ServletException("Failed to locate a Resource Reference Handler Manager component", e);
}
try {
resourceReferenceHandlerManager.handle(resourceReference);
} catch (ResourceReferenceHandlerException e) {
throw new ServletException(String.format("Failed to handle Resource Reference [%s]", resourceReference), e);
}
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class ResourceReferenceHandlerServlet method getResourceReferenceResolver.
private ResourceReferenceResolver<ExtendedURL> getResourceReferenceResolver() throws ServletException {
ResourceReferenceResolver<ExtendedURL> urlResolver;
try {
Type role = new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class);
urlResolver = this.rootComponentManager.getInstance(role);
} catch (ComponentLookupException e) {
// Should not happen since a URL provider should exist on the system.
throw new ServletException("Failed to locate an ExtendedURL Resource Reference Resolver component", e);
}
return urlResolver;
}
Aggregations