public SSOResponse GetUserInfo(string UID) { SSOResponse response = new SSOResponse(); response.SSOScript = EyouSoft.Common.SerializationHelper.ConvertJSON <UserInfo>(CurrentUser.GetUserInfo(UID)); return(response); }
public SSOResponse UserLogout(string UID, string RedirectUrl) { SSOResponse response = new SSOResponse(); CurrentUser.UserLogout(UID); return(response); }
public void UpdateUserInfo(SSOResponse sso) { if (!string.IsNullOrEmpty(sso.SSOScript)) { UserInfo User = EyouSoft.Common.SerializationHelper.InvertJSON <UserInfo>(sso.SSOScript); CurrentUser.UpdateUserInfo(User); } }
public async Task <Guid> Login(string username, string password, string domain) { #region Temporary Code to allow dummy password for any user //if (request.Password.Equals(ConfigurationManager.AppSettings[Constants.Configuration.MockPassword], StringComparison.OrdinalIgnoreCase)) //{ // SSOResponse dummyPasswordResponse = null; // var userResponse = _activeDirectoryHelper.GetUserProfile(request.UserId, request.Domain); // if (userResponse == null) // { // dummyPasswordResponse = new SSOResponse { ErrorCode = Constants.ErrorMessageCodes.InvalidUserName, ErrorMessage = Constants.ErrorMessageCodes.InvalidUserNameMessage }; // return dummyPasswordResponse; // } // dummyPasswordResponse = new SSOResponse { AccessToken = Guid.NewGuid() }; // return dummyPasswordResponse; //} #endregion SSOResponse token = null; System.Net.IPAddress iP = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList[1]; string hostName = HttpContext.Current.Server.MachineName; string userAgentText = HttpContext.Current.Request.Browser.Browser + " " + HttpContext.Current.Request.Browser.Version; var information = new LoginRequest() { Id = ConfigurationManager.AppSettings[Constants.Configuration.ApplicationId], ApplicationId = ConfigurationManager.AppSettings[Constants.Configuration.ApplicationId], Domain = domain, Client = new LoginClient() { Ip = iP.ToString(), HostName = hostName, UserAgent = userAgentText, }, UserId = username.Split('@')[0], Password = password }; using (var client = new HttpClient()) { client.BaseAddress = new Uri(ConfigurationManager.AppSettings[Constants.Configuration.SSOApiBaseUrl]); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(Constants.Global.MediaTypeJson)); var result = client.PostAsJsonAsync(ConfigurationManager.AppSettings[Constants.Configuration.SSOWebAuthLogin], information); var response = result.Result.Content.ReadAsStringAsync().Result; //var result = await client.PostAsJsonAsync(ConfigurationManager.AppSettings[Constants.Configuration.SSOWebAuthLogin], information); //var response = result.Content.ReadAsStringAsync().Result; //var response = client.PostAsJsonAsync("api/Web/Auth/Login", information); //token = await result.Content.ReadAsAsync<SSOResponse>(); token = JsonConvert.DeserializeObject <SSOResponse>(response); } return(token.AccessToken); }
/// <summary> /// 更新用户信息 /// </summary> public void UpdateUser(EyouSoft.SSOComponent.Entity.UserInfo User) { if (User != null) { SSOResponse response = new SSOResponse(); response.UserInfo = User; new EyouSoft.SSOComponent.Remote.UserLogin().UpdateUserInfo(response); } }
/// <summary> /// 用户退出 /// </summary> /// <param name="UID">用户编号</param> /// <param name="RedirectUrl">跳转地址</param>a /// <returns>SSO返回信息</returns> public SSOResponse UserLogout(string UID, string RedirectUrl) { //RemoveCache(); LocalLogin.UserLogout(UID); SSOResponse response = new SSOResponse(); EyouSoft.SSOComponent.SSORemote.SSOResponse remoteResponse = RemoteLogin.UserLogout(UID, RedirectUrl); response.IsValid = remoteResponse.IsValid; return(null); }
/// <summary> /// 用户登录 /// </summary> /// <param name="UserName">用户名</param> /// <param name="PWD">用户密码</param> /// <param name="LoginTicket">登录凭据值</param> /// <param name="RedirectUrl">跳转地址</param> /// <returns>SSO返回信息</returns> public SSOResponse UserLoginPassword(string UserName, string PWD, string LoginTicket, PasswordType PwdType) { SSOResponse response = new SSOResponse(); SSORemote.PasswordType _pwdtype = (EyouSoft.SSOComponent.SSORemote.PasswordType)Convert.ToInt32(PwdType); EyouSoft.SSOComponent.SSORemote.SSOResponse remoteResponse = RemoteLogin.UserLoginPassword(UserName, PWD, LoginTicket, _pwdtype); response.IsValid = remoteResponse.IsValid; response.UserInfo = this.ConvertToUser(remoteResponse.UserInfo); //SetCache(); LocalLogin.UpdateUserInfo(response.UserInfo); return(response); }
public SSOResponse UserLoginPassword(string UserName, string PWD, string LoginTicket, PasswordType PwdType) { UserInfo User = CurrentUser.UserLoginAct(UserName, PWD, LoginTicket, PwdType); SSOResponse response = new SSOResponse(); if (User != null) { response.IsValid = true; response.UserInfo = User; } return(response); }
public SSOResponse UserLoginAct(string UserName, string PWD, string LoginTicket, string RedirectUrl) { UserInfo User = CurrentUser.UserLoginAct(UserName, PWD, LoginTicket); SSOResponse response = new SSOResponse(); if (User != null) { response.IsValid = true; response.UserInfo = User; } return(response); }
/// <summary> /// 更新用户信息 /// </summary> /// <param name="sso">sso信息</param> public void UpdateUserInfo(SSOResponse sso) { //SetCache(); if (sso == null) { return; } LocalLogin.UpdateUserInfo(sso.UserInfo); EyouSoft.SSOComponent.SSORemote.SSOResponse remoteresponse = new EyouSoft.SSOComponent.SSORemote.SSOResponse(); remoteresponse.SSOScript = EyouSoft.Common.SerializationHelper.ConvertJSON <UserInfo>(sso.UserInfo); RemoteLogin.UpdateUserInfo(remoteresponse); }
/// <summary> /// 用户登录 /// </summary> /// <param name="UserName">用户名</param> /// <param name="PWD">用户密码</param> /// <param name="LoginTicket">登录凭据值</param> /// <param name="RedirectUrl">跳转地址</param> /// <returns>SSO返回信息</returns> public SSOResponse UserLoginAct(string UserName, string PWD, string LoginTicket, string RedirectUrl) { SSOResponse response = new SSOResponse(); UserInfo User = new UserInfo(); EyouSoft.SSOComponent.SSORemote.SSOResponse remoteResponse = RemoteLogin.UserLoginAct(UserName, PWD, LoginTicket, RedirectUrl); User.ID = remoteResponse.UserInfo.ID; response.IsValid = remoteResponse.IsValid; response.UserInfo = User; //SetCache(); LocalLogin.UpdateUserInfo(User); return(response); }
public SSOResponse GetTicketUser(string UserName, string LoginTicket) { SSOResponse response1 = new SSOResponse(); UserInfo User = CurrentUser.UserLoginAct(UserName, "", LoginTicket); SSOResponse response = new SSOResponse(); if (User != null) { response.IsValid = true; response.SSOScript = EyouSoft.Common.SerializationHelper.ConvertJSON <UserInfo>(User); response.UserInfo = User; } return(response); }
public SSOResponse SearchUser(SearchUserInputParams inputParams) { SSOResponse rval = new SSOResponse(); try { User user = rval.User; SearchUser(inputParams.GetEnvironment(), ref user); } catch (Exception ex) { } return(rval); }
/// <summary> /// 用户登录 /// </summary> /// <param name="UserName">用户名</param> /// <param name="PWD">用户密码</param> /// <param name="LoginTicket">登录凭据值</param> /// <param name="RedirectUrl">跳转地址</param> /// <returns>SSO返回信息</returns> public SSOResponse UserLoginAct(string UserName, string PWD, string LoginTicket, string RedirectUrl) { SSOResponse response = new SSOResponse(); EyouSoft.SSOComponent.SSORemote.SSOResponse remoteResponse = RemoteLogin.UserLoginAct(UserName, PWD, LoginTicket, RedirectUrl); if (remoteResponse != null && !string.IsNullOrEmpty(remoteResponse.SSOScript)) { response.UserInfo = EyouSoft.Common.SerializationHelper.InvertJSON <UserInfo>(remoteResponse.SSOScript); response.IsValid = remoteResponse.IsValid; if (response.UserInfo != null && response.UserInfo.IsEnable) { //response.UserInfo = this.ConvertToUser(remoteResponse.UserInfo); //SetCache(); LocalLogin.UpdateUserInfo(response.UserInfo); } } return(response); }
/// <summary> /// 用户登录 /// </summary> /// <param name="UserName">用户名</param> /// <param name="PWD">用户密码</param> /// <param name="LoginTicket">登录凭据值</param> /// <param name="PwdType">登录密码类型</param> /// <returns>SSO返回信息</returns> public SSOResponse UserLoginPassword(string UserName, string PWD, string LoginTicket, PasswordType PwdType) { SSOResponse response = new SSOResponse(); SSORemote.PasswordType _pwdtype = (EyouSoft.SSOComponent.SSORemote.PasswordType)Convert.ToInt32(PwdType); EyouSoft.SSOComponent.SSORemote.SSOResponse remoteResponse = RemoteLogin.UserLoginPassword(UserName, PWD, LoginTicket, _pwdtype); if (remoteResponse != null && !string.IsNullOrEmpty(remoteResponse.SSOScript)) { response.IsValid = remoteResponse.IsValid; response.UserInfo = EyouSoft.Common.SerializationHelper.InvertJSON <UserInfo>(remoteResponse.SSOScript); if (response.UserInfo != null && response.UserInfo.IsEnable) { //response.UserInfo = this.ConvertToUser(remoteResponse.UserInfo); //SetCache(); LocalLogin.UpdateUserInfo(response.UserInfo); } } return(response); }
/// <summary> /// 根据用户名、凭据值获取用户信息 /// </summary> /// <param name="UserName">用户名</param> /// <param name="LoginTicket">登录凭据值</param> /// <returns>SSO返回信息</returns> public SSOResponse GetTicketUser(string UserName, string LoginTicket) { SSOResponse response = new SSOResponse(); UserInfo User = new UserInfo(); EyouSoft.SSOComponent.SSORemote.SSOResponse remoteResponse = RemoteLogin.GetTicketUser(UserName, LoginTicket); if (remoteResponse != null && !string.IsNullOrEmpty(remoteResponse.SSOScript)) { response.UserInfo = EyouSoft.Common.SerializationHelper.InvertJSON <UserInfo>(remoteResponse.SSOScript); response.IsValid = remoteResponse.IsValid; if (response.UserInfo != null) { //response.UserInfo = this.ConvertToUser(remoteResponse.UserInfo); //SetCache(); LocalLogin.UpdateUserInfo(response.UserInfo); } } return(response); }
public SSOResponse VerifyToken([FromBody] VerifyTokenInputParams inputParams) { try { /* * JObject rval = new JObject(); * rval["IsAuthenticated"] = false; * try * { * * JObject userObj = new JObject(); * userObj["FirstName"] = "Test"; * * rval.Add("User", userObj); * * return rval.ToString(); * } * catch (Exception ex) * { * rval["Error"] = ex.ToString(); * } * return rval.ToString(); */ SSOLookup worker = new SSOLookup(_configuration); SSOResponse resp = worker.VerifySSOSession(inputParams); if (inputParams.search_ldap_dir) { User user = resp.User; worker.SearchUser(inputParams.GetEnvironment(), ref user); } return(resp); } catch (Exception ex) { return(new SSOResponse() { error_message = "Exception in VerifyToken(), details: " + ex.Message }); } }
public string Post([FromBody] VerifyTokenInputParams inputParams) { try { /* * JObject rval = new JObject(); * rval["IsAuthenticated"] = false; * try * { * * JObject userObj = new JObject(); * userObj["FirstName"] = "Test"; * * rval.Add("User", userObj); * * return rval.ToString(); * } * catch (Exception ex) * { * rval["Error"] = ex.ToString(); * } * return rval.ToString(); */ SSOLookup worker = new SSOLookup(_configuration); SSOResponse resp = worker.VerifySSOSession(inputParams); if (inputParams.search_ldap_dir && resp.has_valid_session && !String.IsNullOrEmpty(resp.User.login_id)) { User user = resp.User; worker.SearchUser(inputParams.GetEnvironment(), ref user); } //return JsonConvert.SerializeObject(resp, Formatting.Indented); string rval = JsonConvert.SerializeObject(resp, Formatting.Indented); return(rval); } catch (Exception ex) { return("{\"error_message\" : \"{0}\"" + ex.Message + "\"}"); } }
/// <summary> /// 获取用户信息 /// </summary> /// <param name="UID">用户编号</param> /// <returns>用户信息</returns> public SSOResponse GetUserInfo(string UID) { //GetCache(); SSOResponse response = new SSOResponse(); UserInfo User = LocalLogin.GetUserInfo(UID); if (User == null) { EyouSoft.SSOComponent.SSORemote.SSOResponse remoteresponse = RemoteLogin.GetUserInfo(UID); if (remoteresponse != null && !string.IsNullOrEmpty(remoteresponse.SSOScript)) { User = EyouSoft.Common.SerializationHelper.InvertJSON <UserInfo>(remoteresponse.SSOScript); if (User != null) { LocalLogin.UpdateUserInfo(User); } } } response.UserInfo = User; return(response); }
public SSOResponse VerifySSOSession(VerifyTokenInputParams inputParams) { SSOResponse rval = new SSOResponse(); try { if (String.IsNullOrEmpty(inputParams.sso_token)) { throw new Exception("Missing valid SSO Token."); } string baseURL = ""; Models.Environment enviro = inputParams.GetEnvironment(); switch (enviro) { case Models.Environment.Dev: baseURL = GetStringValue("S_SSO_URL_DEV"); break; case Models.Environment.QA: baseURL = GetStringValue("S_SSO_URL_QA"); break; default: baseURL = GetStringValue("S_SSO_URL_PROD"); break; } // required format on call string ssoURL = String.Format("{0}/?session_id={1}&session_key={2}&session_appname={3}", baseURL, inputParams.sso_token, GetStringValue("S_SSO_SessionKey"), GetStringValue("S_SSO_SessionAppName")); Uri ssoUri = new Uri(ssoURL); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(ssoUri); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream recStream = resp.GetResponseStream(); Encoding encode = Encoding.GetEncoding("utf-8"); StreamReader reader = new StreamReader(recStream, encode); string sResponse = reader.ReadToEnd(); // we have a response now, loop through the key value pairs string[] vals = sResponse.Split(new char[2] { ':', '=' }); int count = 0; while ((count + 1) < vals.Count()) { switch (vals[count].ToUpper()) { case SESSION_STATE: rval.session_state = vals[count + 1]; rval.has_valid_session = string.Compare(rval.session_state, "valid", true) == 0; break; case SESSION_TIMELEFT: try { string[] ts = vals[count + 1].Split('.'); if (ts.Length > 5) { rval.session_time_left = new DateTime(Int32.Parse(ts[0]), Int32.Parse(ts[1]), Int32.Parse(ts[2]), Int32.Parse(ts[3]), Int32.Parse(ts[4]), Int32.Parse(ts[5])); } } catch (Exception) { } break; case SESSION_AUTHLEVEL: rval.session_level = vals[count + 1]; break; case USER_ID: rval.User.login_id = vals[count + 1]; break; case USER_TYPE: rval.User.sso_user_type = vals[count + 1]; break; case USER_FIRSTNAME: rval.User.first_name = vals[count + 1]; break; case USER_LASTNAME: rval.User.last_name = vals[count + 1]; break; case USER_EMAIL: rval.User.email = vals[count + 1]; break; case ERROR_CODE: rval.error_code = vals[count + 1]; break; default: rval.User.attributes.Add(vals[count], vals[count + 1]); break; } count += 2; } } catch (Exception ex) { rval.error_message = ex.Message; } return(rval); }