Search in sources :

Example 1 with SecurityData

use of org.talend.ms.crm.sdk.SecurityData in project tdi-studio-se by Talend.

the class MSCRMClient method doGetOnlineConnection.

/**
     * URL for the Discovery Service For North America Microsoft account, discovery service url is
     * https://dev.crm.dynamics.com/XRMServices/2011/Discovery.svc Microsoft office 365, discovery service url is
     * https://disco.crm.dynamics.com/XRMServices/2011/Discovery.svc To use appropriate discovery service url for other
     * environments refer http://technet.microsoft.com/en-us/library/gg309401.aspx
     * 
     * @throws Exception
     */
public OrganizationServiceStub doGetOnlineConnection(String discoveryServiceURL) throws Exception {
    try {
        // Retrieve the authentication policy for the discovery service.
        OnlineAuthenticationPolicy discoveryPolicy = new OnlineAuthenticationPolicy(discoveryServiceURL + FlatWSDLSuffix);
        WsdlTokenManager discoeryTokenManager = new WsdlTokenManager();
        // Authenticate the user using the discovery authentication policy.
        SecurityData discoverySecurityData = discoeryTokenManager.authenticate(discoveryServiceURL, username, password, discoveryPolicy.getAppliesTo(), discoveryPolicy.getPolicy(), discoveryPolicy.getIssuerUri());
        // Retrieve discovery stub using organization URL with the security data.
        DiscoveryServiceStub discoveryServiceStub = createDiscoveryServiceStub(discoveryServiceURL, discoverySecurityData);
        // Retrieve organization service url using discovery stub.
        String orgUrl = discoverOrganizationUrl(discoveryServiceStub, orgName);
        // The discovery service stub cannot be reused against the organization service
        // as the Issuer and AppliesTo may differ between the discovery and organization services.
        // Retrieve the authentication policy for the organization service.
        OnlineAuthenticationPolicy organizationPolicy = new OnlineAuthenticationPolicy(orgUrl + FlatWSDLSuffix);
        WsdlTokenManager orgTokenManager = new WsdlTokenManager();
        // Authenticate the user using the organization authentication policy.
        SecurityData securityData = orgTokenManager.authenticate(orgUrl, username, password, organizationPolicy.getAppliesTo(), organizationPolicy.getPolicy(), organizationPolicy.getIssuerUri());
        // Retrieve organization stub using organization URL with the security data.
        serviceStub = createOrganizationServiceStub(orgUrl, securityData);
        Options options = serviceStub._getServiceClient().getOptions();
        if (reuseHttpClient != null) {
            options.setProperty(org.apache.axis2.transport.http.HTTPConstants.REUSE_HTTP_CLIENT, reuseHttpClient);
        }
        if (timeout != null) {
            options.setTimeOutInMilliSeconds(Long.valueOf(timeout));
            options.setProperty(org.apache.axis2.transport.http.HTTPConstants.SO_TIMEOUT, timeout);
            options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CONNECTION_TIMEOUT, timeout);
        }
    } catch (IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage e) {
        throw new Exception(e.getFaultMessage().getDiscoveryServiceFault().getMessage());
    }
    return serviceStub;
}
Also used : DiscoveryServiceStub(com.microsoft.schemas.xrm._2011.contracts.DiscoveryServiceStub) Options(org.apache.axis2.client.Options) OnlineAuthenticationPolicy(org.talend.ms.crm.sdk.OnlineAuthenticationPolicy) SecurityData(org.talend.ms.crm.sdk.SecurityData) IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage(com.microsoft.schemas.xrm._2011.contracts.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage) WsdlTokenManager(org.talend.ms.crm.sdk.WsdlTokenManager) XMLStreamException(javax.xml.stream.XMLStreamException) RemoteException(java.rmi.RemoteException)

Aggregations

DiscoveryServiceStub (com.microsoft.schemas.xrm._2011.contracts.DiscoveryServiceStub)1 IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage (com.microsoft.schemas.xrm._2011.contracts.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage)1 RemoteException (java.rmi.RemoteException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Options (org.apache.axis2.client.Options)1 OnlineAuthenticationPolicy (org.talend.ms.crm.sdk.OnlineAuthenticationPolicy)1 SecurityData (org.talend.ms.crm.sdk.SecurityData)1 WsdlTokenManager (org.talend.ms.crm.sdk.WsdlTokenManager)1