use of com.zimbra.cs.account.Cos in project zm-mailbox by Zimbra.
the class PurgeTest method completeCosRetentionPolicy.
@Test
public void completeCosRetentionPolicy() throws Exception {
RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
Config config = Provisioning.getInstance().getConfig();
Policy keep1 = mgr.createSystemKeepPolicy(config, "keep1", "300d");
Map<String, Object> attrs = new HashMap<String, Object>();
Cos cos = Provisioning.getInstance().createCos("testcos2", attrs);
Policy keep2 = mgr.createSystemKeepPolicy(cos, "keep2", "600d");
// Assign cos to the account
getAccount().setCOSId(cos.getId());
// Create mailbox policy that references the system policy, and confirm that
// lookup returns the latest values.
RetentionPolicy mboxRP1 = new RetentionPolicy(Arrays.asList(Policy.newSystemPolicy(keep2.getId())), null);
RetentionPolicy completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP1);
Policy latest = completeRP.getKeepPolicy().get(0);
assertEquals(keep2, latest);
// Modify cos policy and confirm that the accessor returns the latest values.
mgr.modifySystemPolicy(cos, keep2.getId(), "new keep2", "301d");
completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP1);
latest = completeRP.getKeepPolicy().get(0);
assertFalse(keep2.equals(latest));
assertEquals(keep2.getId(), latest.getId());
assertEquals("new keep2", latest.getName());
assertEquals("301d", latest.getLifetime());
// Make sure system policy does not apply to this user.
RetentionPolicy mboxRP2 = new RetentionPolicy(Arrays.asList(Policy.newSystemPolicy(keep1.getId())), null);
completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP2);
assertTrue(completeRP.getKeepPolicy().isEmpty());
// remove cos retention policy
mgr.deleteSystemPolicy(cos, keep2.getId());
// make sure account retention policy is empty
completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP1);
assertTrue(completeRP.getKeepPolicy().isEmpty());
// make sure system policy is applicable now
completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP2);
latest = completeRP.getKeepPolicy().get(0);
assertTrue(keep1.equals(latest));
assertEquals(keep1.getId(), latest.getId());
assertEquals("keep1", latest.getName());
assertEquals("300d", latest.getLifetime());
}
use of com.zimbra.cs.account.Cos 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.Cos in project zm-mailbox by Zimbra.
the class PseudoTarget method createPseudoTarget.
/**
* construct a pseudo target
*
* if targetType is a domain-ed type: account. cr, dl:
* then exactly one of the following must be passed in:
* - domainBy == null
* domainStr == null
* createPseudoDomain == true
* or
* - domainBy != null
* domainStr != null
* createPseudoDomain == false
*
* @param prov
* @param targetType
* @param domainBy
* @param domainStr
* @param createPseudoDomain
* @param cosBy
* @param cosStr
* @param domainName used only when targetType is domain, ignored otherwise.
* if not null, the pseudo domain will be created with the provided domainName,
* not a pseudo name.
* This is only used/needed for computing settable attrs when creating a domain.
* We need to be able to traverse the domain hierarchy for grants with the subDomain modifier.
* @return
* @throws ServiceException
*/
public static Entry createPseudoTarget(Provisioning prov, TargetType targetType, Key.DomainBy domainBy, String domainStr, boolean createPseudoDomain, Key.CosBy cosBy, String cosStr, String domainName) throws ServiceException {
Entry targetEntry = null;
Config config = prov.getConfig();
String zimbraId = PseudoZimbraId.getPseudoZimbraId();
Map<String, Object> attrMap = new HashMap<String, Object>();
attrMap.put(Provisioning.A_zimbraId, zimbraId);
Domain pseudoDomain = null;
Domain domain = null;
if (targetType == TargetType.account || targetType == TargetType.calresource || targetType == TargetType.dl || targetType == TargetType.group) {
if (createPseudoDomain) {
domain = pseudoDomain = (Domain) createPseudoTarget(prov, TargetType.domain, null, null, false, null, null);
} else {
if (domainBy == null || domainStr == null)
throw ServiceException.INVALID_REQUEST("domainBy and domain identifier is required", null);
domain = prov.get(domainBy, domainStr);
}
if (domain == null) {
throw AccountServiceException.NO_SUCH_DOMAIN(domainStr);
}
}
switch(targetType) {
case account:
case calresource:
Cos cos = null;
if (cosBy != null && cosStr != null) {
cos = prov.get(cosBy, cosStr);
if (cos == null) {
throw AccountServiceException.NO_SUCH_COS(cosStr);
}
attrMap.put(Provisioning.A_zimbraCOSId, cos.getId());
} else {
String domainCosId = domain != null ? domain.getAttr(Provisioning.A_zimbraDomainDefaultCOSId, null) : null;
if (domainCosId != null) {
cos = prov.get(Key.CosBy.id, domainCosId);
}
if (cos == null) {
cos = prov.get(Key.CosBy.name, Provisioning.DEFAULT_COS_NAME);
}
}
if (targetType == TargetType.account) {
targetEntry = new PseudoAccount("pseudo@" + domain.getName(), zimbraId, attrMap, cos.getAccountDefaults(), prov, pseudoDomain);
} else {
targetEntry = new PseudoCalendarResource("pseudo@" + domain.getName(), zimbraId, attrMap, cos.getAccountDefaults(), prov, pseudoDomain);
}
break;
case cos:
targetEntry = new PseudoCos("pseudocos", zimbraId, attrMap, prov);
break;
case dl:
targetEntry = new PseudoDistributionList("pseudo@" + domain.getName(), zimbraId, attrMap, prov, pseudoDomain);
break;
case group:
targetEntry = new PseudoDynamicGroup("pseudo@" + domain.getName(), zimbraId, attrMap, prov, pseudoDomain);
break;
case domain:
String name = domainName == null ? "pseudo.pseudo" : domainName;
targetEntry = new PseudoDomain(name, zimbraId, attrMap, config.getDomainDefaults(), prov);
break;
case server:
targetEntry = new PseudoServer("pseudo.pseudo", zimbraId, attrMap, config.getServerDefaults(), prov);
break;
case alwaysoncluster:
targetEntry = new PseudoAlwaysOnCluster("pseudo.pseudo", zimbraId, attrMap, null, prov);
break;
case ucservice:
targetEntry = new PseudoUCService("pseudo", zimbraId, attrMap, prov);
break;
case xmppcomponent:
targetEntry = new PseudoXMPPComponent("pseudo", zimbraId, attrMap, prov);
break;
case zimlet:
targetEntry = new PseudoZimlet("pseudo", zimbraId, attrMap, prov);
break;
default:
throw ServiceException.INVALID_REQUEST("unsupported target for createPseudoTarget: " + targetType.getCode(), null);
}
return targetEntry;
}
use of com.zimbra.cs.account.Cos in project zm-mailbox by Zimbra.
the class DataSourceCallback method scheduleCos.
/**
* Updates data source schedules for all accounts that are on the current server
* and in the given COS.
*/
private void scheduleCos(Cos cos) throws ServiceException {
ZimbraLog.datasource.info("Updating schedule for all DataSources for all accounts in COS %s.", cos.getName());
List<Account> accts;
Provisioning prov = Provisioning.getInstance();
// Look up all account id's for this server
if (prov instanceof LdapProv)
accts = lookupAccountsFromLDAP(prov, cos.getId());
else
accts = lookupAccountsFromDB(prov);
// Update schedules for all data sources on this server
for (Account account : accts) {
if (account != null && Provisioning.ACCOUNT_STATUS_ACTIVE.equals(account.getAccountStatus(prov))) {
Cos accountCos = prov.getCOS(account);
if (accountCos != null && cos.getId().equals(accountCos.getId())) {
scheduleAccount(account);
}
}
}
}
use of com.zimbra.cs.account.Cos 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);
}
}
Aggregations