use of com.zimbra.cs.account.AttributeManager 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.AttributeManager in project zm-mailbox by Zimbra.
the class AttributeConstraint method main.
/**
* @param args
*/
public static void main(String[] args) throws ServiceException {
Provisioning prov = Provisioning.getInstance();
AttributeManager am = AttributeManager.getInstance();
AttributeConstraint.fromString(am, "zimbraPasswordMinLength:min=6");
AttributeConstraint.fromString(am, "zimbraPasswordMaxLength:min=64");
AttributeConstraint.fromString(am, "zimbraPasswordMinLength:min=6:max=64:values=1,2,3");
AttributeConstraint.fromString(am, "zimbraFeatureMailEnabled:values=FALSE,TRUE");
Account acct = prov.get(Key.AccountBy.name, "user1@phoebe.mac");
Cos cos = prov.getCOS(acct);
cos.unsetConstraint();
Map<String, Object> cosConstraints = new HashMap<String, Object>();
// integer
cos.addConstraint("zimbraPasswordMinLength:min=6:max=10:values=8,9", cosConstraints);
// long
long longMax = Long.MAX_VALUE;
long longMaxMinusOne = longMax - 1;
cos.addConstraint("zimbraMailQuota:max=" + longMaxMinusOne, cosConstraints);
// duration
cos.addConstraint("zimbraPasswordLockoutDuration:min=5h:max=1d", cosConstraints);
// gentime
cos.addConstraint("zimbraPrefPop3DownloadSince:min=20060315023000Z", cosConstraints);
// string
cos.addConstraint("zimbraPrefGroupMailBy:values=conversation", cosConstraints);
// bad constraint, invalid min constraint
cos.addConstraint("zimbraCalendarMaxRevisions:min=zz:max=10", cosConstraints);
// multi-value
cos.addConstraint("zimbraZimletAvailableZimlets:values=A,B,C", cosConstraints);
prov.modifyAttrs(cos, cosConstraints);
Map<String, AttributeConstraint> constraints = getConstraint(cos);
// integer
test(constraints, "zimbraPasswordMinLength", "5", true);
test(constraints, "zimbraPasswordMinLength", "6", true);
test(constraints, "zimbraPasswordMinLength", "7", true);
test(constraints, "zimbraPasswordMinLength", "8", false);
test(constraints, "zimbraPasswordMinLength", "9", false);
test(constraints, "zimbraPasswordMinLength", "10", true);
test(constraints, "zimbraPasswordMinLength", "11", true);
// long
test(constraints, "zimbraMailQuota", "" + longMaxMinusOne, false);
test(constraints, "zimbraMailQuota", "" + longMax, true);
// duration
test(constraints, "zimbraPasswordLockoutDuration", "3h", true);
test(constraints, "zimbraPasswordLockoutDuration", "25h", true);
test(constraints, "zimbraPasswordLockoutDuration", "30m", true);
test(constraints, "zimbraPasswordLockoutDuration", "5h", false);
test(constraints, "zimbraPasswordLockoutDuration", "600m", false);
test(constraints, "zimbraPasswordLockoutDuration", "24h", false);
// gentime
test(constraints, "zimbraPrefPop3DownloadSince", "20050315023000Z", true);
test(constraints, "zimbraPrefPop3DownloadSince", "20060315023000Z", false);
test(constraints, "zimbraPrefPop3DownloadSince", "20060315023001Z", false);
// string, enum, ...
test(constraints, "zimbraPrefGroupMailBy", "message", true);
test(constraints, "zimbraPrefGroupMailBy", "conversation", false);
// bad constraint
test(constraints, "zimbraCalendarMaxRevisions", "1", false);
test(constraints, "zimbraCalendarMaxRevisions", "10", false);
test(constraints, "zimbraCalendarMaxRevisions", "11", true);
// multi-value
test(constraints, "zimbraZimletAvailableZimlets", new String[] { "A", "B" }, false);
test(constraints, "zimbraZimletAvailableZimlets", new String[] { "A", "X" }, true);
// no constraint
test(constraints, "zimbraPasswordMaxLength", "100", false);
}
use of com.zimbra.cs.account.AttributeManager 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.AttributeManager in project zm-mailbox by Zimbra.
the class ZLdapHelper method getModList.
private ZModificationList getModList(ZLdapContext zlc, String dn, Map<String, ? extends Object> attrs, Entry entry) throws ServiceException {
ZModificationList modList = zlc.createModificationList();
AttributeManager attrMgr = AttributeManager.getInst();
for (Map.Entry<String, ? extends Object> attr : attrs.entrySet()) {
Object v = attr.getValue();
String key = attr.getKey();
boolean doAdd = key.charAt(0) == '+';
boolean doRemove = key.charAt(0) == '-';
if (doAdd || doRemove) {
// make sure there aren't other changes without +/- going on at the same time
key = key.substring(1);
if (attrs.containsKey(key))
throw ServiceException.INVALID_REQUEST("can't mix +attrName/-attrName with attrName", null);
}
boolean containsBinaryData = attrMgr == null ? false : attrMgr.containsBinaryData(key);
boolean isBinaryTransfer = attrMgr == null ? false : attrMgr.isBinaryTransfer(key);
// Convert array to List so it can be treated as a Collection
if (v instanceof Object[]) {
// Note: Object[] cast is required, so that asList() knows to create a List
// that contains the contents of the object array, as opposed to a List with one
// element, which is the entire Object[]. Ick.
v = Arrays.asList((Object[]) v);
}
if (v instanceof Collection) {
Collection c = (Collection) v;
if (c.size() == 0) {
// make sure it exists
if (entry.getAttr(key, false) != null) {
modList.removeAttr(key, isBinaryTransfer);
}
} else {
// Convert values Collection to a String array
String[] sa = new String[c.size()];
int i = 0;
for (Object o : c) {
sa[i++] = (o == null ? null : o.toString());
}
// Add attrs
if (doAdd) {
modList.addAttr(key, sa, entry, containsBinaryData, isBinaryTransfer);
} else if (doRemove) {
modList.removeAttr(key, sa, entry, containsBinaryData, isBinaryTransfer);
} else {
modList.modifyAttr(key, sa, containsBinaryData, isBinaryTransfer);
}
}
} else if (v instanceof Map) {
throw ServiceException.FAILURE("Map is not a supported value type", null);
} else {
String s = (v == null ? null : v.toString());
if (doAdd) {
modList.addAttr(key, s, entry, containsBinaryData, isBinaryTransfer);
} else if (doRemove) {
modList.removeAttr(key, s, entry, containsBinaryData, isBinaryTransfer);
} else {
modList.modifyAttr(key, s, entry, containsBinaryData, isBinaryTransfer);
}
}
}
return modList;
}
use of com.zimbra.cs.account.AttributeManager in project zm-mailbox by Zimbra.
the class ToXML method encodeAttrs.
public static void encodeAttrs(Element e, Map attrs, String key, Set<String> reqAttrs, Set<String> hideAttrs, AttrRightChecker attrRightChecker) {
AttributeManager attrMgr = null;
try {
attrMgr = AttributeManager.getInstance();
} catch (ServiceException se) {
ZimbraLog.account.warn("failed to get AttributeManager instance", se);
}
Set<String> reqAttrsLowerCase = null;
if (reqAttrs != null) {
reqAttrsLowerCase = new HashSet<String>();
for (String reqAttr : reqAttrs) {
reqAttrsLowerCase.add(reqAttr.toLowerCase());
}
}
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 (reqAttrsLowerCase != null && !reqAttrsLowerCase.contains(name.toLowerCase())) {
continue;
}
// do not return attrs hidden by protocol
if (hideAttrs != null && hideAttrs.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], AdminConstants.E_A, key, idnType, allowed);
}
} else if (value instanceof String) {
value = com.zimbra.cs.service.account.ToXML.fixupZimbraPrefTimeZoneId(name, (String) value);
encodeAttr(e, name, (String) value, AdminConstants.E_A, key, idnType, allowed);
}
}
}
Aggregations