Search in sources :

Example 11 with AttributeManager

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);
    }
}
Also used : AttributeManager(com.zimbra.cs.account.AttributeManager) Server(com.zimbra.cs.account.Server) Config(com.zimbra.cs.account.Config) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning)

Example 12 with AttributeManager

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);
        }
    }
}
Also used : Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) AttributeManager(com.zimbra.cs.account.AttributeManager) Config(com.zimbra.cs.account.Config) Element(com.zimbra.common.soap.Element) Iterator(java.util.Iterator) Map(java.util.Map)

Example 13 with AttributeManager

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;
}
Also used : AttributeManager(com.zimbra.cs.account.AttributeManager) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) TreeSet(java.util.TreeSet) Element(com.zimbra.common.soap.Element) AttributeClass(com.zimbra.cs.account.AttributeClass)

Example 14 with AttributeManager

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);
        }
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) AttributeManager(com.zimbra.cs.account.AttributeManager) Attribute(com.unboundid.ldap.sdk.Attribute) Collection(java.util.Collection) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Map(java.util.Map)

Example 15 with AttributeManager

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);
        }
    }
}
Also used : Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) AttributeManager(com.zimbra.cs.account.AttributeManager) ServiceException(com.zimbra.common.service.ServiceException) Iterator(java.util.Iterator) Map(java.util.Map) IDNType(com.zimbra.cs.account.AttributeManager.IDNType)

Aggregations

AttributeManager (com.zimbra.cs.account.AttributeManager)19 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ServiceException (com.zimbra.common.service.ServiceException)4 AttributeInfo (com.zimbra.cs.account.AttributeInfo)4 Element (com.zimbra.common.soap.Element)3 IDNType (com.zimbra.cs.account.AttributeManager.IDNType)3 Provisioning (com.zimbra.cs.account.Provisioning)3 Iterator (java.util.Iterator)3 Entry (java.util.Map.Entry)3 Attribute (com.unboundid.ldap.sdk.Attribute)2 AttributeClass (com.zimbra.cs.account.AttributeClass)2 Config (com.zimbra.cs.account.Config)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 Collection (java.util.Collection)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 Version (com.zimbra.common.util.Version)1 Account (com.zimbra.cs.account.Account)1 AttributeFlag (com.zimbra.cs.account.AttributeFlag)1 Cos (com.zimbra.cs.account.Cos)1