use of com.zimbra.cs.account.AttributeInfo in project zm-mailbox by Zimbra.
the class LdapProvisioning method getBasicDLAttrs.
private String[] getBasicDLAttrs() throws ServiceException {
AttributeManager attrMgr = AttributeManager.getInstance();
Set<String> dlAttrs = attrMgr.getAllAttrsInClass(AttributeClass.distributionList);
Set<String> attrs = Sets.newHashSet(dlAttrs);
attrs.add(Provisioning.A_objectClass);
// the member attr
attrs.remove(Provisioning.A_zimbraMailForwardingAddress);
// does not apply to DL
attrs.remove(Provisioning.A_zimbraMailTransport);
// 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 modifyEphemeralAttrs.
private void modifyEphemeralAttrs(Entry entry, Map<String, Object> attrs, Map<String, AttributeInfo> ephemeralAttrMap) throws ServiceException {
EphemeralLocation location = new LdapEntryLocation(entry);
EphemeralStore store = EphemeralStore.getFactory().getStore();
for (Map.Entry<String, Object> e : attrs.entrySet()) {
String key = e.getKey();
Object value = e.getValue();
boolean doAdd = key.charAt(0) == '+';
boolean doRemove = key.charAt(0) == '-';
if (doAdd || doRemove) {
key = key.substring(1);
if (attrs.containsKey(key))
throw ServiceException.INVALID_REQUEST("can't mix +attrName/-attrName with attrName", null);
}
AttributeInfo ai = ephemeralAttrMap.get(key.toLowerCase());
AttributeConverter converter = null;
if (ai == null) {
continue;
}
if (ai.isDynamic()) {
converter = AttributeMigration.getConverter(key);
if (converter == null) {
ZimbraLog.ephemeral.warn("Dynamic ephemeral attribute %s has no registered AttributeConverter, so cannot be modified with modifyAttrs", key);
continue;
}
}
if (value instanceof Collection) {
Collection values = (Collection) value;
if (values.size() == 0) {
ZimbraLog.ephemeral.warn("Ephemeral attribute %s doesn't support deletion by key; only deletion by key+value is supported", key);
continue;
} else {
for (Object v : values) {
if (v == null) {
continue;
}
String s = v.toString();
handleEphemeralAttrChange(store, key, s, location, ai, converter, doAdd, doRemove);
}
}
} else if (value instanceof Map) {
throw ServiceException.FAILURE("Map is not a supported value type", null);
} else if (value != null) {
String s = value.toString();
handleEphemeralAttrChange(store, key, s, location, ai, converter, doAdd, doRemove);
} else {
ZimbraLog.ephemeral.warn("Ephemeral attribute %s doesn't support deletion by key; only deletion by key+value is supported", key);
}
}
}
use of com.zimbra.cs.account.AttributeInfo in project zm-mailbox by Zimbra.
the class BUG_27075 method doEntry.
private void doEntry(ZLdapContext zlc, Entry entry, String entryName, AttributeClass klass) throws ServiceException {
printer.println();
printer.println("------------------------------");
printer.println("Upgrading " + entryName + ": ");
AttributeManager am = AttributeManager.getInstance();
Set<String> attrs = am.getAttrsInClass(klass);
Map<String, Object> attrValues = new HashMap<String, Object>();
for (String attr : attrs) {
AttributeInfo ai = am.getAttributeInfo(attr);
if (ai == null)
continue;
List<Version> attrVersion = ai.getSince();
if (needsUpgrade(am, attr)) {
if (verbose) {
printer.println("");
printer.println("Checking " + entryName + " attribute: " + attr + attrVersion);
}
String curVal = entry.getAttr(attr);
if (curVal != null) {
// already has a value, skip it
if (verbose) {
if (ai.getCardinality() == AttributeCardinality.multi)
curVal = formatMultiValue(entry.getMultiAttrSet(attr));
printer.println(" skipping - already has value: " + curVal);
}
continue;
}
/*
* use the upgrade values if set, otherwise use the default values
*
* Note, we support the case when we need to leave the value unset
* on upgrades, but set a value on new installs. In AttributeManager,
* if <globalConfigValueUpgrade> or <defaultCOSValueUpgrade> element
* is present but does not have a value, AttributeInfo.getGlobalConfigValuesUpgrade()/
* getDefaultCosValuesUpgrade() will return an empty List. If the upgrade
* element is not present, the two methods will return null. We check
* null here and if it is null then use the same default value for new
* installs.
*/
List<String> values = null;
if (klass == AttributeClass.globalConfig) {
values = ai.getGlobalConfigValuesUpgrade();
if (values == null)
values = ai.getGlobalConfigValues();
} else if (klass == AttributeClass.cos) {
values = ai.getDefaultCosValuesUpgrade();
if (values == null)
values = ai.getDefaultCosValues();
} else {
printer.println("Internal error: invalid attribute class " + klass.name());
return;
}
if (values == null || values.size() == 0) {
if (verbose) {
printer.println(" skipping - does not have a default value");
}
continue;
}
attrValues.clear();
if (ai.getCardinality() != AttributeCardinality.multi) {
printer.println(" setting " + entryName + " attribute " + attr + attrVersion + " to: " + values.get(0));
attrValues.put(attr, values.get(0));
} else {
printer.println(" setting " + entryName + " attribute " + attr + attrVersion + " to: " + formatMultiValue(values));
attrValues.put(attr, values.toArray(new String[0]));
}
try {
modifyAttrs(zlc, entry, attrValues);
} catch (ServiceException e) {
// log the exception and continue
printer.println("Caught ServiceException while modifying " + entryName + " attribute " + attr);
printer.printStackTrace(e);
}
}
}
}
use of com.zimbra.cs.account.AttributeInfo in project zm-mailbox by Zimbra.
the class ModifyPrefs method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
if (!canModifyOptions(zsc, account))
throw ServiceException.PERM_DENIED("can not modify options");
HashMap<String, Object> prefs = new HashMap<String, Object>();
Map<String, Set<String>> name2uniqueAttrValues = new HashMap<String, Set<String>>();
for (KeyValuePair kvp : request.listKeyValuePairs(AccountConstants.E_PREF, AccountConstants.A_NAME)) {
String name = kvp.getKey(), value = kvp.getValue();
char ch = name.length() > 0 ? name.charAt(0) : 0;
int offset = ch == '+' || ch == '-' ? 1 : 0;
if (!name.startsWith(PREF_PREFIX, offset))
throw ServiceException.INVALID_REQUEST("pref name must start with " + PREF_PREFIX, null);
AttributeInfo attrInfo = AttributeManager.getInstance().getAttributeInfo(name.substring(offset));
if (attrInfo == null) {
throw ServiceException.INVALID_REQUEST("no such attribute: " + name, null);
}
if (attrInfo.isCaseInsensitive()) {
String valueLowerCase = Strings.nullToEmpty(value).toLowerCase();
if (name2uniqueAttrValues.get(name) == null) {
Set<String> set = new HashSet<String>();
set.add(valueLowerCase);
name2uniqueAttrValues.put(name, set);
StringUtil.addToMultiMap(prefs, name, value);
} else {
Set<String> set = name2uniqueAttrValues.get(name);
if (set.add(valueLowerCase)) {
StringUtil.addToMultiMap(prefs, name, value);
}
}
} else {
StringUtil.addToMultiMap(prefs, name, value);
}
}
if (prefs.containsKey(Provisioning.A_zimbraPrefMailForwardingAddress)) {
if (!account.getBooleanAttr(Provisioning.A_zimbraFeatureMailForwardingEnabled, false))
throw ServiceException.PERM_DENIED("forwarding not enabled");
}
// call modifyAttrs and pass true to checkImmutable
Provisioning.getInstance().modifyAttrs(account, prefs, true, zsc.getAuthToken());
Element response = zsc.createElement(AccountConstants.MODIFY_PREFS_RESPONSE);
return response;
}
Aggregations