use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method searchCOS.
private List<Cos> searchCOS(ZLdapFilter filter, ZLdapContext initZlc) throws ServiceException {
List<Cos> result = new ArrayList<Cos>();
try {
ZSearchResultEnumeration ne = helper.searchDir(mDIT.cosBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE(), initZlc, LdapServerType.REPLICA);
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
result.add(new LdapCos(sr.getDN(), sr.getAttributes(), this));
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup cos via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
}
return result;
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllIdentities.
@Override
public List<Identity> getAllIdentities(Account account) throws ServiceException {
LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
if (ldapEntry == null)
throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
@SuppressWarnings("unchecked") List<Identity> result = (List<Identity>) account.getCachedData(IDENTITY_LIST_CACHE_KEY);
if (result != null) {
return result;
}
result = getIdentitiesByQuery(ldapEntry, filterFactory.allIdentities(), null);
for (Identity identity : result) {
// gross hack for 4.5beta. should be able to remove post 4.5
if (identity.getId() == null) {
String id = LdapUtil.generateUUID();
identity.setId(id);
Map<String, Object> newAttrs = new HashMap<String, Object>();
newAttrs.put(Provisioning.A_zimbraPrefIdentityId, id);
try {
modifyIdentity(account, identity.getName(), newAttrs);
} catch (ServiceException se) {
ZimbraLog.account.warn("error updating identity: " + account.getName() + " " + identity.getName() + " " + se.getMessage(), se);
}
}
}
result.add(getDefaultIdentity(account));
result = Collections.unmodifiableList(result);
account.setCachedData(IDENTITY_LIST_CACHE_KEY, result);
return result;
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method createUCService.
@Override
public UCService createUCService(String name, Map<String, Object> attrs) throws ServiceException {
name = name.toLowerCase().trim();
CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
AttributeManager.getInstance().preModify(attrs, null, callbackContext, true);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_UCSERVICE);
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(attrs);
Set<String> ocs = LdapObjectClass.getUCServiceObjectClasses(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, name);
String dn = mDIT.ucServiceNameToDN(name);
entry.setDN(dn);
zlc.createEntry(entry);
UCService ucService = getUCServiceById(zimbraIdStr, zlc, true);
AttributeManager.getInstance().postModify(attrs, ucService, callbackContext);
return ucService;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.SERVER_EXISTS(name);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to create ucservice: " + name, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method refreshEntry.
void refreshEntry(Entry entry, ZLdapContext initZlc) throws ServiceException {
try {
String dn = ((LdapEntry) entry).getDN();
ZAttributes attributes = helper.getAttributes(initZlc, dn);
Map<String, Object> attrs = attributes.getAttrs();
Map<String, Object> defaults = null;
Map<String, Object> secondaryDefaults = null;
Map<String, Object> overrideDefaults = null;
if (entry instanceof Account) {
//
// We can get here from either modifyAttrsInternal or reload path.
//
// If we got here from modifyAttrsInternal, zimbraCOSId on account
// might have been changed, added, removed, but entry now still contains
// the old attrs. Create a temp Account object from the new attrs, and then
// use the same cos of the temp Account object for our entry object.
//
// If we got here from reload, attrs are likely not changed, the callsites
// just want a refreshed object. For this case it's best if we still
// always resolve the COS correctly. makeAccount is a cheap call and won't
// add any overhead like loading cos/domain from LDAP: even if cos/domain
// has to be loaded (because not in cache) in the getCOS(temp) call, it's
// just the same as calling (buggy) getCOS(entry) before.
//
// We only need the temp object for the getCOS call, don't need to setup
// primary/secondary defaults on the temp object because:
// zimbraCOSId is only on account(of course), and that's all needed
// for determining the COS for the account in the getCOS call: if
// zimbraCOSId is not set on account, it will fallback to the domain
// default COS, then fallback to the system default COS.
//
Account temp = makeAccountNoDefaults(dn, attributes);
Cos cos = getCOS(temp);
if (cos != null)
defaults = cos.getAccountDefaults();
Domain domain = getDomain((Account) entry);
if (domain != null)
secondaryDefaults = domain.getAccountDefaults();
} else if (entry instanceof Domain) {
defaults = getConfig().getDomainDefaults();
} else if (entry instanceof Server) {
defaults = getConfig().getServerDefaults();
AlwaysOnCluster aoc = getAlwaysOnCluster((Server) entry);
if (aoc != null) {
overrideDefaults = aoc.getServerOverrides();
}
}
if (defaults == null && secondaryDefaults == null)
entry.setAttrs(attrs);
else
entry.setAttrs(attrs, defaults, secondaryDefaults, overrideDefaults);
extendLifeInCacheOrFlush(entry);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to refresh entry", e);
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method renameXMPPComponent.
// Only called from renameDomain for now
void renameXMPPComponent(String zimbraId, String newName) throws ServiceException {
LdapXMPPComponent comp = (LdapXMPPComponent) get(Key.XMPPComponentBy.id, zimbraId);
if (comp == null)
throw AccountServiceException.NO_SUCH_XMPP_COMPONENT(zimbraId);
newName = newName.toLowerCase().trim();
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.RENAME_XMPPCOMPONENT);
String newDn = mDIT.xmppcomponentNameToDN(newName);
zlc.renameEntry(comp.getDN(), newDn);
// remove old comp from cache
xmppComponentCache.remove(comp);
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.IM_COMPONENT_EXISTS(newName);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to rename XMPPComponent: " + zimbraId, e);
} finally {
LdapClient.closeContext(zlc);
}
}
Aggregations