public TestAuthComm(string url) { Startup(); Thread.Sleep(1000); Console.Write("\n\n"); DependencyInjection di = DependencyInjection.GetInstance(); di.SetConfig("config.xml"); Console.WriteLine("Demo AuthComm"); Console.WriteLine("-----------------------------"); result = new List<string>(); authR = new AuthResult(); m_MsgList = new List<Message>(); // Logger.LogWrite(EskimoDBLogLevel.Verbose, "Creating"); try { channel1 = (IAuthServer)di.CreateObject("authserv", new object[]{ null,new BasicHttpBinding(),url}); channel2 = (IAuthValidate)di.CreateObject("authvalid", new object[]{ null,new BasicHttpBinding(),url}); Console.WriteLine("Connecting to the server!"); } catch (Exception ex) { Console.WriteLine(ex); Console.WriteLine("Fail to connect the server!"); } }
public AuthResult Authenticate(string userName, string pwd, out string token) { AuthResult authret = new AuthResult(); //string msg = ""; authret.valid = m_Mgr.LogIn(userName, pwd, out token, out authret.msg); return authret; }
public AuthResult CreateUser(string newUser, string newUserPwd, string token) { AuthResult authret = new AuthResult(); //string msg = ""; authret.valid = m_Mgr.Register(newUser, newUserPwd, out authret.msg); return authret; }
public ReturnRequest(AuthResult m_RetAuthResult, string m_RetToken, DateTime m_RetExpTime, bool m_RetRequestResult, string m_RetSignature) { m_AuthResult = m_RetAuthResult; m_Token = m_RetToken; m_ExpTime = m_RetExpTime; m_RequestResult = m_RetRequestResult; m_Signature = m_RetSignature; }
public AuthResult mockCreateNewUser(string newUser, string newUserPwd, string token) { AuthResult authresult = new AuthResult(); authresult.valid = true; authresult.msg = "Successfully created users!"; return authresult; }
private bool test1() { Message test1 = new Message(); test1.TestID = 1; test1.Passed = false; Console.WriteLine("Demo WCF Using Authenticate!"); try { authR = channel1.Authenticate("team1", "clientapi", out token); } catch (Exception ex) { Console.WriteLine(ex); } if (authR.valid) test1.Msg = "The Authenticate is passed!"; else test1.Msg = "The Authenticate is failed!"; Console.WriteLine(test1.Msg); test1.Passed = authR.valid; m_MsgList.Add(test1); return test1.Passed; }
/// <summary> /// Change the privilege of a user /// </summary> /// <param name="userName">user Name</param> /// <param name="administrator">is an administrator or not</param> /// <param name="token"> the token of current user</param> /// <returns>the result of changing the privilege</returns> public AuthResult ChangeUserPrivilege(string userName, bool administrator, string token) { Console.Write("\n"); Console.WriteLine("Try to change the privilege of " +userName + " ..."); Console.Write("\n"); AuthResult ret = new AuthResult(); // judge whether the token is a administrator or not if (AuthMgr.IsAdmin(AuthMgr.RetrieveUserName(token))) ret.valid = AuthMgr.ChangeUserPrivilege(userName, administrator, out ret.msg); else { ret.valid = false; ret.msg = "Token is not valid"; } Console.Write("\n"); Console.WriteLine(ret.msg + "\n"); return ret; }
/// <summary> /// authenticate whether the user is exsited /// </summary> /// <param name="userName">user name</param> /// <param name="pwd">user's password</param> /// <param name="token">if the user exsited, return a token</param> /// <returns>the result of Authentication</returns> public AuthResult Authenticate(string userName, string pwd, out string token) { Console.Write("\n"); Console.WriteLine("Authenticate the userName and password..."); Console.Write("\n"); AuthResult ret = new AuthResult(); string temp = null; // call the method in AuthMgr to authenticate the account ret.valid =AuthMgr.LogIn(userName, pwd, out token, out temp); ret.msg = temp; return ret; }
/// <summary> /// Create a new user, the input token should indicate an adminstrator /// </summary> /// <param name="newUser">new user name</param> /// <param name="newUserPwd">new password</param> /// <param name="token">the adminstrator's token</param> /// <returns>the result of createUser</returns> public AuthResult CreateUser(string newUser, string newUserPwd, string token) { Console.Write("\n"); Console.WriteLine("Create a new user..."); Console.Write("\n"); string tempMsg = null; AuthResult ret = new AuthResult(); string tempUser = AuthMgr.RetrieveUserName(token); if (tempUser == null) { ret.msg = "Token expired or not existed!"; ret.valid = false; Console.WriteLine(ret.msg); return ret; } // judge whether the current user is an adminstrator or not if (AuthMgr.IsAdmin(tempUser)) { // call AuthMgr's function "Register" to create a new account ret.valid = AuthMgr.Register(newUser, newUserPwd, out tempMsg); ret.msg = tempMsg; Console.WriteLine(ret.msg); return ret; } else { ret.msg = "Only the adminstrator can create a new user!"; ret.valid = false; Console.WriteLine(ret.msg); return ret; } }
public AuthResult mockChangePassword(string newUser, string newUserPwd, string token) { AuthResult authresult = new AuthResult(); authresult.valid = true; authresult.msg = "Successfully Change Password!"; return authresult; }
private bool test10() { Message test10 = new Message(); test10.TestID = 10; test10.Passed = false; Console.WriteLine("Demo WCF using Create user"); try { authR = channel1.CreateUser("User7", "_12456774", token); } catch (Exception ex) { Console.WriteLine(ex); } if (authR.valid) test10.Msg = "Create User7 Case has been passed!"; else test10.Msg = "Create User7 Case has been failed!"; Console.WriteLine(test10.Msg); test10.Passed = authR.valid; m_MsgList.Add(test10); return test10.Passed; }
// Not finished, needs to be done public AuthResult ChangePassword(string userName, string pwd, string token) { AuthResult authret = new AuthResult(); return authret; }
private bool test8() { Message test8 = new Message(); test8.TestID = 8; test8.Passed = false; Console.WriteLine("Demo WCF using Create user"); try { authR = channel1.CreateUser("User5", "completely", invalidToken); } catch (Exception ex) { Console.WriteLine(ex); } if (!authR.valid) test8.Msg = "Create User5 Case has been passed!"; else test8.Msg = "Create User5 Case has been failed!"; Console.WriteLine(test8.Msg); if (authR.valid == false) test8.Passed = true; m_MsgList.Add(test8); return test8.Passed; }
private bool test16() { Console.WriteLine("Demo Change password"); Message test16 = new Message(); test16.TestID = 16; test16.Passed = false; try { channel1.Authenticate("User1", "123412341234", out User1Token); authR = channel1.ChangePassword("User1", "123", User1Token); } catch (Exception ex) { Console.WriteLine(ex); } if (!authR.valid) test16.Msg = "The change password Case is passed!"; else test16.Msg = "The change password Case is failed!"; Console.WriteLine(test16.Msg); if (authR.valid == false) test16.Passed = true; m_MsgList.Add(test16); return test16.Passed; }
private bool test15() { Console.WriteLine("Demo Change password"); Message test15 = new Message(); test15.TestID = 15; test15.Passed = false; try { channel1.Authenticate("User7", "_12456774", out User7Token); authR = channel1.ChangePassword("User7", "123123123123", User7Token); } catch (Exception ex) { Console.WriteLine(ex); } if (authR.valid) test15.Msg = "The Change password Case is passed!"; else test15.Msg = "The Change password Case is failed!"; Console.WriteLine(test15.Msg); test15.Passed = authR.valid; m_MsgList.Add(test15); return test15.Passed; }
private bool test13() { Console.WriteLine("Demo the privilege changing function"); Message test13 = new Message(); test13.TestID = 13; test13.Passed = false; try { channel1.Authenticate("User1", "123412341234", out User1Token); authR = channel1.ChangeUserPrivilege("User1", true, User1Token); } catch (Exception ex) { Console.WriteLine(ex); } if (!authR.valid) test13.Msg = "Changing Privilege of User1 Case is passed!"; else test13.Msg = "Changing Privilege of User1 Case is failed!"; Console.WriteLine(test13.Msg); if (authR.valid == false) test13.Passed = true; m_MsgList.Add(test13); return test13.Passed; }
private bool test12() { Console.WriteLine("Demo the privilege changing function"); Message test12 = new Message(); test12.TestID = 12; test12.Passed = false; try { authR = channel1.ChangeUserPrivilege("User7", true, token); } catch (Exception ex) { Console.WriteLine(ex); } if (authR.valid) test12.Msg = "Changing Privilege of User7 Case is passed!"; else test12.Msg = "Changing Privilege of User7 Case is failed!"; Console.WriteLine(test12.Msg); test12.Passed = authR.valid; m_MsgList.Add(test12); return test12.Passed; }
private bool test11() { Message test11 = new Message(); test11.TestID = 11; test11.Passed = false; Console.WriteLine("Demo WCF using Create user"); try { authR = channel1.CreateUser("User8", "_12456774", invalidToken); } catch (Exception ex) { Console.WriteLine(ex); } if (!authR.valid) test11.Msg = "Create User8 Case has been passed!"; else test11.Msg = "Create User8 Case has been failed!"; Console.WriteLine(test11.Msg); if (authR.valid == false) test11.Passed = true; m_MsgList.Add(test11); return test11.Passed; }
/// <summary> /// Change password of a user /// </summary> /// <param name="userName">user name</param> /// <param name="pwd">new password</param> /// <param name="token">the token of the user</param> /// <returns>the result of changing password</returns> public AuthResult ChangePassword(string userName, string pwd, string token) { Console.Write("\n"); Console.WriteLine("Try to change the password of " + userName + " ..."); Console.Write("\n"); AuthResult ret = new AuthResult(); // judge whether the token is an administrator or not, administrator can change anybody's password if (AuthMgr.IsAdmin(AuthMgr.RetrieveUserName(token))) { ret.valid = AuthMgr.ChangePwd(userName, pwd, out ret.msg); Console.WriteLine("\nChange password of " + userName + "\n"); return ret; } // judge whether the token match the userName, the current user can change its password else if (AuthMgr.RetrieveUserName(token) == userName) { ret.valid = AuthMgr.ChangePwd(userName, pwd, out ret.msg); Console.WriteLine("\n"+ret.msg+"\n"); return ret; } else { ret.valid = false; ret.msg = "Token is not valid!"; Console.WriteLine("\n"+ret.msg+"\n"); return ret; } }
/// <summary> /// Change the password of specific user /// </summary> /// <param name="userName"></param> /// <param name="pwd"></param> /// <param name="token"></param> /// <returns></returns> public AuthResult ChangePassword(string userName, string pwd, string token) { AuthResult ret = new AuthResult(); try { Logger.LogWrite("Changing the user password of " + userName); ret = mockAuthServer.ChangePassword(userName, pwd, token); } catch (Exception ex) { Console.WriteLine(ex); } return ret; }
private void ProcessRequest(Request req, out ReturnRequest retreq, out SynchronizeRequest syncreq) { AuthImplement authimplement = new AuthImplement(m_AuthManager); string token = ""; DateTime exptime = DateTime.Now; bool result = false; AuthResult authret = new AuthResult(); switch (req.m_RequestType) { case RequestType.Authenticate: authret = authimplement.Authenticate(req.m_Username, req.m_Password, out token); authimplement.Validate(token, out exptime); req.m_Token = token; break; case RequestType.CreateUser: authret = authimplement.CreateUser(req.m_Username, req.m_Password, token); break; case RequestType.IsAdmin: break; case RequestType.Validate: result = authimplement.Validate(req.m_Token, out exptime); break; } // Make the ReturnRequest and SynchronizeRequest object retreq = new ReturnRequest(authret, token, exptime, result, req.m_Signature); syncreq = new SynchronizeRequest(req, m_ID, exptime); }
private bool test6() { Message test6 = new Message(); test6.TestID = 6; test6.Passed = false; Console.WriteLine("Demo WCF using Create user"); try { authR = channel1.CreateUser("User3", "123456", token); } catch (Exception ex) { Console.WriteLine(ex); } if (!authR.valid) test6.Msg = "Create User3 Case has been passed!"; else test6.Msg = "Create User3 Case has been failed!"; Console.WriteLine(test6.Msg); if (authR.valid == false) test6.Passed = true; m_MsgList.Add(test6); return test6.Passed; }
private bool test9() { Message test9 = new Message(); test9.TestID = 9; test9.Passed = false; Console.WriteLine("Demo WCF using Create user"); try { authR = channel1.CreateUser("User6", "abcdefghijklmnopqrstuvwxyx", invalidToken); } catch (Exception ex) { Console.WriteLine(ex); } if (!authR.valid) test9.Msg = "Create User6 Case has been passed!"; else test9.Msg = "Create User6 Case has been failed!"; Console.WriteLine(test9.Msg); if (authR.valid == false) test9.Passed = true; m_MsgList.Add(test9); return test9.Passed; }
// Not finished, needs to be done public AuthResult ChangeUserPrivilege(string userName, bool administrator, string token) { AuthResult authret = new AuthResult(); return authret; }
private bool test2() { Message test2 = new Message(); test2.TestID = 2; test2.Passed = false; Console.WriteLine("Demo WCF Using Authenticate!"); try { authR = channel1.Authenticate("team1", "123456789", out invalidToken); } catch (Exception ex) { Console.WriteLine(ex); } if (!authR.valid) test2.Msg = "The Authenticate is passed!"; else test2.Msg = "The Authenticate is failed!"; Console.WriteLine(test2.Msg); if (authR.valid == false) test2.Passed = true; m_MsgList.Add(test2); return test2.Passed; }
public AuthResult mockAuthenticateUser(string newUser, string newUserPwd, string token) { AuthResult authresult = new AuthResult(); authresult.valid = true; authresult.msg = "Successfully authenticate users!"; return authresult; }
private bool test5() { Message test5 = new Message(); test5.TestID = 5; test5.Passed = false; Console.WriteLine("Demo WCF using Create user"); try { authR = channel1.CreateUser("User2", "123123321321", token); } catch (Exception ex) { Console.WriteLine(ex); } if (authR.valid) test5.Msg = "Create User2 Case has been passed!"; else test5.Msg = "Create User2 Case has been failed!"; Console.WriteLine(test5.Msg); test5.Passed = authR.valid; m_MsgList.Add(test5); return test5.Passed; }