@Override public DocumentReference getAuthorReference(DocumentReference reference) throws WikiComponentException { XWikiDocument componentDocument = this.getDocument(reference); return componentDocument.getAuthorReference(); }
@Override public boolean hasProgrammingRights(DocumentReference reference) throws WikiComponentException { XWikiDocument document = getDocument(reference); return this.authorization.hasAccess(Right.PROGRAM, document.getAuthorReference(), null); }
/** * Note that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument. * * @deprecated since 3.0M3 use {@link #getAuthorReference()} instead */ @Deprecated public String getAuthor() { String author; DocumentReference authorReference = getAuthorReference(); if (authorReference == null) { author = ""; } else { author = this.compactWikiEntityReferenceSerializer.serialize(authorReference, getDocumentReference()); } return author; }
@Override public PatientData<String> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); Map<String, String> result = new LinkedHashMap<>(); DateTimeFormatter dateFormatter = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC); result.put(DOCUMENT_NAME, doc.getDocumentReference().getName()); result.put(CREATION_DATE, dateFormatter.print(new DateTime(doc.getCreationDate()))); result.put(AUTHOR, (doc.getAuthorReference() != null) ? doc.getAuthorReference().getName() : UNKNOWN_USER); result.put(DATE, dateFormatter.print(new DateTime(doc.getDate()))); return new DictionaryPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }
/** * Note that this method cannot be removed for now since it's used by Hibernate for loading a XWikiDocument. * * @deprecated since 3.0M3 use {@link #setAuthorReference} instead */ @Deprecated public void setAuthor(String author) { // Note: Consider "" or null as the same, i.e. the author not being set DocumentReference authorReference = null; if (author != null && author.length() > 0) { authorReference = this.explicitReferenceDocumentReferenceResolver.resolve( this.xClassEntityReferenceResolver.resolve(author, EntityType.DOCUMENT), getDocumentReference()); } if ((getAuthorReference() == null && authorReference != null) || (getAuthorReference() != null && !getAuthorReference().equals(authorReference))) { setMetaDataDirty(true); } setAuthorReference(authorReference); }
@Override public PatientData<String> load(Patient patient) { try { XWikiDocument doc = (XWikiDocument) this.documentAccessBridge.getDocument(patient.getDocument()); Map<String, String> result = new LinkedHashMap<>(); DateTimeFormatter dateFormatter = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC); result.put(DOCUMENT_NAME, doc.getDocumentReference().getName()); result.put(CREATION_DATE, dateFormatter.print(new DateTime(doc.getCreationDate()))); result.put(AUTHOR, (doc.getAuthorReference() != null) ? doc.getAuthorReference().getName() : UNKNOWN_USER); result.put(DATE, dateFormatter.print(new DateTime(doc.getDate()))); return new DictionaryPatientData<>(getName(), result); } catch (Exception e) { this.logger.error("Could not find requested document or some unforeseen" + " error has occurred during controller loading ", e.getMessage()); } return null; }
@Override public List<WikiComponent> buildComponents(BaseObject baseObject) throws WikiComponentException { try { // Check that the document owner is allowed to build the components XWikiDocument parentDocument = baseObject.getOwnerDocument(); this.checkRights(parentDocument.getDocumentReference(), parentDocument.getAuthorReference()); // Instantiate the component return Arrays.asList( new WikiNotificationFilterDisplayer(parentDocument.getAuthorReference(), this.componentManager, baseObject)); } catch (Exception e) { throw new WikiComponentException(String.format( "Unable to build the WikiNotificationFilterDisplayer wiki component " + "for [%s].", baseObject), e); } }
/** * @param document the translation document * @param scope the scope * @throws AccessDeniedException thrown when the document author does not have enough right for the provided * {@link Scope} */ private void checkRegistrationAuthorization(XWikiDocument document, Scope scope) throws AccessDeniedException { switch (scope) { case GLOBAL: this.authorizationManager.checkAccess(Right.PROGRAM, document.getAuthorReference(), null); break; case WIKI: this.authorizationManager.checkAccess(Right.ADMIN, document.getAuthorReference(), document .getDocumentReference().getWikiReference()); break; default: break; } }
private void checkProgrammingRights() throws AuthorizationException { XWikiContext xcontext = this.xcontextProvider.get(); authorizationManager.checkAccess(Right.PROGRAM, xcontext.getDoc().getAuthorReference(), xcontext.getDoc() .getDocumentReference()); }
private void initialize(XWikiDocument editorDocument) throws WikiComponentException { this.authorReference = editorDocument.getAuthorReference(); BaseObject editorObject = editorDocument.getXObject(EDITOR_CLASS_REFERENCE); if (editorObject != null) { initialize(editorObject); } else { throw new WikiComponentException(String.format( "The document [%s] is missing the XWiki.EditorClass object.", editorDocument.getDocumentReference())); } }
/** * @param baseObject the object containing the component definition * @param roleType the role Type implemented * @param roleHint the role hint for this role implementation */ public AbstractBaseObjectWikiComponent(BaseObject baseObject, Type roleType, String roleHint) { this.objectReference = baseObject.getReference(); this.authorReference = baseObject.getOwnerDocument().getAuthorReference(); this.roleType = roleType; this.roleHint = roleHint; this.scope = WikiComponentScope.fromString(baseObject.getStringValue(XPROPERTY_SCOPE)); }
/** * Checks if the last author of the document holding the extension(s) has the rights required to register extensions * for the given scope. If the document author doesn't have the required rights a {@link WikiComponentException} is * thrown. * * @param extensionsDoc the document holding the extension(s) * @param scope the scope to check the rights for * @throws WikiComponentException if the document author doesn't have the required rights to register extensions */ private void checkRights(XWikiDocument extensionsDoc, WikiComponentScope scope) throws WikiComponentException { if (scope == WikiComponentScope.GLOBAL) { if (!this.authorization.hasAccess(Right.PROGRAM, extensionsDoc.getAuthorReference(), null)) { throw new WikiComponentException("Registering global UI extensions requires programming rights"); } } else if (scope == WikiComponentScope.WIKI) { if (!this.authorization.hasAccess(Right.ADMIN, extensionsDoc.getAuthorReference(), extensionsDoc.getDocumentReference().getWikiReference())) { throw new WikiComponentException( "Registering UI extensions at wiki level requires wiki administration rights"); } } }
/** * @param solrDocument the Solr document * @param translatedDocument the XWiki document * @param entityReference the document reference */ private void setAuthors(SolrInputDocument solrDocument, XWikiDocument translatedDocument, EntityReference entityReference) { XWikiContext xcontext = this.xcontextProvider.get(); String authorString = entityReferenceSerializer.serialize(translatedDocument.getAuthorReference()); solrDocument.setField(FieldUtils.AUTHOR, authorString); String authorDisplayString = xcontext.getWiki().getPlainUserName(translatedDocument.getAuthorReference(), xcontext); solrDocument.setField(FieldUtils.AUTHOR_DISPLAY, authorDisplayString); String creatorString = entityReferenceSerializer.serialize(translatedDocument.getCreatorReference()); solrDocument.setField(FieldUtils.CREATOR, creatorString); String creatorDisplayString = xcontext.getWiki().getPlainUserName(translatedDocument.getCreatorReference(), xcontext); solrDocument.setField(FieldUtils.CREATOR_DISPLAY, creatorDisplayString); }
/** * Get the right component manager based on the scope. * * @param document the translation document * @param scope the translation scope * @param create true if the component manager should be created if it does not exists * @return the component manager corresponding to the provided {@link Scope} */ private ComponentManager getComponentManager(XWikiDocument document, Scope scope, boolean create) { String hint; switch (scope) { case WIKI: hint = "wiki:" + document.getDocumentReference().getWikiReference().getName(); break; case USER: hint = "user:" + this.serializer.serialize(document.getAuthorReference()); break; default: hint = null; break; } return this.cmManager.getComponentManager(hint, create); }
private void saveGroupDocument(XWikiDocument document, String message) throws WikiUserManagerException { // Get the XWiki objects XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); // The document should be hidden document.setHidden(true); // The document must have a creator if (document.getCreatorReference() == null) { document.setCreatorReference(xcontext.getUserReference()); } // The document must have an author if (document.getAuthorReference() == null) { document.setAuthorReference(xcontext.getUserReference()); } // Save the document try { xwiki.saveDocument(document, message, xcontext); } catch (XWikiException e) { throw new WikiUserManagerException("Fail to save the member group", e); } }
@Override public void save(WikiPropertyGroup group, String wikiId) throws WikiPropertyGroupException { XWikiContext context = xcontextProvider.get(); XWiki xwiki = context.getWiki(); WikiTemplatePropertyGroup templateGroup = (WikiTemplatePropertyGroup) group; try { XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId); BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS, true, context); object.setIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, templateGroup.isTemplate() ? 1 : 0); // The document must have a creator if (descriptorDocument.getCreatorReference() == null) { descriptorDocument.setCreatorReference(context.getUserReference()); } // The document must have an author if (descriptorDocument.getAuthorReference() == null) { descriptorDocument.setAuthorReference(context.getUserReference()); } xwiki.saveDocument(descriptorDocument, String.format("Changed property group [%s].", GROUP_NAME), context); } catch (WikiManagerException e) { throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e); } catch (XWikiException e) { throw new WikiPropertyGroupException("Unable to save descriptor document.", e); } }
/** * Check that all required permissions are respected by both the script and the user. * * @param wikiId the id of the wiki concerned by the operation * @param user the user concerned by the operation * * @throws AccessDeniedException if the permissions are not respected */ private void checkRights(String wikiId, DocumentReference user) throws AccessDeniedException { XWikiContext context = xcontextProvider.get(); // Does the script author have the admin right? // // The goal is to avoid that a non-granted user writes a script, which could be executed by an administrator, // which uses this script service to perform "nasty" operations, like being invited to a sub-wiki. // // By the past, we checked for the programing right, but it was too restrictive, as it make impossible to // a user without programing rights to create a wiki and then invite some peoples in it. authorizationManager.checkAccess(Right.ADMIN, context.getDoc().getAuthorReference(), context.getDoc().getDocumentReference()); // Is the user concerned by the operation? if (user != null && user.equals(context.getUserReference())) { // If the user is concerned, then she has the right to perform this operation. return; } // Does the current user have the admin right? authorizationManager.checkAccess(Right.ADMIN, context.getUserReference(), new WikiReference(wikiId)); }
private void setDescriptorDocMetadata(XWikiDocument descriptorDoc) { XWikiContext context = xcontextProvider.get(); // Set the document as hidden descriptorDoc.setHidden(true); // The document must have a creator if (descriptorDoc.getCreatorReference() == null) { descriptorDoc.setCreatorReference(context.getUserReference()); } // The document must have an author if (descriptorDoc.getAuthorReference() == null) { descriptorDoc.setAuthorReference(context.getUserReference()); } // Set the document parent if (descriptorDoc.getParentReference() == null) { EntityReference parentReference = new EntityReference("WebHome", EntityType.DOCUMENT); parentReference.appendParent(new EntityReference("WikiManager", EntityType.SPACE)); descriptorDoc.setParentReference(parentReference); } } }
@Override public PatientSummary createPatientSummary(Patient patient, UriInfo uriInfo) { if (patient == null) { return null; } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { return null; } PatientSummary result = new PatientSummary(); XWikiDocument doc = patient.getXDocument(); result.withId(patient.getId()).withEid(patient.getExternalId()); result.withCreatedBy(String.valueOf(patient.getReporter())).withLastModifiedBy( String.valueOf(doc.getAuthorReference())); result.withVersion(doc.getVersion()); result.withCreatedOn(new DateTime(doc.getCreationDate()).withZone(DateTimeZone.UTC)); result.withLastModifiedOn(new DateTime(doc.getDate()).withZone(DateTimeZone.UTC)); result.withLinks(this.autolinker.get().forSecondaryResource(PatientResource.class, uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .build()); return result; }
public LDAPProfileXClass(XWikiContext context) throws XWikiException { this.context = context; XWikiDocument ldapClassDoc = context.getWiki().getDocument(LDAPPROFILECLASS_REFERENCE, context); this.ldapClass = ldapClassDoc.getXClass(); boolean needsUpdate = this.ldapClass.addTextField(LDAP_XFIELD_DN, LDAP_XFIELDPN_DN, 80); needsUpdate |= this.ldapClass.addTextField(LDAP_XFIELD_UID, LDAP_XFIELDPN_UID, 80); if (ldapClassDoc.getCreatorReference() == null) { needsUpdate = true; ldapClassDoc.setCreator(XWikiRightService.SUPERADMIN_USER); } if (ldapClassDoc.getAuthorReference() == null) { needsUpdate = true; ldapClassDoc.setAuthorReference(ldapClassDoc.getCreatorReference()); } if (!ldapClassDoc.isHidden()) { needsUpdate = true; ldapClassDoc.setHidden(true); } if (needsUpdate) { context.getWiki().saveDocument(ldapClassDoc, "Update LDAP user profile class", context); } }