Search in sources :

Example 81 with Provisioning

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);
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) Provisioning(com.zimbra.cs.account.Provisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv) DistributionList(com.zimbra.cs.account.DistributionList)

Example 82 with Provisioning

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;
}
Also used : Provisioning(com.zimbra.cs.account.Provisioning)

Example 83 with Provisioning

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);
    }
}
Also used : Provisioning(com.zimbra.cs.account.Provisioning)

Example 84 with Provisioning

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();
        }
    }
}
Also used : JSONObject(org.json.JSONObject) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HttpClient(org.apache.commons.httpclient.HttpClient) JSONObject(org.json.JSONObject) Provisioning(com.zimbra.cs.account.Provisioning) MessagingException(javax.mail.MessagingException) ServiceException(com.zimbra.common.service.ServiceException)

Example 85 with Provisioning

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;
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

Provisioning (com.zimbra.cs.account.Provisioning)532 Account (com.zimbra.cs.account.Account)216 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)158 Element (com.zimbra.common.soap.Element)144 ServiceException (com.zimbra.common.service.ServiceException)96 BeforeClass (org.junit.BeforeClass)93 MockProvisioning (com.zimbra.cs.account.MockProvisioning)89 Server (com.zimbra.cs.account.Server)83 HashMap (java.util.HashMap)76 Domain (com.zimbra.cs.account.Domain)70 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)53 Mailbox (com.zimbra.cs.mailbox.Mailbox)50 Cos (com.zimbra.cs.account.Cos)32 Test (org.junit.Test)30 NamedEntry (com.zimbra.cs.account.NamedEntry)25 AuthToken (com.zimbra.cs.account.AuthToken)23 Group (com.zimbra.cs.account.Group)23 ArrayList (java.util.ArrayList)23 AccountServiceException (com.zimbra.cs.account.AccountServiceException)22 DistributionList (com.zimbra.cs.account.DistributionList)22