Search in sources :

Example 1 with LdapServer

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;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 2 with LdapServer

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);
    }
}
Also used : InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException)

Example 3 with LdapServer

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);
    }
}
Also used : InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) ZAttributes(com.zimbra.cs.ldap.ZAttributes)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)3 LdapServer (com.zimbra.cs.account.ldap.entry.LdapServer)3 InMemoryLdapServer (com.zimbra.cs.ldap.unboundid.InMemoryLdapServer)3 Server (com.zimbra.cs.account.Server)2 LdapEntryNotFoundException (com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException)1 ZAttributes (com.zimbra.cs.ldap.ZAttributes)1 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)1 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)1 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)1 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)1 ArrayList (java.util.ArrayList)1