/// <summary> /// Notifies the login window that SSO has been completed. /// </summary> /// <param name="authenticationResult">The current state of the authentication process. <see cref="RallyRestApi.AuthenticationResult"/></param> /// <param name="api">The API that was authenticated against.</param> protected override void NotifyLoginWindowSsoComplete( RallyRestApi.AuthenticationResult authenticationResult, RallyRestApi api) { if (LoginWindowSsoAuthenticationComplete != null) { LoginWindowSsoAuthenticationComplete.Invoke(authenticationResult, api); } }
internal void SsoAuthenticationComplete(RallyRestApi.AuthenticationResult authenticationResult, RallyRestApi api) { if (authenticationResult == RallyRestApi.AuthenticationResult.Authenticated) { Close(); } else { UpdateLoginState(); } }
public static RallyRestApi GetRallyRestApiWithApiKey(string apiKey = "", string server = RallyRestApi.DEFAULT_SERVER, string wsapiVersion = "") { if (String.IsNullOrWhiteSpace(apiKey)) { apiKey = Settings.Default.ApiKey; } RallyRestApi api = new RallyRestApi(webServiceVersion: wsapiVersion); RallyRestApi.AuthenticationResult authResult = api.AuthenticateWithApiKey(apiKey, server); Assert.AreEqual(RallyRestApi.AuthenticationResult.Authenticated, authResult); return(api); }
// HELP: This method handles the passthrough from the delegates. // This is where you would need to update your application to show the logged in state. #region UpdateAuthenticationResults private void UpdateAuthenticationResults(RallyRestApi.AuthenticationResult authenticationResult, RallyRestApi api) { authResultLabel.Content = authenticationResult.ToString(); if (api != null) { authTypeLabel.Content = api.ConnectionInfo.AuthType.ToString(); zSessionIDLabel.Content = api.ConnectionInfo.ZSessionID; } else { authTypeLabel.Content = "None"; zSessionIDLabel.Content = String.Empty; } }
/// <summary> /// Auto authenticates the user if there are saved credentials. /// </summary> /// <param name="allowSsoForautoAuthenticate">Is SSO authentication allowed for auto-authentication? /// This may open a web browser UI.</param> /// <returns>The current state of the authentication process. <see cref="RallyRestApi.AuthenticationResult"/></returns> /// <example> /// <code language="C#"> /// RallyRestApi.AuthenticationResult result = authMgr.AutoAuthenticate(false); /// </code> /// </example> public RallyRestApi.AuthenticationResult AutoAuthenticate(bool allowSsoForautoAuthenticate) { if (!IsUiSupported) { throw new NotImplementedException("Auto-Authentication is only supported for UI based authentication mangers."); } RallyRestApi.AuthenticationResult authenticationResult = Api.AuthenticationState; if (authenticationResult != RallyRestApi.AuthenticationResult.Authenticated) { string errorMessage; authenticationResult = PerformAuthenticationCheck(out errorMessage, allowSsoForautoAuthenticate); } return(authenticationResult); }
// HELP: This delegate notifies us that authentication has completed. #region AuthenticationStateChange private void AuthenticationComplete(RallyRestApi.AuthenticationResult authenticationResult, RallyRestApi api) { UpdateAuthenticationResults(authenticationResult, api); //DynamicJsonObject toCreate = new DynamicJsonObject(); //toCreate["Name"] = "Daniel"; //toCreate["Owner"] = 49900394378; //if (api == null) //{ // api = new RallyRestApi(wpfAuthMgr); //} //var result = api.Create("task", toCreate); }
/// <summary> /// Reports the results of an SSO action. /// </summary> /// <param name="success">Was SSO authentication completed successfully?</param> /// <param name="rallyServer">The server that the ZSessionID is for.</param> /// <param name="zSessionID">The zSessionID that was returned from Rally.</param> protected void ReportSsoResults(bool success, string rallyServer, string zSessionID) { if (SsoAuthenticationComplete != null) { if (success) { RallyRestApi.AuthenticationResult authResult = Api.AuthenticateWithZSessionID(Api.ConnectionInfo.UserName, zSessionID, rallyServer: rallyServer); if (authResult == RallyRestApi.AuthenticationResult.Authenticated) { LoginDetails.SaveToDisk(); NotifyLoginWindowSsoComplete(authResult, Api); SsoAuthenticationComplete.Invoke(authResult, Api); return; } } LoginDetails.MarkUserAsLoggedOut(); Api.Logout(); NotifyLoginWindowSsoComplete(RallyRestApi.AuthenticationResult.NotAuthorized, null); SsoAuthenticationComplete.Invoke(RallyRestApi.AuthenticationResult.NotAuthorized, null); } }
/// <summary> /// Performs an authentication check against Rally with the specified credentials /// </summary> private RallyRestApi.AuthenticationResult PerformAuthenticationCheckAgainstRally(out string errorMessage, bool allowSso) { if (!IsUiSupported) { throw new InvalidProgramException("This method is only supported by UI enabled Authentication Managers."); } RallyRestApi.AuthenticationResult authResult = RallyRestApi.AuthenticationResult.NotAuthorized; errorMessage = String.Empty; WebProxy proxy = GetProxy(out errorMessage); if (!String.IsNullOrWhiteSpace(errorMessage)) { return(RallyRestApi.AuthenticationResult.NotAuthorized); } if (String.IsNullOrWhiteSpace(LoginDetails.RallyServer)) { errorMessage = LoginFailureServerEmpty; } else if (String.IsNullOrWhiteSpace(LoginDetails.Username)) { errorMessage = LoginFailureLoginEmpty; } Uri serverUri = null; try { if (String.IsNullOrWhiteSpace(LoginDetails.RallyServer)) { errorMessage = "Bad URI format for Rally Server"; } else { serverUri = new Uri(LoginDetails.RallyServer); } } catch { errorMessage = "Bad URI format for Rally Server"; } try { if (String.IsNullOrWhiteSpace(errorMessage)) { authResult = Api.Authenticate(LoginDetails.Username, LoginDetails.GetPassword(), serverUri, proxy, allowSSO: allowSso); } } catch (RallyUnavailableException) { errorMessage = "Rally is currently unavailable."; } catch (WebException e) { if (e.Response is HttpWebResponse) { if ((((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.BadGateway) || (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.BadRequest)) { errorMessage = LoginFailureBadServer; } else if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.ProxyAuthenticationRequired) { errorMessage = LoginFailureProxyCredentials; } else if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.Unauthorized) { errorMessage = LoginFailureCredentials; } else { errorMessage = LoginFailureUnknown; } } else if ((e is WebException) && (((WebException)e).Status == WebExceptionStatus.ConnectFailure)) { errorMessage = LoginFailureBadConnection; } else { errorMessage = LoginFailureUnknown; } } UpdateAuthenticationState(); return(Api.AuthenticationState); }
/// <summary> /// Notifies the login window that SSO has been completed. /// </summary> /// <param name="authenticationResult">The current state of the authentication process. <see cref="RallyRestApi.AuthenticationResult"/></param> /// <param name="api">The API that was authenticated against.</param> protected abstract void NotifyLoginWindowSsoComplete( RallyRestApi.AuthenticationResult authenticationResult, RallyRestApi api);
// HELP: This delegate notifies us that SSO authentication has completed. #region SsoAuthenticationComplete private void SsoAuthenticationComplete(RallyRestApi.AuthenticationResult authenticationResult, RallyRestApi api) { UpdateAuthenticationResults(authenticationResult, api); }
/// <summary> /// Notifies the login window that SSO has been completed. /// </summary> /// <param name="authenticationResult">The current state of the authentication process. <see cref="RallyRestApi.AuthenticationResult"/></param> /// <param name="api">The API that was authenticated against.</param> /// <exception cref="NotImplementedException">This method is not supported for this authentication manager.</exception> protected override void NotifyLoginWindowSsoComplete( RallyRestApi.AuthenticationResult authenticationResult, RallyRestApi api) { throw new NotImplementedException("This authorization manager does not support UI elements."); }