public void Configuration(IAppBuilder app) { AuthenticationMode authMode = ((AuthenticationSection)ConfigurationManager.GetSection("system.web/authentication")).Mode; var compilation = (CompilationSection)ConfigurationManager.GetSection("system.web/compilation"); var server = System.Environment.MachineName; if (authMode.ToString() == "Forms") { ConfigureAuth(app); } }
private void InitializeUserIdentity(string username) { string authenticationType; AuthenticationMode authenticationMode = ((AuthenticationSection)WebConfigurationManager.GetSection("system.web/authentication")).Mode; switch (authenticationMode) { case AuthenticationMode.Forms: authenticationType = authenticationMode.ToString(); break; default: throw new UnsupportedAuthenticationType(); } identity = new GenericIdentity(username, authenticationType); }
internal void AuthenticateUser(Uri successRedirect, AuthenticationMode authMode = AuthenticationMode.Authorize, TokenValidationPolicy tokenValidationPolicy = TokenValidationPolicy.EveryLogin, AuthValidationMode authValidationMode = AuthValidationMode.Graceful, string email = null, string appSecret = null) { if (AuthenticationMode.Identify.Equals(authMode) && String.IsNullOrEmpty(appSecret)) { throw new ApplicationException(LocalizedStrings.LocalizedResources.Authentication_AppSecretMissing); } this.SuccessRedirect = successRedirect; bool needsLogin = TokenValidationPolicy.EveryLogin.Equals(tokenValidationPolicy); if (!needsLogin && TokenValidationPolicy.OnNewVersion.Equals(tokenValidationPolicy)) { string lastAuthorizedVersion = IsolatedStorageSettings.ApplicationSettings.GetValue(Constants.AuthLastAuthorizedVersionKey) as String; needsLogin = (lastAuthorizedVersion == null) || (new Version(lastAuthorizedVersion) < new Version(ManifestHelper.GetAppVersion())); } if (needsLogin) { ((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(new Uri("/HockeyApp;component/Views/LoginPage.xaml?authmode=" + HttpUtility.UrlEncode(authMode.ToString()) + "&appsecret=" + HttpUtility.UrlEncode(appSecret) + "&email=" + HttpUtility.UrlEncode(email ?? "") + "&validationmode=" + HttpUtility.UrlEncode(authValidationMode.ToString() ?? ""), UriKind.Relative)); } else { ((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(successRedirect); } }
public static void Save(ConfigurationSaveMode saveMode) { CategoryPropertyItem rootItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(RemoteDesktopConfiguration.Settings.CategoryPropertyItems, CONFIG_ROOT); if (rootItem == null) { rootItem = new CategoryPropertyItem(); rootItem.Id = CONFIG_ROOT; RemoteDesktopConfiguration.Settings.CategoryPropertyItems.Add(rootItem); } CategoryPropertyItem piAuthMode = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_AUTHENTICATION_MODE); if (piAuthMode == null) { piAuthMode = new CategoryPropertyItem(); piAuthMode.Id = CONFIG_AUTHENTICATION_MODE; rootItem.PropertyItems.Add(piAuthMode); } piAuthMode.EntryValue = AuthenticationMode.ToString(); CategoryPropertyItem piModuleStore = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_AUTHENTICATION_MODULE_STORE); if (piModuleStore == null) { piModuleStore = new CategoryPropertyItem(); piModuleStore.Id = CONFIG_AUTHENTICATION_MODULE_STORE; rootItem.PropertyItems.Add(piModuleStore); } piModuleStore.EntryValue = AuthenticationModuleStore; CategoryPropertyItem piPropagation = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_PROPAGATE_ON_NETWORK); if (piPropagation == null) { piPropagation = new CategoryPropertyItem(); piPropagation.Id = CONFIG_PROPAGATE_ON_NETWORK; rootItem.PropertyItems.Add(piPropagation); } piPropagation.EntryValue = PropagateServiceOnTheNetwork.ToString(); CategoryPropertyItem piDesktopShareMode = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_DESKTOP_SHARE_MODE); if (piDesktopShareMode == null) { piDesktopShareMode = new CategoryPropertyItem(); piDesktopShareMode.Id = CONFIG_DESKTOP_SHARE_MODE; rootItem.PropertyItems.Add(piDesktopShareMode); } piDesktopShareMode.EntryValue = DesktopShareMode.ToString(); CategoryPropertyItem piAcceptInputEvents = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_ACCEPT_INPUTS_FROM_CLIENTS); if (piAcceptInputEvents == null) { piAcceptInputEvents = new CategoryPropertyItem(); piAcceptInputEvents.Id = CONFIG_ACCEPT_INPUTS_FROM_CLIENTS; rootItem.PropertyItems.Add(piAcceptInputEvents); } piAcceptInputEvents.EntryValue = AcceptKeyboardAndMouseInputFromClients.ToString(); CategoryPropertyItem piDesktopImageClipWidth = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_DESKTOP_IMAGE_CLIP_WIDTH); if (piDesktopImageClipWidth == null) { piDesktopImageClipWidth = new CategoryPropertyItem(); piDesktopImageClipWidth.Id = CONFIG_DESKTOP_IMAGE_CLIP_WIDTH; rootItem.PropertyItems.Add(piDesktopImageClipWidth); } piDesktopImageClipWidth.EntryValue = DesktopImageClipWidth.ToString(); CategoryPropertyItem piDesktopImageClipHeight = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_DESKTOP_IMAGE_CLIP_HEIGHT); if (piDesktopImageClipHeight == null) { piDesktopImageClipHeight = new CategoryPropertyItem(); piDesktopImageClipHeight.Id = CONFIG_DESKTOP_IMAGE_CLIP_HEIGHT; rootItem.PropertyItems.Add(piDesktopImageClipHeight); } piDesktopImageClipHeight.EntryValue = DesktopImageClipHeight.ToString(); CategoryPropertyItem piClientsPerServiceThreads = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_CLIENTS_PER_SERVICE_THREADS); if (piClientsPerServiceThreads == null) { piClientsPerServiceThreads = new CategoryPropertyItem(); piClientsPerServiceThreads.Id = CONFIG_CLIENTS_PER_SERVICE_THREADS; rootItem.PropertyItems.Add(piClientsPerServiceThreads); } piClientsPerServiceThreads.EntryValue = ClientsPerServiceThreads.ToString(); CategoryPropertyItem piMaximumFailedLoginAttempt = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_MAXIMUM_FAILED_LOGIN_ATTEMPT); if (piMaximumFailedLoginAttempt == null) { piMaximumFailedLoginAttempt = new CategoryPropertyItem(); piMaximumFailedLoginAttempt.Id = CONFIG_MAXIMUM_FAILED_LOGIN_ATTEMPT; rootItem.PropertyItems.Add(piMaximumFailedLoginAttempt); } piMaximumFailedLoginAttempt.EntryValue = MaximumFailedLoginAttempt.ToString(); CategoryPropertyItem piBlackListTimeout = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_BLACKLIST_TIMEOUT); if (piBlackListTimeout == null) { piBlackListTimeout = new CategoryPropertyItem(); piBlackListTimeout.Id = CONFIG_BLACKLIST_TIMEOUT; rootItem.PropertyItems.Add(piBlackListTimeout); } piBlackListTimeout.EntryValue = BlackListTimeout.ToString(); CategoryPropertyItem piImageClipQuality = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_IMAGE_CLIP_QUALITY); if (piImageClipQuality == null) { piImageClipQuality = new CategoryPropertyItem(); piImageClipQuality.Id = CONFIG_IMAGE_CLIP_QUALITY; rootItem.PropertyItems.Add(piImageClipQuality); } piImageClipQuality.EntryValue = DefaultImageClipQuality.ToString(); CategoryPropertyItem piMouseMoveSendingInterval = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_MOUSE_MOVE_SEND_INTERVAL); if (piMouseMoveSendingInterval == null) { piMouseMoveSendingInterval = new CategoryPropertyItem(); piMouseMoveSendingInterval.Id = CONFIG_MOUSE_MOVE_SEND_INTERVAL; rootItem.PropertyItems.Add(piMouseMoveSendingInterval); } piMouseMoveSendingInterval.EntryValue = MouseMoveSendInterval.ToString(); RemoteDesktopConfiguration.Save(saveMode); }
public void MSAUTHWS_S04_TC01_VerifyLoginUnderPassportAuthentication() { Site.Assume.IsTrue(Common.IsRequirementEnabled(132, this.Site), "This case runs only when the requirement 132 is enabled."); // Invoke Mode operation. AuthenticationMode authMode = this.authwsAdapter.Mode(); bool isVerifyPassportMode = AuthenticationMode.Passport == authMode; Site.Assume.IsTrue(isVerifyPassportMode, string.Format("The expected result of Mode is Passport, the actual result is{0}", authMode.ToString())); // Invoke Login operation. LoginResult loginResult = this.authwsAdapter.Login(this.validUserName, this.validPassword); Site.Assert.IsNotNull(loginResult, "Login result is not null"); Site.Assert.IsNull(loginResult.CookieName, "The cookie name is null"); }
/// <summary> /// Attempts to authenticate the stream /// </summary> /// <param name="stream">the base stream to authenticate</param> /// <param name="useSsl">gets if ssl should be used</param> /// <param name="secureStream">the secure stream that is valid if the function returns true.</param> /// <param name="token">the user's token assocated with what user created the stream</param> /// <returns>true if successful, false otherwise</returns> public bool TryAuthenticateAsServer(Stream stream, bool useSsl, out Stream secureStream, out T token) { token = default(T); secureStream = null; SslStream ssl = null; try { Stream stream2; byte[] certSignatures; if (useSsl) { if (!TryConnectSsl(stream, out ssl)) { return(false); } stream2 = ssl; certSignatures = SecureStream.ComputeCertificateChallenge(true, ssl); } else { certSignatures = new byte[0]; stream2 = stream; } TryAgain: State state = m_state; AuthenticationMode authenticationMode = (AuthenticationMode)stream2.ReadNextByte(); Guid userToken; switch (authenticationMode) { case AuthenticationMode.None: if (!state.ContainsDefaultCredentials) { stream2.Write(false); if (ssl != null) { ssl.Dispose(); } return(false); } stream2.Write(true); userToken = state.DefaultUserToken; break; //case AuthenticationMode.Srp: //SRP // m_srp.AuthenticateAsServer(ssl, certSignatures); // break; case AuthenticationMode.Integrated: //Integrated if (!m_integrated.TryAuthenticateAsServer(stream2, out userToken, certSignatures)) { if (ssl != null) { ssl.Dispose(); } return(false); } break; //case AuthenticationMode.Scram: //Scram // m_scram.AuthenticateAsServer(ssl, certSignatures); // break; //case AuthenticationMode.Certificate: //Certificate // m_cert.AuthenticateAsServer(ssl); // break; case AuthenticationMode.ResumeSession: if (TryResumeSession(stream2, certSignatures, out userToken)) { lock (m_syncRoot) { m_userTokens.TryGetValue(userToken, out token); } secureStream = stream2; return(true); } goto TryAgain; default: Log.Publish(MessageLevel.Info, "Invalid Authentication Method", authenticationMode.ToString()); return(false); } stream2.Write(false); stream2.Flush(); //ToDo: Support resume tickets //byte[] ticket; //byte[] secret; //CreateResumeTicket(userToken, out ticket, out secret); //stream2.WriteByte((byte)ticket.Length); //stream2.Write(ticket); //stream2.WriteByte((byte)secret.Length); //stream2.Write(secret); //stream2.Flush(); lock (m_syncRoot) { m_userTokens.TryGetValue(userToken, out token); } secureStream = stream2; return(true); } catch (Exception ex) { Log.Publish(MessageLevel.Info, "Authentication Failed: Unknown Exception", null, null, ex); if (ssl != null) { ssl.Dispose(); } return(false); } }
public InvalidAuthenticationModeException(AuthenticationMode authenticationMode) : base(authenticationMode.ToString()) { }