Skip to content

Commit

Permalink
feat: [COR-936] Create account with given zimbraId (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonersivri authored Feb 6, 2024
1 parent c011b2c commit 2f5e8c5
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1425,14 +1425,13 @@ private Account createAccount(

entry.addAttr(A_objectClass, ocs);

// fail account creation if zimbraId attribute is passed in create account(ca) command
if (uuid != null) {
throw ServiceException.FAILURE(
"Failed to create account, passing account zimbraId in attributes is not allowed.",
null);
String zimbraIdStr;
if (uuid == null) {
zimbraIdStr = LdapUtil.generateUUID();
} else {
zimbraIdStr = uuid;
}

String zimbraIdStr = LdapUtil.generateUUID();
entry.setAttr(A_zimbraId, zimbraIdStr);
entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ public void handleZimbraId(Map<String, Object> attrs) throws ServiceException {

if (zimbraId != null) {
// present, validate if it is a valid uuid
try {
if (!LdapUtil.isValidUUID(zimbraId))
throw ServiceException.INVALID_REQUEST(zimbraId + " is not a valid UUID", null);
} catch (IllegalArgumentException e) {
throw ServiceException.INVALID_REQUEST(zimbraId + " is not a valid UUID", e);
}

LdapUtil.validateZimbraId(zimbraId);

/* check for uniqueness of the zimbraId
*
* for now we go with GIGO (garbage in, garbage out) and not check, since there is a race condition
Expand Down
14 changes: 14 additions & 0 deletions store/src/main/java/com/zimbra/cs/ldap/LdapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

// TODO: get rid of this
import javax.naming.ldap.Rdn;

import com.zimbra.common.service.ServiceException;
import com.zimbra.common.util.ByteUtil;
import com.zimbra.common.util.UUIDUtil;
import com.zimbra.cs.account.Provisioning;
Expand Down Expand Up @@ -125,6 +127,18 @@ public static boolean isValidUUID(String strRep) throws IllegalArgumentException
return true;
}

public static void validateZimbraId(String zimbraId) throws ServiceException {
if (zimbraId == null ) {
throw ServiceException.INVALID_REQUEST("null is not a valid zimbraId", null);
}

try {
UUID.fromString(zimbraId);
} catch (IllegalArgumentException e) {
throw ServiceException.INVALID_REQUEST(zimbraId + " is not a valid UUID", e);
}
}

/**
* Return the later (more recent) of two LDAP timestamps. Timestamp
* format is YYYYMMDDhhmmssZ. (e.g. 20060315023000Z)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package com.zimbra.cs.service.admin;

import static com.zimbra.common.account.ZAttrProvisioning.A_zimbraId;

import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -55,12 +53,6 @@ public Element handle(Element request, Map<String, Object> context) throws Servi
String name = req.getName().toLowerCase();
Map<String, Object> attrs = req.getAttrsAsOldMultimap(true /* ignoreEmptyValues */);

//fail account creation if zimbraId attribute is passed in CreateAccountRequest
if(attrs.containsKey(A_zimbraId)){
throw ServiceException.INVALID_REQUEST(
"Failed to create account, passing account zimbraId in attributes is not allowed.", null);
}

checkDomainRightByEmail(zsc, name, Admin.R_createAccount);
checkSetAttrsOnCreate(zsc, TargetType.account, name, attrs);
checkCos(zsc, attrs);
Expand Down
Loading

0 comments on commit 2f5e8c5

Please sign in to comment.