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