public override void Init() { base.Init(); try { if (!m_initializationOK) { lock (m_loginMutex) { if (!m_initializationOK) { ValisSystem system = new ValisSystem(); AccessToken = system.LogOnUser("s3Rv3rUs3r", "v@l1$D@#M)NP@$$)"); if (AccessToken == null) { throw new VLException("Invalid account credentials"); } Debug.WriteLine(string.Format("ValisHttpApplication:: AccessToken for {0} acquired!", AccessToken.LogOnToken)); m_initializationOK = true; } } } } catch (Exception ex) { Debug.WriteLine(string.Format("ValisHttpApplication:: (An exception occured!): {0}", ex.Message)); throw new HttpException(ex.Message); } }
public static void _initialize(TestContext context) { System.Diagnostics.Debug.WriteLine("AdminBaseClass::_initialize"); //Δημιουργούμε ένα καινούργιο ValisSystem valisSystem = new ValisSystem(); //τώρα κάνουμε login στο σύστημά μας sysadmin = valisSystem.LogOnUser("sysadmin", "tolk!3n"); Assert.IsNotNull(sysadmin); dev = valisSystem.LogOnUser("developer", "tolk!3n"); Assert.IsNotNull(dev); admin = valisSystem.LogOnUser("admin", "tolk!3n"); Assert.IsNotNull(admin); }
protected void loginButton_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(this.username.Text)) { throw new ApplicationException("invalid username!"); } if (string.IsNullOrWhiteSpace(this.password.Text)) { throw new ApplicationException("invalid password!"); } ValisSystem system = new ValisSystem(); var userToken = system.LogOnUser(this.username.Text, this.password.Text); if (userToken == null) { throw new VLException("Invalid Credentials!"); } Globals.UserToken = userToken; FormsAuthentication.SetAuthCookie(this.username.Text, false /* createPersistentCookie */); if (userToken.PrincipalType == PrincipalType.ClientUser) { //a normal user logged in: if (string.IsNullOrWhiteSpace(Request.QueryString["ReturnUrl"])) { Response.Redirect(Globals.HomePage, false); } else { var returnUrl = Request.QueryString["ReturnUrl"]; if (returnUrl.Contains(ValisSystem.Settings.Core.VerifyUrl.Url)) { Response.Redirect(Request.QueryString["ReturnUrl"], false); } else { Response.Redirect(Globals.HomePage, false); } } } else { //a system user logged in: //if (string.IsNullOrWhiteSpace(Request.QueryString["ReturnUrl"])) //{ Response.Redirect(Globals.SystemDefaultPage, false); //} //else //{ // Response.Redirect(Request.QueryString["ReturnUrl"], false); //} } this.Context.ApplicationInstance.CompleteRequest(); } catch (ThreadAbortException) { // } catch (Exception ex) { this.password.Text = string.Empty; this.username.Text = string.Empty; ClientScript.RegisterStartupScript(this.GetType(), "error", string.Format("alert('{0}');", ex.Message), true); } }
public void ConnectivityTest02() { ValisSystem vsystem = new ValisSystem(); Assert.IsNull(vsystem.LogOnUser(null, null)); Assert.IsNull(vsystem.LogOnUser("sysadmin", string.Empty)); Assert.IsNull(vsystem.LogOnUser(string.Empty, "tolk!3n")); Assert.IsNull(vsystem.LogOnUser("qeqeqeqwe", "qweqqe")); //WE CHECK THE builtin sysadmin ACCOUNT: var sysAdmin = vsystem.LogOnUser("sysadmin", "tolk!3n"); Assert.IsNotNull(sysAdmin); Assert.IsTrue(sysAdmin.Principal == 2); Assert.IsTrue(sysAdmin.PrincipalType == PrincipalType.SystemUser); Assert.IsTrue(sysAdmin.IsBuiltIn); Assert.IsTrue(sysAdmin.DefaultLanguage == BuiltinLanguages.Invariant.LanguageId); //ValidateAccessToken var sysAdmin2 = vsystem.ValidateAccessToken(sysAdmin.AccessTokenId); Assert.IsNotNull(sysAdmin2); Assert.AreEqual <VLAccessToken>(sysAdmin, sysAdmin2); vsystem.LogOffUser(sysAdmin); sysAdmin2 = vsystem.ValidateAccessToken(sysAdmin.AccessTokenId); Assert.IsNull(sysAdmin2); //WE CHECK THE builtin developer ACCOUNT: var dev = vsystem.LogOnUser("developer", "tolk!3n"); Assert.IsNotNull(dev); Assert.IsTrue(dev.Principal == 3); Assert.IsTrue(dev.IsBuiltIn); Assert.IsTrue(dev.DefaultLanguage == BuiltinLanguages.Greek.LanguageId); //ValidateAccessToken var dev2 = vsystem.ValidateAccessToken(dev.AccessTokenId); Assert.IsNotNull(dev2); Assert.AreEqual <VLAccessToken>(dev, dev2); vsystem.LogOffUser(dev); dev2 = vsystem.ValidateAccessToken(dev.AccessTokenId); Assert.IsNull(dev2); //WE CHECK the builtin administrator ACCOUNT: var admin = vsystem.LogOnUser("admin", "tolk!3n"); Assert.IsNotNull(admin); Assert.IsTrue(admin.Principal == 4); Assert.IsTrue(admin.IsBuiltIn); Assert.IsTrue(admin.DefaultLanguage == BuiltinLanguages.Greek.LanguageId); //ValidateAccessToken var admin2 = vsystem.ValidateAccessToken(admin.AccessTokenId); Assert.IsNotNull(admin2); Assert.AreEqual <VLAccessToken>(admin, admin2); vsystem.LogOffUser(admin); admin2 = vsystem.ValidateAccessToken(admin.AccessTokenId); Assert.IsNull(admin2); }