//------------------------------------------------------------------------------------------------------------------------- // Premier appel Radius public string AuthenticateRadius(string strUserName, string strPassword) { string messageLog = "== Authenticate Radius Step 1 ==============" + Environment.NewLine + "Radius Host : " + m_strRadiusHost + Environment.NewLine + "Radius Port : " + m_nRadiusPort + Environment.NewLine + "Shared Key : " + m_strRadiusSharedKey + Environment.NewLine + "Timos user name : " + strUserName + Environment.NewLine; string reponseRadius = "Request not sent"; if (strUserName != "youcef") { try { reponseRadius = AdministrationService.AuthenticateRadius(m_strRadiusHost, m_nRadiusPort, m_strRadiusSharedKey, strUserName, strPassword, ""); messageLog += "Radius response : " + reponseRadius + Environment.NewLine; } catch (Exception ex) { messageLog += "Radius response : " + ex.Message + Environment.NewLine; } Context.Log(InfoType.Information, messageLog); } else { messageLog += "Radius response : " + reponseRadius + Environment.NewLine; Context.Log(InfoType.Information, messageLog); return("11#blablabbal"); } return(reponseRadius); /* * if (ExecutingContext.CurrentHostUrl.ToLower().StartsWith(@"http://localhost")) * return "11#blablabbal"; * else * return AdministrationService.AuthenticateRadius(m_strRadiusHost, m_nRadiusPort, m_strRadiusSharedKey, strUserName, strPassword, ""); * //*/ }
//------------------------------------------------------------------------------------------------------------------------- // Authenticate user, using Security Service Configuration AspectizeUser IAuthentication.Authenticate(string userName, string secret, AuthenticationProtocol protocol, HashHelper.Algorithm algorithm, string challenge) { var parts = secret.Split('#'); string otp = parts[0]; //string password = string.Join("#", parts, 1, parts.Length - 1); string password = parts[1]; string state = parts[2]; string messageLog = "== Authenticate Radius Step 2 ==============" + Environment.NewLine + "Timos user name : " + userName + Environment.NewLine + "Radius Host : " + m_strRadiusHost + Environment.NewLine + "Radius Port : " + m_nRadiusPort + Environment.NewLine + "Shared Key : " + m_strRadiusSharedKey + Environment.NewLine + "OTP : " + otp + Environment.NewLine + "STATE : " + state + Environment.NewLine; string reponseRadius = "Request not sent"; if (userName != "youcef") { try { reponseRadius = AdministrationService.AuthenticateRadius(m_strRadiusHost, m_nRadiusPort, m_strRadiusSharedKey, userName, otp, state); messageLog += "Radius response : " + reponseRadius + Environment.NewLine; } catch (Exception ex) { messageLog += "Radius response : " + ex.Message + Environment.NewLine; } Context.Log(InfoType.Information, messageLog); var parts2 = reponseRadius.Split('#'); if (parts2[0] != "2") { return(AspectizeUser.GetUnAuthenticatedUser()); // L'authentification OTP a échoué } } else { messageLog += "Radius response : " + reponseRadius + Environment.NewLine; Context.Log(InfoType.Information, messageLog); } // Authentification TIMOS ITimosServiceForAspectize serviceClientAspectize = (ITimosServiceForAspectize)C2iFactory.GetNewObject(typeof(ITimosServiceForAspectize)); CResultAErreur result = serviceClientAspectize.OpenSession(userName, password); if (result && result.Data is Dictionary <string, object> ) { string strUserKey = ""; // Build Key-Value attached to User Dictionary <string, object> dicoProperties = (Dictionary <string, object>)result.Data; strUserKey = (string)dicoProperties[CUserTimosWebApp.c_champUserKey]; // Build Role List List <string> roles = new List <string>(); roles.Add("Registered"); // Build and return authenticated user with Properties and Roles return(AspectizeUser.GetAuthenticatedUser(strUserKey, roles.ToArray(), dicoProperties)); } return(AspectizeUser.GetUnAuthenticatedUser()); // Fin authentification TIMOS }