use of com.zimbra.cs.account.ldap.entry.LdapServer in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllServers.
@Override
public List<Server> getAllServers(String service) throws ServiceException {
List<Server> result = new ArrayList<Server>();
ZLdapFilter filter;
if (service != null) {
filter = filterFactory.serverByService(service);
} else {
filter = filterFactory.allServers();
}
try {
Map<String, Object> serverDefaults = getConfig().getServerDefaults();
ZSearchResultEnumeration ne = helper.searchDir(mDIT.serverBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
LdapServer s = new LdapServer(sr.getDN(), sr.getAttributes(), serverDefaults, this);
result.add(s);
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to list all servers", e);
}
if (result.size() > 0)
serverCache.put(result, true);
Collections.sort(result);
return result;
}
use of com.zimbra.cs.account.ldap.entry.LdapServer in project zm-mailbox by Zimbra.
the class LdapProvisioning method deleteServer.
@Override
public void deleteServer(String zimbraId) throws ServiceException {
LdapServer server = (LdapServer) getServerByIdInternal(zimbraId);
if (server == null)
throw AccountServiceException.NO_SUCH_SERVER(zimbraId);
// check that no account is still on this server
long numAcctsOnServer = getNumAccountsOnServer(server);
if (numAcctsOnServer != 0) {
throw ServiceException.INVALID_REQUEST("There are " + numAcctsOnServer + " account(s) on this server.", null);
}
String monitorHost = getConfig().getAttr(Provisioning.A_zimbraLogHostname);
String serverName = server.getName();
if (monitorHost != null && monitorHost.trim().equals(serverName)) {
throw ServiceException.INVALID_REQUEST("zimbraLogHostname is set to " + serverName, null);
}
String[] attributesToRemove = { Provisioning.A_zimbraReverseProxyAvailableLookupTargets, Provisioning.A_zimbraReverseProxyUpstreamEwsServers, Provisioning.A_zimbraReverseProxyUpstreamLoginServers };
removeAttrsForServer(attributesToRemove, server.getName());
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_SERVER);
removeServerFromAllCOSes(zimbraId, server.getName(), zlc);
zlc.deleteEntry(server.getDN());
serverCache.remove(server);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to purge server: " + zimbraId, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.account.ldap.entry.LdapServer in project zm-mailbox by Zimbra.
the class LdapProvisioning method getServerByName.
private Server getServerByName(String name, boolean nocache) throws ServiceException {
if (!nocache) {
Server s = serverCache.getByName(name);
if (s != null)
return s;
}
try {
String dn = mDIT.serverNameToDN(name);
ZAttributes attrs = helper.getAttributes(LdapUsage.GET_SERVER, dn);
LdapServer s = new LdapServer(dn, attrs, getConfig().getServerDefaults(), this);
serverCache.put(s);
return s;
} catch (LdapEntryNotFoundException e) {
return null;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup server by name: " + name + " message: " + e.getMessage(), e);
}
}
Aggregations