use of com.zimbra.cs.account.AttributeInfo in project zm-mailbox by Zimbra.
the class LdapProvisioning method getBasicDynamicGroupAttrs.
private String[] getBasicDynamicGroupAttrs() throws ServiceException {
AttributeManager attrMgr = AttributeManager.getInstance();
Set<String> dynGroupAttrs = attrMgr.getAllAttrsInClass(AttributeClass.group);
Set<String> attrs = Sets.newHashSet(dynGroupAttrs);
attrs.add(Provisioning.A_objectClass);
// remove deprecated attrs
for (Iterator<String> iter = attrs.iterator(); iter.hasNext(); ) {
String attr = iter.next();
AttributeInfo ai = attrMgr.getAttributeInfo(attr);
if (ai != null && ai.isDeprecated()) {
iter.remove();
}
}
return Lists.newArrayList(attrs).toArray(new String[attrs.size()]);
}
use of com.zimbra.cs.account.AttributeInfo in project zm-mailbox by Zimbra.
the class LdapProvisioning method modifyAttrsInternal.
/**
* should only be called internally.
*
* @param initCtxt
* @param attrs
* @throws ServiceException
*/
protected void modifyAttrsInternal(Entry entry, ZLdapContext initZlc, Map<String, ? extends Object> attrs, boolean storeEphemeralInLdap) throws ServiceException {
if (entry instanceof Account && !(entry instanceof CalendarResource)) {
Account acct = (Account) entry;
validate(ProvisioningValidator.MODIFY_ACCOUNT_CHECK_DOMAIN_COS_AND_FEATURE, acct.getAttr(A_zimbraMailDeliveryAddress), attrs, acct);
}
if (!storeEphemeralInLdap) {
Map<String, AttributeInfo> ephemeralAttrMap = AttributeManager.getInstance().getEphemeralAttrs();
Map<String, Object> ephemeralAttrs = new HashMap<String, Object>();
// remove after iteration to avoid ConcurrentModificationException
List<String> toRemove = null;
for (Map.Entry<String, ? extends Object> e : attrs.entrySet()) {
String key = e.getKey();
String attrName;
if (key.startsWith("+") || key.startsWith("-")) {
attrName = key.substring(1);
} else {
attrName = key;
}
if (ephemeralAttrMap.containsKey(attrName.toLowerCase())) {
ephemeralAttrs.put(key, e.getValue());
if (null == toRemove) {
// only 3 ephemeral attrs currently
toRemove = Lists.newArrayListWithExpectedSize(3);
}
toRemove.add(key);
}
}
if (null != toRemove) {
for (String key : toRemove) {
attrs.remove(key);
}
}
if (!ephemeralAttrs.isEmpty()) {
modifyEphemeralAttrs(entry, ephemeralAttrs, ephemeralAttrMap);
}
}
modifyLdapAttrs(entry, initZlc, attrs);
}
use of com.zimbra.cs.account.AttributeInfo in project zm-mailbox by Zimbra.
the class EphemeralAttributesTest method initEphemeralAttributes.
private static void initEphemeralAttributes() throws Exception {
Set<AttributeClass> requiredIn = Sets.newHashSet(AttributeClass.account);
Set<AttributeFlag> flags = Sets.newHashSet(AttributeFlag.ephemeral, AttributeFlag.dynamic, AttributeFlag.expirable);
AttributeInfo ai1 = new AttributeInfo(Provisioning.A_zimbraAuthTokens, 1, null, 0, null, AttributeType.TYPE_ASTRING, null, "", true, null, null, AttributeCardinality.multi, requiredIn, null, flags, null, null, null, null, null, "auth tokens", null, null, null);
AttributeInfo ai2 = new AttributeInfo(Provisioning.A_zimbraCsrfTokenData, 1, null, 0, null, AttributeType.TYPE_ASTRING, null, "", true, null, null, AttributeCardinality.multi, requiredIn, null, flags, null, null, null, null, null, "csrf tokens", null, null, null);
AttributeInfo ai3 = new AttributeInfo(Provisioning.A_zimbraLastLogonTimestamp, 1, null, 0, null, AttributeType.TYPE_GENTIME, null, "", true, null, null, AttributeCardinality.single, requiredIn, null, flags, null, null, null, null, null, "last logon timestamp", null, null, null);
AttributeInfo ai4 = new AttributeInfo(Provisioning.A_zimbraAppSpecificPassword, 1, null, 0, null, AttributeType.TYPE_ASTRING, null, "", true, null, null, AttributeCardinality.single, requiredIn, null, flags, null, null, null, null, null, "app-specific passwords", null, null, null);
AttributeManager am = new AttributeManager();
am.addAttribute(ai1);
am.addAttribute(ai2);
am.addAttribute(ai3);
am.addAttribute(ai4);
}
use of com.zimbra.cs.account.AttributeInfo in project zm-mailbox by Zimbra.
the class LdapProvisioning method copyCos.
private Cos copyCos(String srcCosId, String destCosName, Map<String, Object> cosAttrs) throws ServiceException {
destCosName = destCosName.toLowerCase().trim();
Cos srcCos = getCosById(srcCosId, null);
if (srcCos == null)
throw AccountServiceException.NO_SUCH_COS(srcCosId);
// bug 67716, use a case insensitive map because provided attr names may not be
// the canonical name and that will cause multiple entries in the map
Map<String, Object> allAttrs = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
allAttrs.putAll(srcCos.getAttrs());
allAttrs.remove(Provisioning.A_objectClass);
allAttrs.remove(Provisioning.A_zimbraId);
allAttrs.remove(Provisioning.A_zimbraCreateTimestamp);
allAttrs.remove(Provisioning.A_zimbraACE);
allAttrs.remove(Provisioning.A_cn);
allAttrs.remove(Provisioning.A_description);
if (cosAttrs != null) {
for (Map.Entry<String, Object> e : cosAttrs.entrySet()) {
String attr = e.getKey();
Object value = e.getValue();
if (value instanceof String && Strings.isNullOrEmpty((String) value)) {
allAttrs.remove(attr);
} else {
allAttrs.put(attr, value);
}
}
}
CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
// get rid of deprecated attrs
Map<String, Object> allNewAttrs = new HashMap<String, Object>(allAttrs);
for (String attr : allAttrs.keySet()) {
AttributeInfo info = AttributeManager.getInstance().getAttributeInfo(attr);
if (info != null && info.isDeprecated()) {
allNewAttrs.remove(attr);
}
}
allAttrs = allNewAttrs;
AttributeManager.getInstance().preModify(allAttrs, null, callbackContext, true);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_COS);
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(allAttrs);
Set<String> ocs = LdapObjectClass.getCosObjectClasses(this);
entry.addAttr(A_objectClass, ocs);
String zimbraIdStr = LdapUtil.generateUUID();
entry.setAttr(A_zimbraId, zimbraIdStr);
entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
entry.setAttr(A_cn, destCosName);
String dn = mDIT.cosNametoDN(destCosName);
entry.setDN(dn);
zlc.createEntry(entry);
Cos cos = getCosById(zimbraIdStr, zlc);
AttributeManager.getInstance().postModify(allAttrs, cos, callbackContext);
return cos;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.COS_EXISTS(destCosName);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to create cos: " + destCosName, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.account.AttributeInfo in project zm-mailbox by Zimbra.
the class GetAttributeInfo method encodeAttr.
private void encodeAttr(Element response, AttributeManager attrMgr, String attr) {
AttributeInfo attrInfo = attrMgr.getAttributeInfo(attr);
if (attrInfo == null) {
ZimbraLog.account.info("no attribte info for " + attr);
return;
}
String desc = attrInfo.getDescription();
String deSpacedDesc = FileGenUtil.wrapComments((desc == null ? "" : desc), Integer.MAX_VALUE, "");
Element eAttr = response.addElement(AdminConstants.E_A);
eAttr.addAttribute(AdminConstants.A_N, attr);
eAttr.addAttribute(AdminConstants.A_DESC, deSpacedDesc);
}
Aggregations