public void addBaseClass(BaseClass bclass) { this.classCache.put(bclass.getDocumentReference(), bclass); }
/** * @param userDocument the user profile page. * @return the dn store in the user profile. Null if it can't find any or if it's empty. */ public String getDn(XWikiDocument userDocument) { BaseObject ldapObject = userDocument.getXObject(this.ldapClass.getDocumentReference()); return ldapObject == null ? null : getDn(ldapObject); }
/** * @param userDocument the user profile page. * @return the uid store in the user profile. Null if it can't find any or if it's empty. */ public String getUid(XWikiDocument userDocument) { BaseObject ldapObject = userDocument.getXObject(this.ldapClass.getDocumentReference()); return ldapObject == null ? null : getUid(ldapObject); }
/** * @deprecated since 2.2.3 use {@link com.xpn.xwiki.doc.XWikiDocument#newXObject} */ @Deprecated public BaseCollection newObject(XWikiContext context) throws XWikiException { BaseObject bobj = newCustomClassInstance(context); bobj.setXClassReference(this.localReferenceEntityReferenceSerializer.serialize(getDocumentReference())); return bobj; }
/** * Update LDAP profile object with provided LDAP user informations. * * @param userDocument the user profile page to update. * @param dn the dn to store in the LDAP profile. * @param uid the uid to store in the LDAP profile. * @return true if modifications has been made to provided user profile, false otherwise. */ public boolean updateLDAPObject(XWikiDocument userDocument, String dn, String uid) { BaseObject ldapObject = userDocument.getXObject(this.ldapClass.getDocumentReference(), true, this.context); Map<String, String> map = new HashMap<String, String>(); boolean needsUpdate = false; String objDn = getDn(ldapObject); if (!dn.equalsIgnoreCase(objDn)) { map.put(LDAP_XFIELD_DN, dn); needsUpdate = true; } String objUid = getUid(ldapObject); if (!uid.equalsIgnoreCase(objUid)) { map.put(LDAP_XFIELD_UID, uid); needsUpdate = true; } if (needsUpdate) { this.ldapClass.fromMap(map, ldapObject); } return needsUpdate; }
BaseObject memberObj = groupDoc.newXObject(groupClass.getDocumentReference(), context); Map<String, String> map = new HashMap<String, String>(); map.put(XWIKI_GROUP_MEMBERFIELD, xwikiUserName);
public void readObjectsFromForm(EditForm eform, XWikiContext context) throws XWikiException { for (DocumentReference reference : getXObjects().keySet()) { List<BaseObject> oldObjects = getXObjects(reference); List<BaseObject> newObjects = new ArrayList<BaseObject>(); while (newObjects.size() < oldObjects.size()) { newObjects.add(null); } for (int i = 0; i < oldObjects.size(); i++) { BaseObject oldobject = oldObjects.get(i); if (oldobject != null) { BaseClass baseclass = oldobject.getXClass(context); BaseObject newobject = (BaseObject) baseclass.fromMap(eform.getObject( this.localEntityReferenceSerializer.serialize(baseclass.getDocumentReference()) + "_" + i), oldobject); newobject.setNumber(oldobject.getNumber()); newobject.setGuid(oldobject.getGuid()); newobject.setDocumentReference(getDocumentReference()); newObjects.set(newobject.getNumber(), newobject); } } getXObjects().put(reference, newObjects); } setContentDirty(true); }
BaseObject userObj = userProfile.getXObject(userClass.getDocumentReference());
List<BaseObject> xobjects = groupDoc.getXObjects(groupClass.getDocumentReference()); if (xobjects != null) { for (BaseObject memberObj : xobjects) { BaseObject memberObj = groupDoc.newXObject(groupClass.getDocumentReference(), context); Map<String, String> map = new HashMap<String, String>(); map.put(XWIKI_GROUP_MEMBERFIELD, xwikiUserName);
/** * Remove user name from provided XWiki group. * * @param xwikiUserName the full name of the user. * @param groupName the name of the group. * @param context the XWiki context. */ // TODO move this methods in a toolkit for all platform. protected void removeUserFromXWikiGroup(String xwikiUserName, String groupName, XWikiContext context) { try { BaseClass groupClass = context.getWiki().getGroupClass(context); // Get the XWiki document holding the objects comprising the group membership list XWikiDocument groupDoc = context.getWiki().getDocument(groupName, context); // Get and remove the specific group membership object for the user BaseObject groupObj = groupDoc.getXObject(groupClass.getDocumentReference(), XWIKI_GROUP_MEMBERFIELD, xwikiUserName); groupDoc.removeXObject(groupObj); // Save modifications context.getWiki().saveDocument(groupDoc, context); } catch (Exception e) { LOG.error("Failed to remove a user from a group " + xwikiUserName + " group: " + groupName, e); } }
/** * Remove user name from provided XWiki group. * * @param xwikiUserName the full name of the user. * @param groupName the name of the group. * @param context the XWiki context. */ // TODO move this methods in a toolkit for all platform. protected void removeUserFromXWikiGroup(String xwikiUserName, String groupName, XWikiContext context) { try { BaseClass groupClass = context.getWiki().getGroupClass(context); // Get the XWiki document holding the objects comprising the group membership list XWikiDocument groupDoc = context.getWiki().getDocument(groupName, context); synchronized (groupDoc) { // Get and remove the specific group membership object for the user BaseObject groupObj = groupDoc.getXObject(groupClass.getDocumentReference(), XWIKI_GROUP_MEMBERFIELD, xwikiUserName); groupDoc.removeXObject(groupObj); // Save modifications context.getWiki().saveDocument(groupDoc, context); } } catch (Exception e) { LOGGER.error("Failed to remove a user from a group " + xwikiUserName + " group: " + groupName, e); } }
/** * Create a new user. * * @param userName the name of the user (without the space) * @param map extra datas to add to user profile object * @param userRights the right of the user on his own profile page * @param context the XWiki context * @return <ul> * <li>1: ok</li> * <li>-3: user already exists</li> * </ul> * @throws XWikiException failed to create the new user */ public int createUser(String userName, Map<String, ? > map, String userRights, XWikiContext context) throws XWikiException { BaseClass userClass = context.getWiki().getUserClass(context); String content; Syntax syntax; if (!context.getWiki().getDefaultDocumentSyntax().equals(Syntax.XWIKI_1_0.toIdString())) { content = "{{include document=\"XWiki.XWikiUserSheet\"/}}"; syntax = Syntax.XWIKI_2_0; } else { content = "#includeForm(\"XWiki.XWikiUserSheet\")"; syntax = Syntax.XWIKI_1_0; } return createUser(userName, map, new EntityReference(userClass.getDocumentReference().getName(), EntityType.DOCUMENT), content, syntax, userRights, context); }
/** * Note: BaseElement#setName() does not support setting reference anymore since 2.4M2. This was broken and * has been replaced by this overridden method. See XWIKI-5285 * * {@inheritDoc} * * @deprecated since 2.2M2 use {@link #setDocumentReference(org.xwiki.model.reference.DocumentReference)} */ @Deprecated @Override public void setName(String name) { if (this instanceof MetaClass || this instanceof PropertyMetaClass) { super.setName(name); } else { DocumentReference reference = getDocumentReference(); if (reference != null) { EntityReference relativeReference = this.relativeEntityReferenceResolver.resolve(name, EntityType.DOCUMENT); reference.getLastSpaceReference() .setName(relativeReference.extractReference(EntityType.SPACE).getName()); reference.setName(relativeReference.extractReference(EntityType.DOCUMENT).getName()); } else { reference = this.currentMixedDocumentReferenceResolver.resolve(name); } setDocumentReference(reference); } }
/** * @param validXWikiUserName a valid XWiki username for which to get a profile document * @param ldapUid ldap UID of the user profile to get * @param context the XWiki context * @return a (new) XWiki document for the passed username * @throws XWikiException when a problem occurs while retrieving the user profile */ private XWikiDocument getAvailableUserProfile(String validXWikiUserName, String ldapUid, XWikiContext context) throws XWikiException { BaseClass userClass = context.getWiki().getUserClass(context); LDAPProfileXClass ldapXClass = new LDAPProfileXClass(context); DocumentReference userReference = new DocumentReference(context.getDatabase(), XWIKI_USER_SPACE, validXWikiUserName); // Check if the default profile document is available for (int i = 0; true; ++i) { if (i > 0) { userReference.setName(validXWikiUserName + "_" + i); } XWikiDocument doc = context.getWiki().getDocument(userReference, context); // Don't use non user existing document if (doc.isNew() || doc.getXObject(userClass.getDocumentReference()) != null) { String ldapUidFromObject = ldapXClass.getUid(doc); // If the user is a LDAP user compare uids if (ldapUidFromObject == null || ldapUid.equalsIgnoreCase(ldapUidFromObject)) { return doc; } } } }
public void protectUserPage(String userName, String userRights, XWikiDocument doc, XWikiContext context) throws XWikiException { BaseClass rclass = getRightsClass(context); EntityReference rightClassReference = this.localReferenceEntityReferenceSerializer.serialize(rclass.getDocumentReference()); // Add protection to the page BaseObject newrightsobject = doc.newXObject(rightClassReference, context); newrightsobject.setLargeStringValue("groups", "XWiki.XWikiAdminGroup"); newrightsobject.setStringValue("levels", userRights); newrightsobject.setIntValue("allow", 1); BaseObject newuserrightsobject = doc.newXObject(rightClassReference, context); newuserrightsobject.setLargeStringValue("users", userName); newuserrightsobject.setStringValue("levels", userRights); newuserrightsobject.setIntValue("allow", 1); }
protected void addUserToGroup(String userName, String groupName, XWikiContext context) throws XWikiException { BaseClass groupClass = getGroupClass(context); XWikiDocument groupDoc = getDocument(groupName, context); BaseObject memberObject = groupDoc.newXObject( this.localReferenceEntityReferenceSerializer.serialize(groupClass.getDocumentReference()), context); memberObject.setStringValue("member", userName); if (groupDoc.isNew()) { saveDocument(groupDoc, context.getMessageTool().get("core.comment.addedUserToGroup"), context); } else { // TODO Fix use of deprecated call. getHibernateStore().saveXWikiObject(memberObject, context, true); } try { XWikiGroupService gservice = getGroupService(context); gservice.addUserToGroup(userName, context.getDatabase(), groupName, context); } catch (Exception e) { LOG.error("Failed to update group service cache", e); } }
BaseObject userObj = userProfile.getXObject(userClass.getDocumentReference());
if (doc.isNew() || doc.getXObject(userClass.getDocumentReference()) != null) { String ldapUidFromObject = ldapXClass.getUid(doc);
DocumentReference righsClassReference = context.getWiki().getRightsClass(context).getDocumentReference();
this.localReferenceEntityReferenceSerializer.serialize(baseclass.getDocumentReference()), context); baseclass.fromMap(map, userObject);