use of com.zimbra.cs.account.CalendarResource in project zm-mailbox by Zimbra.
the class LdapProvisioning method modifyAttrsInternal.
/**
* should only be called internally.
*
* @param initCtxt
* @param attrs
* @throws ServiceException
*/
protected void modifyAttrsInternal(Entry entry, ZLdapContext initZlc, Map<String, ? extends Object> attrs, boolean storeEphemeralInLdap) throws ServiceException {
if (entry instanceof Account && !(entry instanceof CalendarResource)) {
Account acct = (Account) entry;
validate(ProvisioningValidator.MODIFY_ACCOUNT_CHECK_DOMAIN_COS_AND_FEATURE, acct.getAttr(A_zimbraMailDeliveryAddress), attrs, acct);
}
if (!storeEphemeralInLdap) {
Map<String, AttributeInfo> ephemeralAttrMap = AttributeManager.getInstance().getEphemeralAttrs();
Map<String, Object> ephemeralAttrs = new HashMap<String, Object>();
// remove after iteration to avoid ConcurrentModificationException
List<String> toRemove = null;
for (Map.Entry<String, ? extends Object> e : attrs.entrySet()) {
String key = e.getKey();
String attrName;
if (key.startsWith("+") || key.startsWith("-")) {
attrName = key.substring(1);
} else {
attrName = key;
}
if (ephemeralAttrMap.containsKey(attrName.toLowerCase())) {
ephemeralAttrs.put(key, e.getValue());
if (null == toRemove) {
// only 3 ephemeral attrs currently
toRemove = Lists.newArrayListWithExpectedSize(3);
}
toRemove.add(key);
}
}
if (null != toRemove) {
for (String key : toRemove) {
attrs.remove(key);
}
}
if (!ephemeralAttrs.isEmpty()) {
modifyEphemeralAttrs(entry, ephemeralAttrs, ephemeralAttrMap);
}
}
modifyLdapAttrs(entry, initZlc, attrs);
}
use of com.zimbra.cs.account.CalendarResource in project zm-mailbox by Zimbra.
the class AdminDocumentHandler method proxyIfNecessary.
@Override
protected Element proxyIfNecessary(Element request, Map<String, Object> context) throws ServiceException {
// if we've explicitly been told to execute here, don't proxy
ZimbraSoapContext zsc = getZimbraSoapContext(context);
if (zsc.getProxyTarget() != null)
return null;
try {
Provisioning prov = Provisioning.getInstance();
Provisioning.Reasons reasons = new Provisioning.Reasons();
// check whether we need to proxy to the home server of a target account
String[] xpath = getProxiedAccountPath();
String acctId = (xpath != null ? getXPath(request, xpath) : null);
if (acctId != null) {
Account acct = getAccount(prov, AccountBy.id, acctId, zsc.getAuthToken());
if (acct != null && !Provisioning.onLocalServer(acct, reasons)) {
ZimbraLog.soap.info("Proxying request: ProxiedAccountPath=%s reason: %s", Joiner.on("/").join(xpath), reasons.getReason());
return proxyRequest(request, context, acctId);
}
}
xpath = getProxiedAccountElementPath();
Element acctElt = (xpath != null ? getXPathElement(request, xpath) : null);
if (acctElt != null) {
Account acct = getAccount(prov, AccountBy.fromString(acctElt.getAttribute(AdminConstants.A_BY)), acctElt.getText(), zsc.getAuthToken());
if (acct != null && !Provisioning.onLocalServer(acct, reasons)) {
ZimbraLog.soap.info("Proxying request: ProxiedAccountElementPath=%s acctElt=%s reason: %s", Joiner.on("/").join(xpath), acctElt.toString(), reasons.getReason());
return proxyRequest(request, context, acct.getId());
}
}
// check whether we need to proxy to the home server of a target calendar resource
xpath = getProxiedResourcePath();
String rsrcId = (xpath != null ? getXPath(request, xpath) : null);
if (rsrcId != null) {
CalendarResource rsrc = getCalendarResource(prov, Key.CalendarResourceBy.id, rsrcId);
if (rsrc != null && !Provisioning.onLocalServer(rsrc, reasons)) {
ZimbraLog.soap.info("Proxying request: ProxiedResourcePath=%s rsrcId=%s reason: %s", Joiner.on("/").join(xpath), rsrcId, reasons.getReason());
return proxyRequest(request, context, rsrcId);
}
}
xpath = getProxiedResourceElementPath();
Element resourceElt = (xpath != null ? getXPathElement(request, xpath) : null);
if (resourceElt != null) {
CalendarResource rsrc = getCalendarResource(prov, Key.CalendarResourceBy.fromString(resourceElt.getAttribute(AdminConstants.A_BY)), resourceElt.getText());
if (rsrc != null && !Provisioning.onLocalServer(rsrc, reasons)) {
ZimbraLog.soap.info("Proxying request: ProxiedResourceElementPath=%s resourceElt=%s reason: %s", Joiner.on("/").join(xpath), resourceElt.toString(), reasons.getReason());
return proxyRequest(request, context, rsrc.getId());
}
}
// check whether we need to proxy to a target server
xpath = getProxiedServerPath();
String serverId = (xpath != null ? getXPath(request, xpath) : null);
if (serverId != null) {
Server server = prov.get(Key.ServerBy.id, serverId);
if (server != null && !getLocalHostId().equalsIgnoreCase(server.getId())) {
ZimbraLog.soap.info("Proxying request: ProxiedServerPath=%s serverId=%s server=%s reason: server ID=%s != localHostId=%s", Joiner.on("/").join(xpath), serverId, server.getName(), server.getId(), getLocalHostId());
return proxyRequest(request, context, server);
}
}
return null;
} catch (ServiceException e) {
// if something went wrong proxying the request, just execute it locally
if (ServiceException.PROXY_ERROR.equals(e.getCode()))
return null;
// but if it's a real error, it's a real error
throw e;
}
}
use of com.zimbra.cs.account.CalendarResource in project zm-mailbox by Zimbra.
the class TestJaxbProvisioning method testCalendarResource.
@Test
public void testCalendarResource() throws Exception {
ZimbraLog.test.debug("Starting testCalendarResource");
deleteCalendarResourceIfExists(testCalRes);
deleteDomainIfExists(testCalResDomain);
Domain dom = prov.createDomain(testCalResDomain, null);
assertNotNull("Domain for " + domain1, dom);
Map<String, Object> attrs = Maps.newHashMap();
attrs.put("displayName", testCalResDisplayName);
attrs.put("zimbraCalResType", "Location");
attrs.put("zimbraCalResLocationDisplayName", "Harare");
CalendarResource calRes = prov.createCalendarResource(testCalRes, TestUtil.DEFAULT_PASSWORD, attrs);
assertNotNull("CalendarResource on create", calRes);
prov.renameCalendarResource(calRes.getId(), testNewCalRes);
List<CalendarResource> resources = prov.getAllCalendarResources(dom, Provisioning.getInstance().getLocalServer());
assertNotNull("CalendarResource List for getAll", resources);
assertEquals("CalendarResource list size", 1, resources.size());
calRes = prov.get(Key.CalendarResourceBy.id, calRes.getId());
prov.deleteCalendarResource(calRes.getId());
}
use of com.zimbra.cs.account.CalendarResource in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method searchAliasTarget.
@Test
public void searchAliasTarget() throws Exception {
Account acct = createAccount(genAcctNameLocalPart("acct"));
CalendarResource cr = createCalendarResource(genAcctNameLocalPart("cr"));
DistributionList dl = createDistributionList(genGroupNameLocalPart("dl"));
DynamicGroup dg = createDynamicGroup(genGroupNameLocalPart("dg"));
// prepend a digit so the order returned from SearchDirectory is predictable
prov.addAlias(acct, TestUtil.getAddress("1-acct-alias", domain.getName()));
prov.addAlias(cr, TestUtil.getAddress("2-cr-alias", domain.getName()));
prov.addGroupAlias(dl, TestUtil.getAddress("3-dl-alias", domain.getName()));
prov.addGroupAlias(dg, TestUtil.getAddress("4-dg-alias", domain.getName()));
SearchDirectoryOptions options = new SearchDirectoryOptions(domain);
options.setTypes(ObjectType.aliases);
options.setSortOpt(SortOpt.SORT_ASCENDING);
options.setFilterString(FilterId.UNITTEST, null);
List<NamedEntry> aliases = prov.searchDirectory(options);
assertEquals(4, aliases.size());
Alias acctAlias = (Alias) aliases.get(0);
Alias crAlias = (Alias) aliases.get(1);
Alias dlAlias = (Alias) aliases.get(2);
Alias dgAlias = (Alias) aliases.get(3);
NamedEntry acctAliasTarget = prov.searchAliasTarget(acctAlias, true);
assertEquals(acct.getId(), acctAliasTarget.getId());
NamedEntry crAliasTarget = prov.searchAliasTarget(crAlias, true);
assertEquals(cr.getId(), crAliasTarget.getId());
NamedEntry dlAliasTarget = prov.searchAliasTarget(dlAlias, true);
assertEquals(dl.getId(), dlAliasTarget.getId());
NamedEntry dgAliasTarget = prov.searchAliasTarget(dgAlias, true);
assertEquals(dg.getId(), dgAliasTarget.getId());
deleteAccount(acct);
deleteAccount(cr);
deleteGroup(dl);
deleteGroup(dg);
}
use of com.zimbra.cs.account.CalendarResource in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method getAllAccounts.
@Test
public void getAllAccounts() throws Exception {
Account acct3 = createAccount(genAcctNameLocalPart("3"));
Account acct2 = createAccount(genAcctNameLocalPart("2"));
Account acct1 = createAccount(genAcctNameLocalPart("1"));
CalendarResource cr = createCalendarResource(genAcctNameLocalPart("cr"));
List<NamedEntry> accounts = prov.getAllAccounts(domain);
Verify.verifyEquals(Lists.newArrayList(acct1, acct2, acct3), accounts, true);
// test the visitor interface, sorting is not supported with visitor interface
final List<NamedEntry> acctsByVisitor = Lists.newArrayList();
NamedEntry.Visitor visitor = new NamedEntry.Visitor() {
@Override
public void visit(NamedEntry entry) throws ServiceException {
acctsByVisitor.add(entry);
}
};
prov.getAllAccounts(domain, visitor);
Verify.verifyEquals(Lists.newArrayList(acct1, acct2, acct3), accounts, false);
deleteAccount(acct1);
deleteAccount(acct2);
deleteAccount(acct3);
deleteAccount(cr);
}
Aggregations