Search in sources :

Example 86 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.

the class LdapProvisioning method refreshUserCredentials.

@Override
public void refreshUserCredentials(Account account) throws ServiceException {
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.REPLICA, LdapUsage.GET_ENTRY);
        String[] returnAttrs = { "userPassword", "zimbraAuthTokens", "zimbraAuthTokenValidityValue" };
        ZAttributes attrs = helper.getAttributes(zlc, ((LdapEntry) account).getDN(), returnAttrs);
        Map<String, Object> finalAttrs = account.getAttrs(false, false);
        finalAttrs.putAll(attrs.getAttrs());
        account.setAttrs(finalAttrs);
        // Put this back into the cache
        extendLifeInCacheOrFlush(account);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE(String.format("unable to refresh userPassword for '%s'", account.getName()), e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : 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) ZAttributes(com.zimbra.cs.ldap.ZAttributes)

Example 87 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.

the class AutoProvision method getExternalAttrsByDn.

protected ZAttributes getExternalAttrsByDn(String dn) throws ServiceException {
    String url = domain.getAutoProvLdapURL();
    boolean wantStartTLS = domain.isAutoProvLdapStartTlsEnabled();
    String adminDN = domain.getAutoProvLdapAdminBindDn();
    String adminPassword = domain.getAutoProvLdapAdminBindPassword();
    ExternalLdapConfig config = new ExternalLdapConfig(url, wantStartTLS, null, adminDN, adminPassword, null, "auto provision account");
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getExternalContext(config, LdapUsage.AUTO_PROVISION);
        return prov.getHelper().getAttributes(zlc, dn, getAttrsToFetch());
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ExternalLdapConfig(com.zimbra.cs.ldap.LdapServerConfig.ExternalLdapConfig) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext)

Example 88 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.

the class ExternalGroup method searchGroup.

private static ExternalGroup searchGroup(DomainBy domainBy, String extGroupGrantee, boolean asAdmin) throws ServiceException {
    LdapProv prov = LdapProv.getInst();
    ExternalGroupInfo extGrpInfo = ExternalGroupInfo.parse(extGroupGrantee);
    String zimbraDomain = extGrpInfo.getZimbraDmain();
    String extGroupName = extGrpInfo.getExternalGroupName();
    Domain domain = prov.get(domainBy, zimbraDomain);
    if (domain == null) {
        throw AccountServiceException.NO_SUCH_DOMAIN(zimbraDomain);
    }
    String searchBase = domain.getExternalGroupLdapSearchBase();
    String filterTemplate = domain.getExternalGroupLdapSearchFilter();
    if (searchBase == null) {
        searchBase = LdapConstants.DN_ROOT_DSE;
    }
    String searchFilter = LdapUtil.computeDn(extGroupName, filterTemplate);
    GroupHandler groupHandler = getGroupHandler(domain);
    ZLdapContext zlc = null;
    try {
        zlc = groupHandler.getExternalDelegatedAdminGroupsLdapContext(domain, asAdmin);
        ZSearchResultEntry entry = prov.getHelper().searchForEntry(searchBase, FilterId.EXTERNAL_GROUP, searchFilter, zlc, new String[] { "mail" });
        if (entry != null) {
            return makeExternalGroup(domain, groupHandler, extGroupName, entry.getDN(), entry.getAttributes());
        } else {
            return null;
        }
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) GroupHandler(com.zimbra.cs.account.grouphandler.GroupHandler) Domain(com.zimbra.cs.account.Domain) ExternalGroupInfo(com.zimbra.cs.account.accesscontrol.ZimbraACE.ExternalGroupInfo) LdapProv(com.zimbra.cs.account.ldap.LdapProv) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 89 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.

the class UpgradeOp method replaceAttrs.

protected void replaceAttrs(ZLdapContext initZlc, String dn, ZMutableEntry entry) throws ServiceException {
    Map<String, Object> attrs = entry.getAttributes().getAttrs();
    if (attrs.size() == 0) {
        return;
    }
    printModAttrs(dn, attrs);
    ZLdapContext zlc = initZlc;
    try {
        if (zlc == null) {
            zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
        }
        zlc.replaceAttributes(dn, entry.getAttributes());
    } finally {
        if (initZlc == null) {
            LdapClient.closeContext(zlc);
        }
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext)

Example 90 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.

the class BUG_75450 method doUpgrade.

@Override
void doUpgrade() throws ServiceException {
    ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
    try {
        doDomains(zlc);
        doCos(zlc);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext)

Aggregations

ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)126 ServiceException (com.zimbra.common.service.ServiceException)65 AccountServiceException (com.zimbra.cs.account.AccountServiceException)62 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)60 LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)23 LdapException (com.zimbra.cs.ldap.LdapException)22 ZMutableEntry (com.zimbra.cs.ldap.ZMutableEntry)21 Domain (com.zimbra.cs.account.Domain)19 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)18 CallbackContext (com.zimbra.cs.account.callback.CallbackContext)16 Date (java.util.Date)16 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)14 HashMap (java.util.HashMap)14 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)13 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)12 Account (com.zimbra.cs.account.Account)11 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)11 ZAttributes (com.zimbra.cs.ldap.ZAttributes)10 HashSet (java.util.HashSet)10 GuestAccount (com.zimbra.cs.account.GuestAccount)9