protected override void ProcessRecord() { try { int ishPasswordLength = _ishPassword == null ? 0 : _ishPassword.Length; if (PSCredential != null) { _ishUserName = PSCredential.UserName; _ishSecurePassword = PSCredential.Password; } else if (!String.IsNullOrWhiteSpace(_ishPassword)) { _ishSecurePassword = SecureStringConversions.StringToSecureString(_ishPassword); } else { _ishSecurePassword = null; } WriteVerbose($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + "]"); WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + $"] Timeout[{_timeout}] TimeoutIssue[{_timeoutIssue}] TimeoutService[{_timeoutService}] IgnoreSslPolicyErrors[{_ignoreSslPolicyErrors}]"); IshSession ishSession = null; /* If the PSCmdlet is not accepted switch the condition to * if (!String.IsNullOrWhiteSpace(WsTrustIssuerMexUrl) && !String.IsNullOrWhiteSpace(WsTrustIssuerMexUrl)) */ if (this.ParameterSetName.EndsWith("-ExplicitIssuer")) { WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] WsTrustIssuerUrl[{WsTrustIssuerUrl}] WsTrustIssuerMexUrl[{WsTrustIssuerMexUrl}]"); ishSession = new IshSession(Logger, WsBaseUrl, WsTrustIssuerUrl, WsTrustIssuerMexUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors); } else { ishSession = new IshSession(Logger, WsBaseUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors); } // Keep the IshSession initialization as minimal as possible // Do early load of IshTypeFieldSetup (either <13-TriDKXmlSetup-based or >=13-RetrieveFieldSetupByIshType-API-based) for // usage by ToIshMetadataFields/.../ToIshRequestedMetadataFields and Expand-ISHParameter.ps1 parameter autocompletion //var ishTypeFieldSetup = ishSession.IshTypeFieldSetup; WriteObject(true); } catch (TrisoftAutomationException trisoftAutomationException) { WriteVerbose(trisoftAutomationException.Message); WriteObject(false); } catch (AggregateException aggregateException) { var flattenedAggregateException = aggregateException.Flatten(); WriteVerbose(flattenedAggregateException.ToString()); WriteObject(false); } catch (Exception exception) { WriteVerbose(exception.Message); WriteObject(false); } }
protected override void ProcessRecord() { try { int ishPasswordLength = _ishPassword == null ? 0 : _ishPassword.Length; if (PSCredential != null) { _ishUserName = PSCredential.UserName; _ishSecurePassword = PSCredential.Password; } else if (!String.IsNullOrWhiteSpace(_ishPassword)) { _ishSecurePassword = SecureStringConversions.StringToSecureString(_ishPassword); } else { _ishSecurePassword = null; } WriteVerbose($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + "]"); WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + $"] Timeout[{_timeout}] TimeoutIssue[{_timeoutIssue}] TimeoutService[{_timeoutService}] IgnoreSslPolicyErrors[{_ignoreSslPolicyErrors}]"); IshSession ishSession = null; if (this.ParameterSetName.EndsWith("-ExplicitIssuer")) { WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] WsTrustIssuerUrl[{WsTrustIssuerUrl}] WsTrustIssuerMexUrl[{WsTrustIssuerMexUrl}]"); ishSession = new IshSession(Logger, WsBaseUrl, WsTrustIssuerUrl, WsTrustIssuerMexUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors); } else { ishSession = new IshSession(Logger, WsBaseUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors); } // Do early load of IshTypeFieldSetup (either <13-TriDKXmlSetup-based or >=13-RetrieveFieldSetupByIshType-API-based) for // usage by ToIshMetadataFields/.../ToIshRequestedMetadataFields and Expand-ISHParameter.ps1 parameter autocompletion var ishTypeFieldSetup = ishSession.IshTypeFieldSetup; WriteObject(ishSession); } catch (NotSupportedException notSupportedException) { WriteError(new ErrorRecord(notSupportedException, "-1", ErrorCategory.InvalidOperation, null)); } catch (TrisoftAutomationException trisoftAutomationException) { ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null)); } catch (AggregateException aggregateException) { var flattenedAggregateException = aggregateException.Flatten(); WriteVerbose(flattenedAggregateException.ToString()); ThrowTerminatingError(new ErrorRecord(flattenedAggregateException, base.GetType().Name, ErrorCategory.NotSpecified, null)); } catch (Exception exception) { ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null)); } }
private void CreateConnection() { //prepare connection for authentication/authorization var connectionParameters = new InfoShareWcfConnectionParameters { Credential = _ishSecurePassword == null ? null : new NetworkCredential(_ishUserName, SecureStringConversions.SecureStringToString(_ishSecurePassword)), Timeout = _timeout, IssueTimeout = _timeoutIssue, ServiceTimeout = _timeoutService }; if (_explicitIssuer) { _connection = new InfoShareWcfConnection(_logger, _webServicesBaseUri, _wsTrustIssuerUri, _wsTrustIssuerMexUri, connectionParameters); } else { _connection = new InfoShareWcfConnection(_logger, _webServicesBaseUri, connectionParameters); } // application proxy to get server version or authentication context init is a must as it also confirms credentials, can take up to 1s _logger.WriteDebug("CreateConnection _serverVersion GetApplication25Channel"); var application25Proxy = _connection.GetApplication25Channel(); _logger.WriteDebug("CreateConnection _serverVersion GetApplication25Channel.GetVersion"); _serverVersion = new IshVersion(application25Proxy.GetVersion()); }
protected override void ProcessRecord() { try { if ((this.ParameterSetName.StartsWith("UserNamePassword")) && string.IsNullOrEmpty(_ishUserName)) { // We came in with an empty username but with -IshUserName/-IshPassword; // so fallback to NetworkCredential/ActiveDirectory WriteWarning("Empty -IshUserName so fall back to NetworkCredential/ActiveDirectory, ignoring -IshPassword."); _ishUserName = null; _ishPassword = null; } int ishPasswordLength = _ishPassword == null ? 0 : _ishPassword.Length; if (PSCredential != null) { _ishUserName = PSCredential.UserName; _ishSecurePassword = PSCredential.Password; } else if (!String.IsNullOrWhiteSpace(_ishPassword)) { _ishSecurePassword = SecureStringConversions.StringToSecureString(_ishPassword); } else { _ishSecurePassword = null; } WriteVerbose($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + "]"); WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + $"] Timeout[{_timeout}] TimeoutIssue[{_timeoutIssue}] TimeoutService[{_timeoutService}] IgnoreSslPolicyErrors[{_ignoreSslPolicyErrors}]"); IshSession ishSession = null; if (this.ParameterSetName.EndsWith("-ExplicitIssuer")) { WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] WsTrustIssuerUrl[{WsTrustIssuerUrl}] WsTrustIssuerMexUrl[{WsTrustIssuerMexUrl}]"); ishSession = new IshSession(Logger, WsBaseUrl, WsTrustIssuerUrl, WsTrustIssuerMexUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors); } else { ishSession = new IshSession(Logger, WsBaseUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors); } // Do early load of IshTypeFieldSetup (either <13-TriDKXmlSetup-based or >=13-RetrieveFieldSetupByIshType-API-based) for // usage by ToIshMetadataFields/.../ToIshRequestedMetadataFields and Expand-ISHParameter.ps1 parameter autocompletion var ishTypeFieldSetup = ishSession.IshTypeFieldSetup; // Submit the PSVariable so you don't have to specify '-IshSession $ishSession' all the time, can be retrieved in every cmdlet, preferably in BeginProcessing() WriteVerbose($"Storing IshSession[{ishSession.Name}] under SessionState.{ISHRemoteSessionStateIshSession}"); this.SessionState.PSVariable.Set(ISHRemoteSessionStateIshSession, ishSession); WriteObject(ishSession); } catch (NotSupportedException notSupportedException) { WriteError(new ErrorRecord(notSupportedException, "-1", ErrorCategory.InvalidOperation, null)); } catch (TrisoftAutomationException trisoftAutomationException) { ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null)); } catch (AggregateException aggregateException) { var flattenedAggregateException = aggregateException.Flatten(); WriteWarning(flattenedAggregateException.ToString()); ThrowTerminatingError(new ErrorRecord(flattenedAggregateException, base.GetType().Name, ErrorCategory.NotSpecified, null)); } catch (Exception exception) { if (exception.InnerException != null) { WriteWarning(exception.InnerException.ToString()); } ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null)); } }