use of com.zimbra.cs.account.AttributeManager in project zm-mailbox by Zimbra.
the class GetInfo method doAttrs.
static void doAttrs(Account acct, String locale, Element response, Map<String, Object> attrsMap) throws ServiceException {
AttributeManager attrMgr = AttributeManager.getInstance();
Set<String> attrList = attrMgr.getAttrsWithFlag(AttributeFlag.accountInfo);
Set<String> acctAttrs = attrMgr.getAllAttrsInClass(AttributeClass.account);
Set<String> domainAttrs = attrMgr.getAllAttrsInClass(AttributeClass.domain);
Set<String> serverAttrs = attrMgr.getAllAttrsInClass(AttributeClass.server);
Set<String> configAttrs = attrMgr.getAllAttrsInClass(AttributeClass.globalConfig);
Provisioning prov = Provisioning.getInstance();
Domain domain = prov.getDomain(acct);
Server server = acct.getServer();
Config config = prov.getConfig();
for (String key : attrList) {
Object value = null;
if (Provisioning.A_zimbraLocale.equals(key)) {
value = locale;
} else if (Provisioning.A_zimbraAttachmentsBlocked.equals(key)) {
// leave this a special case for now, until we have enough incidences to make it a pattern
value = config.isAttachmentsBlocked() || acct.isAttachmentsBlocked() ? ProvisioningConstants.TRUE : ProvisioningConstants.FALSE;
} else {
value = attrsMap.get(key);
if (value == null) {
// no value on account/cos
if (!acctAttrs.contains(key)) {
// see if it is on domain, server, or globalconfig
if (domainAttrs.contains(key)) {
if (domain != null) {
// value on domain/global config (domainInherited)
value = domain.getMultiAttr(key);
}
} else if (serverAttrs.contains(key)) {
// value on server/global config (serverInherited)
value = server.getMultiAttr(key);
} else if (configAttrs.contains(key)) {
// value on global config
value = config.getMultiAttr(key);
}
}
}
}
ToXML.encodeAttr(response, key, value);
}
}
use of com.zimbra.cs.account.AttributeManager in project zm-mailbox by Zimbra.
the class GetCos method encodeCos.
public static void encodeCos(Element e, Cos c, Set<String> reqAttrs, AttrRightChecker attrRightChecker) throws ServiceException {
Config config = Provisioning.getInstance().getConfig();
Element cos = e.addNonUniqueElement(AdminConstants.E_COS);
cos.addAttribute(AdminConstants.A_NAME, c.getName());
cos.addAttribute(AdminConstants.E_ID, c.getId());
if (c.isDefaultCos())
cos.addAttribute(AdminConstants.A_IS_DEFAULT_COS, true);
Map attrs = c.getUnicodeAttrs();
AttributeManager attrMgr = AttributeManager.getInstance();
for (Iterator mit = attrs.entrySet().iterator(); mit.hasNext(); ) {
Map.Entry entry = (Entry) mit.next();
String name = (String) entry.getKey();
Object value = entry.getValue();
if (reqAttrs != null && !reqAttrs.contains(name))
continue;
boolean allowed = attrRightChecker == null ? true : attrRightChecker.allowAttr(name);
boolean isCosAttr = !attrMgr.isAccountInherited(name);
if (value instanceof String[]) {
String[] sv = (String[]) value;
for (int i = 0; i < sv.length; i++) {
encodeCosAttr(cos, name, sv[i], isCosAttr, allowed);
}
} else if (value instanceof String) {
value = com.zimbra.cs.service.account.ToXML.fixupZimbraPrefTimeZoneId(name, (String) value);
encodeCosAttr(cos, name, (String) value, isCosAttr, allowed);
}
}
}
use of com.zimbra.cs.account.AttributeManager in project zm-mailbox by Zimbra.
the class GetAttributeInfo method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
String[] attrs = null;
String attrsRequested = request.getAttribute(AdminConstants.A_ATTRS, null);
if (attrsRequested != null) {
attrs = attrsRequested.split(",");
}
String[] entryTypes = null;
String entryTypesRequested = request.getAttribute(AdminConstants.A_ENTRY_TYPES, null);
if (entryTypesRequested != null) {
entryTypes = entryTypesRequested.split(",");
}
if (attrs != null && entryTypes != null) {
throw ServiceException.INVALID_REQUEST("only one of " + AdminConstants.A_ATTRS + " or " + AdminConstants.A_ENTRY_TYPES + " can be specified", null);
}
AttributeManager attrMgr = AttributeManager.getInstance();
Element response = zsc.createElement(AdminConstants.GET_ATTRIBUTE_INFO_RESPONSE);
if (attrs != null) {
for (String attr : attrs) {
encodeAttr(response, attrMgr, attr.trim());
}
} else if (entryTypes != null) {
for (String entry : entryTypes) {
AttributeClass attrClass = AttributeClass.fromString(entry.trim());
TreeSet<String> attrsOnEntry = new TreeSet<String>(attrMgr.getAllAttrsInClass(attrClass));
for (String attr : attrsOnEntry) {
encodeAttr(response, attrMgr, attr);
}
}
} else {
// AttributeManager.getAllAttrs() only contains attrs with AttributeInfo,
// not extension attrs
// attrs = new TreeSet<String>(am.getAllAttrs());
//
// attr sets for each AttributeClass contain attrs in the extensions, use them
TreeSet<String> allAttrs = new TreeSet<String>();
for (AttributeClass ac : AttributeClass.values()) {
allAttrs.addAll(attrMgr.getAllAttrsInClass(ac));
}
for (String attr : allAttrs) {
encodeAttr(response, attrMgr, attr);
}
}
return response;
}
use of com.zimbra.cs.account.AttributeManager in project zm-mailbox by Zimbra.
the class UBIDMutableEntry method mapToAttrs.
// ZMutableEntry
@Override
public void mapToAttrs(Map<String, Object> mapAttrs) {
AttributeManager attrMgr = AttributeManager.getInst();
for (Map.Entry<String, Object> me : mapAttrs.entrySet()) {
String attrName = me.getKey();
Object v = me.getValue();
boolean containsBinaryData = attrMgr == null ? false : attrMgr.containsBinaryData(attrName);
boolean isBinaryTransfer = attrMgr == null ? false : attrMgr.isBinaryTransfer(attrName);
if (v instanceof String) {
ASN1OctetString value = UBIDUtil.newASN1OctetString(containsBinaryData, (String) v);
Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, value);
entry.addAttribute(a);
} else if (v instanceof String[]) {
String[] sa = (String[]) v;
ASN1OctetString[] values = new ASN1OctetString[sa.length];
for (int i = 0; i < sa.length; i++) {
values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, sa[i]);
}
Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
entry.addAttribute(a);
} else if (v instanceof Collection) {
Collection c = (Collection) v;
ASN1OctetString[] values = new ASN1OctetString[c.size()];
int i = 0;
for (Object o : c) {
values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, o.toString());
i++;
}
Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
entry.addAttribute(a);
}
}
}
use of com.zimbra.cs.account.AttributeManager in project zm-mailbox by Zimbra.
the class ToXML method encodeAttrs.
private static void encodeAttrs(Element e, Map attrs, String key, Set<String> reqAttrs, AttrRightChecker attrRightChecker) {
AttributeManager attrMgr = null;
try {
attrMgr = AttributeManager.getInstance();
} catch (ServiceException se) {
ZimbraLog.account.warn("failed to get AttributeManager instance", se);
}
for (Iterator iter = attrs.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Entry) iter.next();
String name = (String) entry.getKey();
Object value = entry.getValue();
// Never return data source passwords
if (name.equalsIgnoreCase(Provisioning.A_zimbraDataSourcePassword))
continue;
value = Provisioning.sanitizedAttrValue(name, value);
// only returns requested attrs
if (reqAttrs != null && !reqAttrs.contains(name))
continue;
boolean allowed = attrRightChecker == null ? true : attrRightChecker.allowAttr(name);
IDNType idnType = AttributeManager.idnType(attrMgr, name);
if (value instanceof String[]) {
String[] sv = (String[]) value;
for (int i = 0; i < sv.length; i++) {
encodeAttr(e, name, sv[i], AccountConstants.E_A, key, idnType, allowed);
}
} else if (value instanceof String) {
value = fixupZimbraPrefTimeZoneId(name, (String) value);
encodeAttr(e, name, (String) value, AccountConstants.E_A, key, idnType, allowed);
}
}
}
Aggregations