private void Application_AuthenticateRequest(Object source, EventArgs e) { string[] roles = null; string userName; string CookieName = AgentHelper.cookieName; string token = AgentHelper.loginAttribute; HttpCookie Cookie = HttpContext.Current.Request.Cookies[CookieName]; LogModuleMsg("Inside Authenticate request"); //if iplanetDirPro cookie is present .. //unpack the cookie and set the username in the context if (Cookie != null) { HttpApplication application = (HttpApplication)source; HttpContext context = application.Context; string url = AgentHelper.serverUrl; url += "/identity/attributes"; //string data = "attributes_names=uid&subjectid=" + HttpUtility.UrlEncode(Cookie.Value); string data = "attributes_names=uid&subjectid=" + Cookie.Value; string restResponse = AgentHelper.MakePostRestCall(url, data); userName = GetUserId(restResponse, token); GenericIdentity userIdentity = new GenericIdentity(userName); GenericPrincipal principal = new GenericPrincipal(userIdentity, roles); context.User = principal; } }
public override string GetUserNameByEmail(string email) { string ret = string.Empty; try { string url = AgentHelper.serverUrl; url += "/identity/search"; if (AgentHelper.IsAgentTokenValid() == false) { AgentHelper.AuthenticateAgent(); } string data = "attributes_names=mail&attributes_values_mail=" + HttpUtility.UrlEncode(email) + "&admin=" + HttpUtility.UrlEncode(AgentHelper.ssoToken.Trim()); string response = AgentHelper.MakePostRestCall(url, data); int i1 = response.IndexOf("="); ret = response.Substring(i1 + 1); } catch (Exception ex) { } return(ret); }
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { MembershipUserCollection ret = null; totalRecords = 0; try { // Initialize the number of records found. totalRecords = 0; string url = AgentHelper.serverUrl; url += "/identity/search"; if (AgentHelper.IsAgentTokenValid() == false) { AgentHelper.AuthenticateAgent(); } if (usernameToMatch[usernameToMatch.Length - 1] == '%') { usernameToMatch = usernameToMatch.Substring(0, usernameToMatch.Length - 1); } string name = usernameToMatch; string nameAttr = "uid"; string data = "attributes_names=" + HttpUtility.UrlEncode(nameAttr) + "&attributes_values_" + nameAttr + "=" + name + "&admin=" + HttpUtility.UrlEncode(AgentHelper.ssoToken.Trim()); string response = AgentHelper.MakePostRestCall(url, data); ret = new MembershipUserCollection(); while (response.IndexOf("=") != -1) { int i1 = response.IndexOf("="); response = response.Substring(i1 + 1); int i2 = response.IndexOf("string"); string username; if (i2 > 0) { username = (response.Substring(0, i2 - 1)).Trim(); } else { username = (response.Substring(0)).Trim(); } MembershipUser muser = GetUser(username, true); if (muser != null) { ret.Add(muser); } totalRecords++; } } catch (Exception ex) { } return(ret); }
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline) { MembershipUser ret = null; try { string url = AgentHelper.serverUrl; url += "/identity/read"; string token = "uid"; if (AgentHelper.IsAgentTokenValid() == false) { AgentHelper.AuthenticateAgent(); } string data = "name=" + HttpUtility.UrlEncode(providerUserKey.ToString()) + "&admin=" + HttpUtility.UrlEncode(AgentHelper.ssoToken.Trim()); string response = AgentHelper.MakePostRestCall(url, data); string name = AgentHelper.GetDataFromResponse(response, token, "identitydetails"); string email = AgentHelper.GetDataFromResponse(response, "mail", "identitydetails"); ret = new MembershipUser(Membership.Provider.Name, name, name, email, string.Empty, string.Empty, true, false, //FIXME instead of the MinValue, should be the creation time DateTime.MinValue, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.MinValue); } catch (Exception ex) { //Log this exception } return(ret); }