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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
Aggregations