public SecurityBehavior(ServiceSecurity mode,StoreLocation storeLocation,StoreName storeName,X509FindType findType,string subjectName) { m_Mode = mode; m_StoreLocation = storeLocation; m_StoreName = storeName; m_FindType = findType; m_SubjectName = subjectName; }
/// <summary> /// </summary> /// <param name="mode">If set to ServiceSecurity.Anonymous,ServiceSecurity.BusinessToBusiness or ServiceSecurity.Internet then the service certificate must be listed in config file</param> public SecurityBehavior(ServiceSecurity mode) : this(mode, StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, null) { }
protected void LoginButton_Click(object sender, EventArgs e) { MembershipController member = new MembershipController(); RoleController role = new RoleController(); UserInfo user = member.GetUserDetails(GetPortalID, UserName.Text); if (user.UserExists && user.IsApproved) { if (!(string.IsNullOrEmpty(UserName.Text) && string.IsNullOrEmpty(PasswordAspx.Text))) { if (PasswordHelper.ValidateUser(user.PasswordFormat, PasswordAspx.Text, user.Password, user.PasswordSalt)) { string userRoles = role.GetRoleNames(user.UserName, GetPortalID); strRoles += userRoles; if (strRoles.Length > 0) { SetUserRoles(strRoles); //SessionTracker sessionTracker = (SessionTracker)Session[SessionKeys.Tracker]; //SessionTracker sessionTracker = (SessionTracker)Session[SessionKeys.Tracker]; //sessionTracker.PortalID = GetPortalID.ToString(); //sessionTracker.Username = UserName.Text; //Session[SessionKeys.Tracker] = sessionTracker; SageFrame.Web.SessionLog SLog = new SageFrame.Web.SessionLog(); SLog.SessionTrackerUpdateUsername(UserName.Text, GetPortalID.ToString()); StringBuilder redirectURL = new StringBuilder(); SecurityPolicy objSecurity = new SecurityPolicy(); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), true, GetPortalID.ToString(), FormsAuthentication.FormsCookiePath); string encTicket = FormsAuthentication.Encrypt(ticket); string randomCookieValue = GenerateRandomCookieValue(); Session[SessionKeys.RandomCookieValue] = randomCookieValue; HttpCookie cookie = new HttpCookie(objSecurity.FormsCookieName(GetPortalID), encTicket); SageFrameConfig objConfig = new SageFrameConfig(); string ServerCookieExpiration = objConfig.GetSettingValueByIndividualKey(SageFrameSettingKeys.ServerCookieExpiration); int expiryTime = Math.Abs(int.Parse(ServerCookieExpiration)); expiryTime = expiryTime < 5 ? 5 : expiryTime; cookie.Expires = DateTime.Now.AddMinutes(expiryTime); Response.Cookies.Add(cookie); ServiceSecurity.IssueToken(GetPortalID); if (Request.QueryString["ReturnUrl"] != null) { string PageNotFoundPage = PortalAPI.PageNotFoundURLWithRoot; string UserRegistrationPage = PortalAPI.RegistrationURLWithRoot; string PasswordRecoveryPage = PortalAPI.PasswordRecoveryURLWithRoot; string ForgotPasswordPage = PortalAPI.ForgotPasswordURL; string PageNotAccessiblePage = PortalAPI.PageNotAccessibleURLWithRoot; string ReturnUrlPage = Request.QueryString["ReturnUrl"].Replace("%2f", "-").ToString(); if (ReturnUrlPage == PageNotFoundPage || ReturnUrlPage == UserRegistrationPage || ReturnUrlPage == PasswordRecoveryPage || ReturnUrlPage == ForgotPasswordPage || ReturnUrlPage == PageNotAccessiblePage) { redirectURL.Append(GetParentURL); redirectURL.Append(PortalAPI.DefaultPageWithExtension); } else { redirectURL.Append(ResolveUrl(Request.QueryString["ReturnUrl"].ToString())); } } else { if (!IsParent) { redirectURL.Append(GetParentURL); redirectURL.Append("/portal/"); redirectURL.Append(GetPortalSEOName); redirectURL.Append("/"); redirectURL.Append(ssc.GetStoreSettingsByKey(StoreSetting.SingleCheckOutURL, GetStoreID, GetPortalID, GetCurrentCultureName)); redirectURL.Append(SageFrameSettingKeys.PageExtension); } else { redirectURL.Append(GetParentURL); redirectURL.Append("/"); redirectURL.Append(ssc.GetStoreSettingsByKey(StoreSetting.SingleCheckOutURL, GetStoreID, GetPortalID, GetCurrentCultureName)); redirectURL.Append(SageFrameSettingKeys.PageExtension); } } int customerID = GetCustomerID; if (customerID == 0) { CustomerGeneralInfo sageUserCust = CustomerGeneralInfoController.CustomerIDGetByUsername(user.UserName, storeID, portalID); if (sageUserCust != null) { customerID = sageUserCust.CustomerID; } } AspxCommonController objCommonCont = new AspxCommonController(); objCommonCont.UpdateCartAnonymoususertoRegistered(storeID, portalID, customerID, sessionCode); Response.Redirect(redirectURL.ToString(), false); } else { FailureText.Text = string.Format("<p class='sfError'>{0}</p>", GetSageMessage("UserLogin", "Youarenotauthenticatedtothisportal")); } } else { FailureText.Text = string.Format("<p class='sfError'>{0}</p>", GetSageMessage("UserLogin", "UsernameandPasswordcombinationdoesntmatched"));//"Username and Password combination doesn't matched!"; } } } else { FailureText.Text = string.Format("<p class='sfError'>{0}</p>", GetSageMessage("UserLogin", "UserDoesnotExist")); } }
/// <summary> /// </summary> /// <param name="mode">Certificate is looked up by name from LocalMachine/My store</param> public SecurityBehavior(ServiceSecurity mode,string serviceCertificateName) : this(mode,StoreLocation.LocalMachine,StoreName.My,X509FindType.FindBySubjectName,serviceCertificateName) { }
public SecurityBehaviorAttribute(ServiceSecurity mode,StoreLocation storeLocation,StoreName storeName,X509FindType findType,string serviceCertificateName) { m_SecurityBehavior = new SecurityBehavior(mode,storeLocation,storeName,findType,serviceCertificateName); }
/// <summary> /// </summary> /// <param name="mode">If set to ServiceSecurity.Anonymous,ServiceSecurity.BusinessToBusiness or ServiceSecurity.Internet then the service certificate must be listed in config file</param> public SecurityBehaviorAttribute(ServiceSecurity mode) { m_SecurityBehavior = new SecurityBehavior(mode); }
public static void SetSecurityMode <T, C>(this DuplexChannelFactory <T, C> factory, ServiceSecurity mode) where T : class { switch (mode) { case ServiceSecurity.None: { if (factory.State == CommunicationState.Opened) { throw new InvalidOperationException("Proxy channel is already opened"); } Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>(); endpoints.Add(factory.Endpoint); SecurityBehavior.ConfigureNone(endpoints); break; } case ServiceSecurity.Anonymous: { if (factory.State == CommunicationState.Opened) { throw new InvalidOperationException("Proxy channel is already opened"); } Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>(); endpoints.Add(factory.Endpoint); SecurityBehavior.ConfigureAnonymous(endpoints); factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust; break; } default: { throw new InvalidOperationException(mode + " is unsupported with this constructor"); } } }
/// <summary> /// </summary> /// <param name="mode">Certificate is looked up by name from LocalMachine/My store</param> public SecurityBehaviorAttribute(ServiceSecurity mode, string serviceCertificateName) { m_SecurityBehavior = new SecurityBehavior(mode, serviceCertificateName); }
protected void SucessFullLogin(UserInfo user) { RoleController role = new RoleController(); Session[SessionKeys.LoginHitCount] = null; string userRoles = role.GetRoleNames(user.UserName, GetPortalID); strRoles += userRoles; if (strRoles.Length > 0) { SetUserRoles(strRoles); //SessionTracker sessionTracker = (SessionTracker)Session[SessionKeys.Tracker]; //sessionTracker.PortalID = GetPortalID.ToString(); //sessionTracker.Username = UserName.Text; //Session[SessionKeys.Tracker] = sessionTracker; SageFrame.Web.SessionLog SLog = new SageFrame.Web.SessionLog(); SLog.SessionTrackerUpdateUsername(UserName.Text, GetPortalID.ToString()); StringBuilder redirectURL = new StringBuilder(); SecurityPolicy objSecurity = new SecurityPolicy(); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), true, GetPortalID.ToString(), FormsAuthentication.FormsCookiePath); // Encrypt the ticket. string encTicket = FormsAuthentication.Encrypt(ticket); //generate random cookieValue string randomCookieValue = GenerateRandomCookieValue(); Session[SessionKeys.RandomCookieValue] = randomCookieValue; //create new cookie with random cookie name and encrypted ticket HttpCookie cookie = new HttpCookie(objSecurity.FormsCookieName(GetPortalID), encTicket); //get default time from setting SageFrameConfig objConfig = new SageFrameConfig(); string ServerCookieExpiration = objConfig.GetSettingValueByIndividualKey(SageFrameSettingKeys.ServerCookieExpiration); int expiryTime = Math.Abs(int.Parse(ServerCookieExpiration)); expiryTime = expiryTime < 5 ? 5 : expiryTime; //set cookie expiry time cookie.Expires = DateTime.Now.AddMinutes(expiryTime); //add cookie to the browser Response.Cookies.Add(cookie); ServiceSecurity.IssueToken(GetPortalID); if (Request.QueryString["ReturnUrl"] != null) { string PageNotFoundPage = PortalAPI.PageNotFoundURLWithRoot; string UserRegistrationPage = PortalAPI.RegistrationURLWithRoot; string PasswordRecoveryPage = PortalAPI.PasswordRecoveryURLWithRoot; string ForgotPasswordPage = PortalAPI.ForgotPasswordURL; string PageNotAccessiblePage = PortalAPI.PageNotAccessibleURLWithRoot; string ReturnUrlPage = string.Empty; if (Request.QueryString["ReturnUrl"].Replace("%2f", "-").ToString().Contains(GetHostURL())) { ReturnUrlPage = Request.QueryString["ReturnUrl"].Replace("%2f", "-").ToString(); } else { ReturnUrlPage = GetHostURL() + Request.QueryString["ReturnUrl"].Replace("%2f", "-").ToString(); } string RequestURL = Request.Url.ToString(); Uri RequestURLPageUri = new Uri(RequestURL); string portalHostURL = RequestURLPageUri.AbsolutePath.TrimStart('/'); if (GetApplicationName == string.Empty) { bool IsWellFormedReturnUrlPage = Uri.IsWellFormedUriString(ReturnUrlPage, UriKind.Absolute); if (IsWellFormedReturnUrlPage) { Uri ReturnUrlPageUri = new Uri(ReturnUrlPage); string ReturnURl = ReturnUrlPageUri.Scheme + Uri.SchemeDelimiter + ReturnUrlPageUri.Host + ":" + ReturnUrlPageUri.Port; string HostUrl = GetHostURL(); Uri uriHostURL = new Uri(HostUrl); Uri uriReturnURL = new Uri(ReturnURl); var resultCompareURL = Uri.Compare(uriHostURL, uriReturnURL, UriComponents.Host | UriComponents.PathAndQuery, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); int resultComparePortalURL = 0; if (portalHostURL.ToLower().Contains("portal") && resultCompareURL == 0) { Uri ReturnUrlPageHostUri = new Uri(ReturnUrlPage); string portalReturnURL = ReturnUrlPageHostUri.AbsolutePath.TrimStart('/'); string[] portalReturnURLSplit = portalReturnURL.Split('/'); string ReturnURLSplitPortal = portalReturnURLSplit[0]; string ReturnURLSplitPortalName = portalReturnURLSplit[1]; string ReturnURLWithPortal = ReturnURLSplitPortal + "/" + ReturnURLSplitPortalName; string[] portalHostURLSplit = portalHostURL.Split('/'); string HostURLSplitPortal = portalHostURLSplit[0]; string HostURLSplitPortalName = portalHostURLSplit[1]; string HostURLWithPortal = HostURLSplitPortal + "/" + HostURLSplitPortalName; resultComparePortalURL = string.Compare(ReturnURLWithPortal, HostURLWithPortal); } if (resultCompareURL != 0 || resultComparePortalURL != 0) { PageNotFoundURL(); } } else { PageNotFoundURL(); } } if (ReturnUrlPage == PageNotFoundPage || ReturnUrlPage == UserRegistrationPage || ReturnUrlPage == PasswordRecoveryPage || ReturnUrlPage == ForgotPasswordPage || ReturnUrlPage == PageNotAccessiblePage) { redirectURL.Append(GetParentURL); redirectURL.Append(PortalAPI.DefaultPageWithExtension); } else { redirectURL.Append(ResolveUrl(Request.QueryString["ReturnUrl"].ToString())); } } else { if (!IsParent) { redirectURL.Append(GetParentURL); redirectURL.Append("/portal/"); redirectURL.Append(GetPortalSEOName); redirectURL.Append("/"); redirectURL.Append(PortalAPI.DefaultPageWithExtension); } else { redirectURL.Append(GetParentURL); redirectURL.Append("/"); redirectURL.Append(PortalAPI.DefaultPageWithExtension); } } HttpContext.Current.Session[SessionKeys.IsLoginClick] = true; if (Session[SessionKeys.LoginHitCount] != null) { HttpContext.Current.Session.Remove(SessionKeys.LoginHitCount); } Response.Redirect(redirectURL.ToString(), false); } else { FailureText.Text = string.Format("<p class='sfError'>{0}</p>", GetSageMessage("UserLogin", "Youarenotauthenticatedtothisportal"));//"You are not authenticated to this portal!"; } }
protected void StartService() { Dictionary <string, string> configs = ConfigHelper.GetPluginSpecificConfig(PluginName); // wenn ein zweiter Port vorhanden ist, kann eine zweite Instanz gestartet werden int instances = configs.ContainsKey("2ndPort") ? 2 : 1; string[] prefixes = new string[] { "", "2nd" }; // TODO: Dynamisch Anzahl und Art der Prefixes herausfinden; momentan sind die Werte fix (max 2 Prefixes/Instanzen, einmal "" und einmal "2nd") try { for (int instance = 1; instance <= instances; instance++) { String authMethod = ConfigHelper.GetInstanceParam(configs, "AuthenticationMethod", prefixes, instance); ServiceSecurity serviceSecurity = new ServiceSecurity(authMethod); Uri uri = new Uri(serviceSecurity.HTTP_S + "://" + _address + ":" + _port + "/" + _uriPattern + "/REST"); if (!uri.IsWellFormedOriginalString()) { throw new Exception("The URI Pattern is not well formed!"); } _uris.Add(uri); ServiceHost host = new ServiceHost(_service, uri) { CloseTimeout = new TimeSpan(0, 0, 0, 0, 50) }; _hosts.Add(host); var binding = new WebHttpBinding { MaxReceivedMessageSize = 268435456, SendTimeout = new TimeSpan(1, 0, 0), ReceiveTimeout = new TimeSpan(1, 0, 0), // für Security: Anhand des Binding-Namens wird eruiert, welche ConfigSection & Prefix für diese ServiceBinding-Instanz genutzt werden soll Name = PluginName + "." + prefixes [instance - 1] }; binding.Security.Mode = serviceSecurity.BindingSecurityMode; binding.Security.Transport.ClientCredentialType = serviceSecurity.BindingClientCredentialType; var readerQuotas = new XmlDictionaryReaderQuotas { MaxDepth = 2147483647, MaxStringContentLength = 2147483647, MaxBytesPerRead = 2147483647, MaxNameTableCharCount = 2147483647, MaxArrayLength = 2147483647 }; binding.ReaderQuotas = readerQuotas; var se = host.AddServiceEndpoint(RESTServiceInterfaceType, binding, uri); var webBehav = new WebHttpBehavior { FaultExceptionEnabled = true, HelpEnabled = true }; se.Behaviors.Add(webBehav); // this adds a additional instanceId header to every response se.Behaviors.Add(new FaultTolerantServiceBehavior()); ((ServiceBehaviorAttribute)host.Description.Behaviors [typeof(ServiceBehaviorAttribute)]).InstanceContextMode = InstanceContextMode.Single; } } catch (Exception) { _hosts.ForEach(h => h.Abort()); throw; } }
protected void StartService() { Dictionary<string, string> configs = ConfigHelper.GetPluginSpecificConfig (PluginName); // wenn ein zweiter Port vorhanden ist, kann eine zweite Instanz gestartet werden int instances = configs.ContainsKey ("2ndPort") ? 2 : 1; string[] prefixes = new string[] { "", "2nd" }; // TODO: Dynamisch Anzahl und Art der Prefixes herausfinden; momentan sind die Werte fix (max 2 Prefixes/Instanzen, einmal "" und einmal "2nd") try { for (int instance = 1; instance <= instances; instance++) { String authMethod = ConfigHelper.GetInstanceParam (configs, "AuthenticationMethod", prefixes, instance); ServiceSecurity serviceSecurity = new ServiceSecurity (authMethod); Uri uri = new Uri (serviceSecurity.HTTP_S + "://" + _address + ":" + _port + "/" + _uriPattern + "/REST"); if (!uri.IsWellFormedOriginalString ()) { throw new Exception ("The URI Pattern is not well formed!"); } _uris.Add (uri); ServiceHost host = new ServiceHost (_service, uri) { CloseTimeout = new TimeSpan (0, 0, 0, 0, 50) }; _hosts.Add (host); var binding = new WebHttpBinding { MaxReceivedMessageSize = 268435456, SendTimeout = new TimeSpan (1, 0, 0), ReceiveTimeout = new TimeSpan (1, 0, 0), // für Security: Anhand des Binding-Namens wird eruiert, welche ConfigSection & Prefix für diese ServiceBinding-Instanz genutzt werden soll Name = PluginName + "." + prefixes [instance - 1] }; binding.Security.Mode = serviceSecurity.BindingSecurityMode; binding.Security.Transport.ClientCredentialType = serviceSecurity.BindingClientCredentialType; var readerQuotas = new XmlDictionaryReaderQuotas { MaxDepth = 2147483647, MaxStringContentLength = 2147483647, MaxBytesPerRead = 2147483647, MaxNameTableCharCount = 2147483647, MaxArrayLength = 2147483647 }; binding.ReaderQuotas = readerQuotas; var se = host.AddServiceEndpoint (RESTServiceInterfaceType, binding, uri); var webBehav = new WebHttpBehavior { FaultExceptionEnabled = true, HelpEnabled = true }; se.Behaviors.Add (webBehav); // this adds a additional instanceId header to every response se.Behaviors.Add (new FaultTolerantServiceBehavior ()); ((ServiceBehaviorAttribute)host.Description.Behaviors [typeof(ServiceBehaviorAttribute)]).InstanceContextMode = InstanceContextMode.Single; } } catch (Exception) { _hosts.ForEach (h => h.Abort ()); throw; } }
public void ShouldGetPermissions() { ServiceSecurity.GetServiceSecurityDescriptor("CarbonGrantPrivilege"); }
protected void SucessFullLogin(UserInfo user) { RoleController role = new RoleController(); Session[SessionKeys.LoginHitCount] = null; string userRoles = role.GetRoleNames(user.UserName, GetPortalID); strRoles += userRoles; if (strRoles.Length > 0) { SetUserRoles(strRoles); SessionTracker sessionTracker = (SessionTracker)Session[SessionKeys.Tracker]; sessionTracker.PortalID = GetPortalID.ToString(); sessionTracker.Username = UserName.Text; Session[SessionKeys.Tracker] = sessionTracker; SageFrame.Web.SessionLog SLog = new SageFrame.Web.SessionLog(); SLog.SessionTrackerUpdateUsername(sessionTracker, sessionTracker.Username, GetPortalID.ToString()); StringBuilder redirectURL = new StringBuilder(); SecurityPolicy objSecurity = new SecurityPolicy(); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), true, GetPortalID.ToString(), FormsAuthentication.FormsCookiePath); // Encrypt the ticket. string encTicket = FormsAuthentication.Encrypt(ticket); //generate random cookieValue string randomCookieValue = GenerateRandomCookieValue(); Session[SessionKeys.RandomCookieValue] = randomCookieValue; //create new cookie with random cookie name and encrypted ticket HttpCookie cookie = new HttpCookie(objSecurity.FormsCookieName(GetPortalID), encTicket); //get default time from setting SageFrameConfig objConfig = new SageFrameConfig(); string ServerCookieExpiration = objConfig.GetSettingValueByIndividualKey(SageFrameSettingKeys.ServerCookieExpiration); int expiryTime = Math.Abs(int.Parse(ServerCookieExpiration)); expiryTime = expiryTime < 5 ? 5 : expiryTime; //set cookie expiry time cookie.Expires = DateTime.Now.AddMinutes(expiryTime); //add cookie to the browser Response.Cookies.Add(cookie); ServiceSecurity.IssueToken(GetPortalID); if (Request.QueryString["ReturnUrl"] != null) { string PageNotFoundPage = PortalAPI.PageNotFoundURLWithRoot; string UserRegistrationPage = PortalAPI.RegistrationURLWithRoot; string PasswordRecoveryPage = PortalAPI.PasswordRecoveryURLWithRoot; string ForgotPasswordPage = PortalAPI.ForgotPasswordURL; string PageNotAccessiblePage = PortalAPI.PageNotAccessibleURLWithRoot; string ReturnUrlPage = Request.QueryString["ReturnUrl"].Replace("%2f", "-").ToString(); if (ReturnUrlPage == PageNotFoundPage || ReturnUrlPage == UserRegistrationPage || ReturnUrlPage == PasswordRecoveryPage || ReturnUrlPage == ForgotPasswordPage || ReturnUrlPage == PageNotAccessiblePage) { redirectURL.Append(GetParentURL); redirectURL.Append(PortalAPI.DefaultPageWithExtension); } else { redirectURL.Append(ResolveUrl(Request.QueryString["ReturnUrl"].ToString())); } } else { if (!IsParent) { redirectURL.Append(GetParentURL); redirectURL.Append("/portal/"); redirectURL.Append(GetPortalSEOName); redirectURL.Append("/"); redirectURL.Append(PortalAPI.DefaultPageWithExtension); } else { redirectURL.Append(GetParentURL); redirectURL.Append("/"); redirectURL.Append(PortalAPI.DefaultPageWithExtension); } } HttpContext.Current.Session["IsLoginClick" + user.UserName] = true; Response.Redirect(redirectURL.ToString(), false); } else { FailureText.Text = string.Format("<p class='sfError'>{0}</p>", GetSageMessage("UserLogin", "Youarenotauthenticatedtothisportal"));//"You are not authenticated to this portal!"; } }
private void RunCommandService() { _serviceFacade = new ServiceCore(); string internalSessionId = Guid.NewGuid().ToString(); // Ensure that the super user admin exists _serviceFacade.ExecuteCommand(new ServiceRequestContext { Command = String.Format("NewUser /name:{0} /pwd:{1} /cpwd:{1} /role:admin /silent", AzureContext.Current.Config.Runtime.SuperUser.Username, AzureContext.Current.Config.Runtime.SuperUser.Password), SessionId = internalSessionId }); // Ensure that the super user readonly exists _serviceFacade.ExecuteCommand(new ServiceRequestContext { Command = String.Format("NewUser /name:{0}_ro /pwd:{1} /cpwd:{1} /role:readonly /silent", AzureContext.Current.Config.Runtime.SuperUser.Username, AzureContext.Current.Config.Runtime.SuperUser.Password), SessionId = internalSessionId }); var serviceConfig = AzureContext.Current.Config.Runtime.Server; _serviceHostNative = new WcfService <ICommandService <object>, NativeCommandService>("localhost", "CommandService"); _serviceHostJson = new WcfService <ICommandService <string>, JsonCommandService>("localhost", "CommandService"); for (int i = 0; i < serviceConfig.Count; i++) { var configuration = new BindingConfiguration { Port = serviceConfig[i].Port.ToString(CultureInfo.InvariantCulture), ServiceType = serviceConfig[i].GetWcfServiceType() }; var binding = BindingFactory.Create(configuration); if (binding.DataTypes.IsSet(DataTypeSupport.Native)) { _serviceHostNative.AddBinding(binding); } else if (binding.DataTypes.IsSet(DataTypeSupport.Json)) { _serviceHostJson.AddBinding(binding); } } if (AzureContext.Current.Config.Runtime.ServiceSecurity == ServiceSecurityMode.BasicSSL) { var serviceSecurity = new ServiceSecurity { CertificateConfiguration = AzureContext.Current.Config.Certificate.Default, SecurityMode = AzureContext.Current.Config.Runtime.ServiceSecurity }; _serviceHostJson.SetSecured(serviceSecurity); _serviceHostNative.SetSecured(serviceSecurity); } _serviceHostNative.Host(); _serviceHostJson.Host(); var authOutput = _serviceFacade.ExecuteCommand(new ServiceRequestContext { Command = String.Format("UserAuth /name:{0} /pwd:{1}", AzureContext.Current.Config.Runtime.SuperUser.Username, AzureContext.Current.Config.Runtime.SuperUser.Password), SessionId = internalSessionId }); var authenticationOutput = authOutput.Data as AuthenticationOutput; if (authenticationOutput == null) { throw new InvalidOperationException( "Could not authenticate server user: "******"GetSettings", SessionId = internalSessionId }); if (settingsOutput != null && settingsOutput.Data != null) { var settings = (Dictionary <string, string>)settingsOutput.Data; foreach (var setting in settings) { CurrentContext.Default.ApplicationParams.Add(setting.Key, setting.Value); } } //AppContext.Current.Log.Info("Agent Started: " + _serviceHostNative); //AppContext.Current.Log.Info("Agent Started: " + _serviceHostJson); }
/// <summary> /// </summary> /// <param name="mode">Certificate is looked up by name from LocalMachine/My store</param> public SecurityBehavior(ServiceSecurity mode, string serviceCertificateName) : this(mode, StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, serviceCertificateName) { }
/// <summary> /// Can only call before openning the host /// </summary> /// <param name="mode">Certificate is looked up by name from LocalMachine/My store</param> public void SetSecurityBehavior(ServiceSecurity mode, string serviceCertificateName, bool useAspNetProviders, string applicationName, bool impersonateAll) { SetSecurityBehavior(mode, StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, serviceCertificateName, useAspNetProviders, applicationName, impersonateAll); }
public SecurityBehaviorAttribute(ServiceSecurity mode, StoreLocation storeLocation, StoreName storeName, X509FindType findType, string serviceCertificateName) { m_SecurityBehavior = new SecurityBehavior(mode, storeLocation, storeName, findType, serviceCertificateName); }
/// <summary> /// Can only call before openning the host /// </summary> /// <param name="mode">If set to ServiceSecurity.Anonymous,ServiceSecurity.BusinessToBusiness or ServiceSecurity.Internet then the service certificate must be listed in config file</param> public static void SetSecurityBehavior(this ServiceHost host, ServiceSecurity mode, bool useAspNetProviders, string applicationName) { SetSecurityBehavior(host, mode, useAspNetProviders, applicationName, false); }
/// <summary> /// Can only call before openning the host /// </summary> /// <param name="mode">If set to ServiceSecurity.Anonymous,ServiceSecurity.BusinessToBusiness or ServiceSecurity.Internet then the service certificate must be listed in config file</param> public static void SetSecurityBehavior(this ServiceHost host, ServiceSecurity mode, bool useAspNetProviders, string applicationName, bool impersonateAll) { SetSecurityBehavior(host, mode, StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, null, useAspNetProviders, applicationName, impersonateAll); }
/// <summary> /// Can only call before openning the host /// </summary> /// <param name="mode">Certificate is looked up by name from LocalMachine/My store</param> public static void SetSecurityBehavior(this ServiceHost host, ServiceSecurity mode, string serviceCertificateName, bool useAspNetProviders, string applicationName) { SetSecurityBehavior(host, mode, StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, serviceCertificateName, useAspNetProviders, applicationName, false); }
/// <summary> /// </summary> /// <param name="mode">Certificate is looked up by name from LocalMachine/My store</param> public SecurityBehaviorAttribute(ServiceSecurity mode,string serviceCertificateName) { m_SecurityBehavior = new SecurityBehavior(mode,serviceCertificateName); }
/// <summary> /// Can only call before openning the host /// </summary> public static void SetSecurityBehavior(this ServiceHost host, ServiceSecurity mode, StoreLocation storeLocation, StoreName storeName, X509FindType findType, string serviceCertificateName, bool useAspNetProviders, string applicationName) { SetSecurityBehavior(host, mode, storeLocation, storeName, findType, serviceCertificateName, useAspNetProviders, applicationName, false); }
/// <summary> /// </summary> /// <param name="mode">If set to ServiceSecurity.Anonymous,ServiceSecurity.BusinessToBusiness or ServiceSecurity.Internet then the service certificate must be listed in config file</param> public SecurityBehavior(ServiceSecurity mode) : this(mode,StoreLocation.LocalMachine,StoreName.My,X509FindType.FindBySubjectName,null) { }
private void LogInPublicModeRegistration() { string strRoles = string.Empty; MembershipController member = new MembershipController(); RoleController role = new RoleController(); UserInfo user = member.GetUserDetails(GetPortalID, UserName.Text.Trim()); if (!(string.IsNullOrEmpty(UserName.Text) && string.IsNullOrEmpty(Password.Text))) { if (PasswordHelper.ValidateUser(user.PasswordFormat, Password.Text, user.Password, user.PasswordSalt)) { string userRoles = role.GetRoleNames(user.UserName, GetPortalID); strRoles += userRoles; if (strRoles.Length > 0) { SetUserRoles(strRoles); //SessionTracker sessionTracker = (SessionTracker)Session[SessionKeys.Tracker]; //sessionTracker.PortalID = GetPortalID.ToString(); //sessionTracker.Username = UserName.Text; //Session[SessionKeys.Tracker] = sessionTracker; SageFrame.Web.SessionLog SLog = new SageFrame.Web.SessionLog(); SageFrameConfig SageConfig = new SageFrameConfig(); SageFrameSettingKeys.PageExtension = SageConfig.GetSettingsByKey(SageFrameSettingKeys.SettingPageExtension); bool EnableSessionTracker = bool.Parse(SageConfig.GetSettingValueByIndividualKey(SageFrameSettingKeys.EnableSessionTracker)); if (EnableSessionTracker) { SLog.SessionTrackerUpdateUsername(UserName.Text, GetPortalID.ToString()); } { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), true, GetPortalID.ToString(), FormsAuthentication.FormsCookiePath); StoreSettingConfig ssc = new StoreSettingConfig(); if (ssc.GetStoreSettingsByKey(StoreSetting.AllowRealTimeNotifications, GetStoreID, GetPortalID, GetCurrentCultureName).ToLower() == "true") { RealTimeHelper.UpdateAdminNotifications(GetStoreID, GetPortalID); } // Encrypt the ticket. string encTicket = FormsAuthentication.Encrypt(ticket); // Create the cookie. string randomCookieValue = GenerateRandomCookieValue(); Session[SessionKeys.RandomCookieValue] = randomCookieValue; SecurityPolicy objSecurity = new SecurityPolicy(); HttpCookie cookie = new HttpCookie(objSecurity.FormsCookieName(GetPortalID), encTicket); SageFrameConfig objConfig = new SageFrameConfig(); string ServerCookieExpiration = objConfig.GetSettingValueByIndividualKey(SageFrameSettingKeys.ServerCookieExpiration); int expiryTime = Math.Abs(int.Parse(ServerCookieExpiration)); expiryTime = expiryTime < 5 ? 5 : expiryTime; cookie.Expires = DateTime.Now.AddMinutes(expiryTime); Response.Cookies.Add(cookie); string sessionCode = string.Empty; ServiceSecurity.IssueToken(GetPortalID); if (HttpContext.Current.Session.SessionID != null) { sessionCode = HttpContext.Current.Session.SessionID.ToString(); } int CustomerID = GetUserDetailsByUserName(UserName.Text, GetPortalID).CustomerID; UpdateCartAnonymoususertoRegistered(GetStoreID, GetPortalID, CustomerID, sessionCode); if (!IsParent) { Response.Redirect(ResolveUrl("~/portal/" + GetPortalSEOName + "/" + pagebase.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage) + Extension), false); } else { Response.Redirect(ResolveUrl("~/" + pagebase.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage) + Extension), false); } } } } } }
public void ShouldGetPermissions() { var service = ServiceController.GetServices()[0]; ServiceSecurity.GetServiceSecurityDescriptor(service.ServiceName); }
protected override void OnStart(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; var contextSettings = new ContextSettings { CommandFactory = new CommandFactory() }; HostContext.CreateFrom(_arguments.GetValue("configPath", "konfdb.json"), contextSettings); CurrentHostContext.Default.Log.Info("Agent Started: DataManagement"); #region Run Command Service ServiceFacade = new ServiceCore(); string internalSessionId = Guid.NewGuid().ToString(); // Ensure that the super user admin exists ServiceFacade.ExecuteCommand(new ServiceRequestContext { Command = String.Format("NewUser /name:{0} /pwd:{1} /cpwd:{1} /role:admin /silent", CurrentHostContext.Default.Config.Runtime.SuperUser.Username, CurrentHostContext.Default.Config.Runtime.SuperUser.Password), SessionId = internalSessionId }); // Ensure that the super user readonly exists ServiceFacade.ExecuteCommand(new ServiceRequestContext { Command = String.Format("NewUser /name:{0}_ro /pwd:{1} /cpwd:{1} /role:readonly /silent", CurrentHostContext.Default.Config.Runtime.SuperUser.Username, CurrentHostContext.Default.Config.Runtime.SuperUser.Password), SessionId = internalSessionId }); var serviceConfig = CurrentHostContext.Default.Config.Runtime.Server; _serviceHostNative = new WcfService <ICommandService <object>, NativeCommandService>("localhost", "CommandService"); _serviceHostJson = new WcfService <ICommandService <string>, JsonCommandService>("localhost", "CommandService"); for (int i = 0; i < serviceConfig.Count; i++) { var configuration = new BindingConfiguration { Port = serviceConfig[i].Port.ToString(CultureInfo.InvariantCulture), ServiceType = serviceConfig[i].GetWcfServiceType() }; var binding = BindingFactory.Create(configuration); if (binding.DataTypes.IsSet(DataTypeSupport.Native)) { _serviceHostNative.AddBinding(binding); } else if (binding.DataTypes.IsSet(DataTypeSupport.Json)) { _serviceHostJson.AddBinding(binding); } } if (CurrentHostContext.Default.Config.Runtime.ServiceSecurity == ServiceSecurityMode.BasicSSL) { var serviceSecurity = new ServiceSecurity { CertificateConfiguration = CurrentHostContext.Default.Config.Certificate.Default, SecurityMode = CurrentHostContext.Default.Config.Runtime.ServiceSecurity }; _serviceHostJson.SetSecured(serviceSecurity); _serviceHostNative.SetSecured(serviceSecurity); } _serviceHostNative.Host(); _serviceHostJson.Host(); var authOutput = ServiceFacade.ExecuteCommand(new ServiceRequestContext { Command = String.Format("UserAuth /name:{0} /pwd:{1}", CurrentHostContext.Default.Config.Runtime.SuperUser.Username, CurrentHostContext.Default.Config.Runtime.SuperUser.Password), SessionId = internalSessionId }); var authenticationOutput = authOutput.Data as AuthenticationOutput; if (authenticationOutput == null) { throw new InvalidOperationException( "Could not authenticate server user: "******"GetSettings", SessionId = internalSessionId }); if (settingsOutput != null && settingsOutput.Data != null) { var settings = (Dictionary <string, string>)settingsOutput.Data; foreach (var setting in settings) { CurrentHostContext.Default.ApplicationParams.Add(setting.Key, setting.Value); } } //AppContext.Current.Log.Info("Agent Started: " + _serviceHostNative); //AppContext.Current.Log.Info("Agent Started: " + _serviceHostJson); #endregion _thread = new Thread(RunInBackground) { Name = "ShellService", IsBackground = true }; _shutdownEvent = new ManualResetEvent(false); _thread.Start(); }