use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class DisplayName method preModify.
@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
if (!((entry instanceof Account) || (entry instanceof DistributionList)))
return;
String displayName;
// update cn only if we are not unsetting display name(cn is required for ZIMBRA_DEFAULT_PERSON_OC)
SingleValueMod mod = singleValueMod(attrName, value);
if (mod.unsetting())
return;
else
displayName = mod.value();
String namingRdnAttr = null;
Provisioning prov = Provisioning.getInstance();
if (prov instanceof LdapProv) {
namingRdnAttr = ((LdapProv) prov).getDIT().getNamingRdnAttr(entry);
}
// update cn only if it is not the naming attr
if (// non LdapProvisioning, pass thru
namingRdnAttr == null || !namingRdnAttr.equals(Provisioning.A_cn)) {
if (!attrsToModify.containsKey(Provisioning.A_cn)) {
attrsToModify.put(Provisioning.A_cn, displayName);
}
}
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class Krb5Principal method getDomainByKrb5Principal.
public static Domain getDomainByKrb5Principal(String principal) throws ServiceException {
Provisioning prov = Provisioning.getInstance();
int idx = principal.indexOf('@');
if (idx != -1) {
String realm = principal.substring(idx + 1);
return prov.get(Key.DomainBy.krb5Realm, realm);
}
return null;
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class LdapObjectClass method main.
/**
* @param args
*/
public static void main(String[] args) throws ServiceException {
Provisioning prov = Provisioning.getInstance();
Set<String> ocs = LdapObjectClass.getCalendarResourceObjectClasses(prov);
for (String oc : ocs) {
System.out.println(oc);
}
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class DataSourceManager method refreshOAuthToken.
public static void refreshOAuthToken(DataSource ds) {
PostMethod postMethod = null;
try {
postMethod = new PostMethod(ds.getOauthRefreshTokenUrl());
postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
postMethod.addParameter(CLIENT_ID, ds.getOauthClientId());
postMethod.addParameter(CLIENT_SECRET, ds.getDecryptedOAuthClientSecret());
postMethod.addParameter(REFRESH_TOKEN, ds.getOauthRefreshToken());
postMethod.addParameter(GRANT_TYPE, REFRESH_TOKEN);
HttpClient httpClient = ZimbraHttpConnectionManager.getExternalHttpConnMgr().getDefaultHttpClient();
int status = httpClient.executeMethod(postMethod);
if (status == HttpStatus.SC_OK) {
ZimbraLog.datasource.info("Refreshed oauth token status=%d", status);
JSONObject response = new JSONObject(postMethod.getResponseBodyAsString());
String oauthToken = response.getString(ACCESS_TOKEN);
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDataSourceOAuthToken, DataSource.encryptData(ds.getId(), oauthToken));
Provisioning provisioning = Provisioning.getInstance();
provisioning.modifyAttrs(ds, attrs);
} else {
ZimbraLog.datasource.info("Could not refresh oauth token status=%d", status);
}
} catch (Exception e) {
ZimbraLog.datasource.warn("Exception while refreshing oauth token", e);
} finally {
if (postMethod != null) {
postMethod.releaseConnection();
}
}
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class DataSourceTask method call.
@Override
public Void call() {
ZimbraLog.clearContext();
ZimbraLog.addMboxToContext(getMailboxId());
ZimbraLog.datasource.debug("Running scheduled import for DataSource %s", getDataSourceId());
Mailbox mbox = null;
try {
// Look up mailbox, account and data source
mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
Account account = mbox.getAccount();
ZimbraLog.addAccountNameToContext(account.getName());
Provisioning prov = Provisioning.getInstance();
DataSource ds = prov.get(account, Key.DataSourceBy.id, getDataSourceId());
if (ds != null) {
ZimbraLog.addDataSourceNameToContext(ds.getName());
if (!ds.isEnabled()) {
ZimbraLog.datasource.info("DataSource is disabled. Cancelling future tasks.");
DataSourceManager.cancelTask(mbox, getDataSourceId());
return null;
}
// Do the work
DataSourceManager.importData(ds);
} else {
ZimbraLog.datasource.info("DataSource %s was deleted. Cancelling future tasks.", getDataSourceId());
DataSourceManager.cancelTask(mbox, getDataSourceId());
}
} catch (ServiceException e) {
ZimbraLog.datasource.warn("Scheduled DataSource import failed.", e);
return null;
}
ZimbraLog.clearContext();
return null;
}
Aggregations