use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class AbstractUsersAndGroupsClassPropertyValuesProvider method getValueFromQueryResult.
@Override
protected PropertyValue getValueFromQueryResult(Object result, T propertyDefinition) {
PropertyValue value = super.getValueFromQueryResult(result, propertyDefinition);
if (value != null && value.getValue() instanceof DocumentReference) {
DocumentReference documentReference = (DocumentReference) value.getValue();
WikiReference wikiReference = propertyDefinition.getOwnerDocument().getDocumentReference().getWikiReference();
// Serialize the user/group reference relative to the wiki were the property is defined.
value.setValue(this.compactSerializer.serialize(documentReference, wikiReference));
value.getMetaData().put(META_DATA_LABEL, getLabel(documentReference, value.getMetaData().get(META_DATA_LABEL)));
value.getMetaData().put(META_DATA_ICON, getIcon(documentReference));
value.getMetaData().put("url", getURL(documentReference));
}
return value;
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class AbstractDatabaseSearchSource method search.
@Override
public List<SearchResult> search(String partialQueryString, String wikiName, String wikis, boolean hasProgrammingRights, String orderField, String order, boolean distinct, int number, int start, Boolean withPrettyNames, String className, UriInfo uriInfo) throws Exception {
XWikiContext xwikiContext = this.xcontextProvider.get();
XWiki xwikiApi = new XWiki(xwikiContext.getWiki(), xwikiContext);
if (partialQueryString == null || StringUtils.startsWithIgnoreCase(partialQueryString, "select")) {
return Collections.emptyList();
}
String queryString = resolveQuery(distinct, partialQueryString);
Query query = this.queryManager.createQuery(queryString, this.queryLanguage);
query.setLimit(number).setOffset(start);
query.setWiki(wikiName);
List<Object> queryResult = query.execute();
WikiReference wikiReference = new WikiReference(wikiName);
/* Build the result. */
List<SearchResult> result = new ArrayList<>();
for (Object object : queryResult) {
Object[] fields = (Object[]) object;
String fullName = (String) fields[0];
String language = (String) fields[3];
DocumentReference documentReference = this.resolver.resolve(fullName, wikiReference);
/* Check if the user has the right to see the found document */
if (this.authorization.hasAccess(Right.VIEW, documentReference)) {
Document doc = xwikiApi.getDocument(documentReference);
String title = doc.getDisplayTitle();
SearchResult searchResult = this.objectFactory.createSearchResult();
searchResult.setType("page");
searchResult.setId(doc.getPrefixedFullName());
searchResult.setPageFullName(doc.getFullName());
searchResult.setTitle(title);
searchResult.setWiki(wikiName);
searchResult.setSpace(doc.getSpace());
searchResult.setPageName(doc.getName());
searchResult.setVersion(doc.getVersion());
searchResult.setAuthor(doc.getAuthor());
Calendar calendar = Calendar.getInstance();
calendar.setTime(doc.getDate());
searchResult.setModified(calendar);
if (withPrettyNames) {
searchResult.setAuthorName(xwikiApi.getUserName(doc.getAuthor(), false));
}
/*
* Avoid to return object information if the user is not authenticated. This will prevent crawlers to
* retrieve information such as email addresses and passwords from user's profiles.
*/
if (StringUtils.isNotEmpty(className) && xwikiContext.getUserReference() != null) {
XWikiDocument xdocument = xwikiContext.getWiki().getDocument(doc.getDocumentReference(), xwikiContext);
BaseObject baseObject = xdocument.getObject(className);
if (baseObject != null) {
searchResult.setObject(this.modelFactory.toRestObject(uriInfo.getBaseUri(), doc, baseObject, false, false));
}
}
String pageUri;
if (StringUtils.isBlank(language)) {
pageUri = Utils.createURI(uriInfo.getBaseUri(), PageResource.class, wikiName, Utils.getSpacesHierarchy(documentReference.getLastSpaceReference()), documentReference.getName()).toString();
} else {
searchResult.setLanguage(language);
pageUri = Utils.createURI(uriInfo.getBaseUri(), PageTranslationResource.class, wikiName, Utils.getSpacesHierarchy(documentReference.getLastSpaceReference()), documentReference.getName(), language).toString();
}
Link pageLink = new Link();
pageLink.setHref(pageUri);
pageLink.setRel(Relations.PAGE);
searchResult.getLinks().add(pageLink);
result.add(searchResult);
}
}
return result;
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class DefaultContextualAuthorizationManagerTest method before.
@Before
public void before() throws Exception {
this.authorizationManager = this.mocker.getInstance(AuthorizationManager.class);
this.currentWikiReference = new WikiReference("wiki");
this.oldcore.getXWikiContext().setWikiId(this.currentWikiReference.getName());
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class CurrentUserAndGroupDocumentReferenceResolverTest method testResolver.
@Test
public void testResolver() throws ComponentLookupException {
assertEquals(new DocumentReference("currentwiki", "XWiki", "Bosse"), this.mocker.getComponentUnderTest().resolve("Bosse"));
assertEquals(new DocumentReference("currentwiki", "bossesSpace", "Bosse"), this.mocker.getComponentUnderTest().resolve("bossesSpace.Bosse"));
assertEquals(new DocumentReference("bossesWiki", "XWiki", "Bosse"), this.mocker.getComponentUnderTest().resolve("Bosse", new WikiReference("bossesWiki")));
assertEquals(new DocumentReference("bossesWiki", "bossesSpace", "Bosse"), this.mocker.getComponentUnderTest().resolve("bossesSpace.Bosse", new WikiReference("bossesWiki")));
assertEquals(new DocumentReference("bossesWiki", "bossesSpace", "Bosse"), this.mocker.getComponentUnderTest().resolve("bossesWiki:bossesSpace.Bosse"));
// If null is passed we expect no reference (i.e. the guest user).
assertNull(this.mocker.getComponentUnderTest().resolve(null));
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class DefaultSecurityEntryReader method read.
/**
* Load the rules from wiki documents.
*
* @param entity Any entity reference that is either a WIKI or a SPACE, or an entity containing a DOCUMENT entity.
* @return the access rules that could be loaded into the cache.
* @throws org.xwiki.security.authorization.AuthorizationException if an issue arise while reading these rules
* from the wiki.
*/
@Override
public SecurityRuleEntry read(SecurityReference entity) throws AuthorizationException {
if (entity == null) {
return null;
}
if (entity.getOriginalReference() == null) {
// More generally, any reference without a valid original reference should not be considered.
return new InternalSecurityRuleEntry(entity, Collections.<SecurityRule>emptyList());
}
DocumentReference documentReference;
DocumentReference classReference;
WikiReference wikiReference;
switch(entity.getType()) {
case WIKI:
wikiReference = new WikiReference(entity);
SpaceReference wikiSpace = new SpaceReference(XWikiConstants.XWIKI_SPACE, wikiReference);
documentReference = new DocumentReference(XWikiConstants.WIKI_DOC, wikiSpace);
classReference = new DocumentReference(XWikiConstants.GLOBAL_CLASSNAME, wikiSpace);
break;
case SPACE:
wikiReference = new WikiReference(entity.extractReference(EntityType.WIKI));
documentReference = new DocumentReference(XWikiConstants.SPACE_DOC, new SpaceReference(entity));
classReference = new DocumentReference(XWikiConstants.GLOBAL_CLASSNAME, new SpaceReference(XWikiConstants.XWIKI_SPACE, wikiReference));
break;
case DOCUMENT:
wikiReference = new WikiReference(entity.extractReference(EntityType.WIKI));
documentReference = new DocumentReference(entity);
classReference = new DocumentReference(XWikiConstants.LOCAL_CLASSNAME, new SpaceReference(XWikiConstants.XWIKI_SPACE, wikiReference));
break;
default:
throw new EntityTypeNotSupportedException(entity.getType(), this);
}
return new InternalSecurityRuleEntry(entity, getSecurityRules(documentReference, classReference, wikiReference));
}
Aggregations