Example #1
0
        /// <summary>
        /// Sets the encoding header.
        /// </summary>
        /// <param name="headers">The header dictionary to set the encoding in.</param>
        /// <param name="authorization">The authorization details.</param>
        public static void SetAuthorization(this NameValueCollection headers, Security.Authorization authorization)
        {
            if (headers == null)
            {
                return;
            }

            if (authorization?.HasValue ?? false)
            {
                headers[EtpHeaders.Authorization] = authorization.Value;
            }
            else
            {
                headers.Remove(EtpHeaders.Authorization);
            }
        }
Example #2
0
        /// <summary>
        /// Validates the access to the site at being of http request
        /// </summary>
        /// <param name="args"></param>
        public override void Process(HttpRequestArgs args)
        {
            #region VARIABLES

            bool   bAuthenticated;
            string sLoginPageUrl;
            string sLoginPageQueryString;

            Item oItem;

            #endregion

            bAuthenticated = false;

            oAuthorization = Authorization.CurrentAuthorization;

            //get the item currently being processed
            oItem = Sitecore.Context.Item;

            if (oItem != null && oItem.InstanceOfTemplate(Genworth.SitecoreExt.Constants.Security.Templates.SecurityBase.Name))
            {
                bAuthenticated = oAuthorization != null && (oAuthorization.IsTestMode || oAuthorization.Claim != null);

                if (!bAuthenticated)
                {
                    sLoginPageUrl         = Authorization.LoginPage;
                    sLoginPageQueryString = Authorization.LoginPage_QueryString;

                    if (!string.IsNullOrEmpty(sLoginPageUrl))
                    {
                        if (!string.IsNullOrEmpty(sLoginPageQueryString) && args != null && args.Context != null &&
                            args.Context.Request != null && !string.IsNullOrEmpty(args.Context.Request.RawUrl)
                            )
                        {
                            sLoginPageUrl += sLoginPageQueryString + System.Web.HttpUtility.UrlEncode(Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(args.Context.Request.RawUrl)));
                        }

                        Sitecore.Diagnostics.Log.Info("AuthorizationResolver.Process redirected to page: " + sLoginPageUrl, this);
                        WebUtil.Redirect(sLoginPageUrl);
                    }
                    else
                    {
                        Sitecore.Diagnostics.Log.Error("Unable to get url for login page. Review setting Genworth.SitecoreExt.Security.LoginPage", this);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpClient"/> class.
        /// </summary>
        /// <param name="uri">The ETP server URI.</param>
        /// <param name="etpVersion">The ETP version for the session.</param>
        /// <param name="encoding">The ETP encoding for the session.</param>
        /// <param name="info">The client's information.</param>
        /// <param name="parameters">The client's parameters.</param>
        /// <param name="authorization">The client's authorization details.</param>
        /// <param name="headers">The WebSocket headers.</param>
        public EtpClient(string uri, EtpVersion etpVersion, EtpEncoding encoding, EtpEndpointInfo info, EtpEndpointParameters parameters = null, Security.Authorization authorization = null, IDictionary <string, string> headers = null)
            : base(etpVersion, encoding, new ClientWebSocket(), info, parameters, headers, true, null)
        {
            Headers.SetAuthorization(authorization);

            ClientSocket.Options.AddSubProtocol(EtpFactory.GetSubProtocol(EtpVersion));

            foreach (var item in Headers)
            {
                ClientSocket.Options.SetRequestHeader(item.Key, item.Value);
            }

            Uri = new Uri(uri);

            // NOTE: User-Agent cannot be set on a .NET Framework ClientWebSocket:
            // https://github.com/dotnet/corefx/issues/26627
        }
Example #4
0
        /// <summary>
        /// Sets the encoding header.
        /// </summary>
        /// <param name="headers">The header dictionary to set the encoding in.</param>
        /// <param name="authorization">The authorization details.</param>
        public static void SetAuthorization(this IDictionary <string, string> headers, Security.Authorization authorization)
        {
            if (headers == null)
            {
                return;
            }

            if (authorization?.HasValue ?? false)
            {
                headers[EtpHeaders.Authorization] = authorization.Value;
            }
            else
            {
                headers.Remove(EtpHeaders.Authorization);
            }
        }
        public IActionResult New(string name, int prefcurr)
        {
            // If the group exists for this user then return error
            //
            Security.Authorization DbRetriever = new Security.Authorization(DbContext, HttpContext);
            Models.User            currUser    = DbRetriever.GetUserFrom(HttpContext);

            // If the UserID in session doesn't reflects an actual user
            // Redirect to the sign up page
            //
            if (currUser == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            // If a group with the same name, bound to this user exists
            // Redirect to user's home page with errors set
            //
            if (currUser.Groups.Where(g => g.Name == name).FirstOrDefault() != null)
            {
                AddErrorMessage(TempData, "A group with the same name already exists");
                return(RedirectToAction("Home", "Account"));
            }

            // Make new group model with the given name
            //
            Models.Group newGroup = new Models.Group()
            {
                Name       = name,
                UserID     = currUser.UserID,
                PrefCurrID = prefcurr
            };

            // Try to validate new model
            // If it fails redirect to user home page passing the newGroup model to display errors
            //
            if (TryValidateModel(newGroup) == false)
            {
                AddErrorMessage(TempData, "Model is not valid");
                return(RedirectToAction("Home", "Account"));
            }

            // Try to make new database record
            //
            try
            {
                DbContext.Groups.Add(newGroup);
                DbContext.SaveChanges();

                // If everything is okay go to user's home page
                //
                AddOkMessage(TempData, "New group created successfully!");
            }
            catch
            {
                // If it fails to add new record to db
                // Redirect to users home page
                //
                AddErrorMessage(TempData, "Error while creating your group!");
            }

            return(RedirectToAction("Home", "Account"));
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpClient"/> class.
        /// </summary>
        /// <param name="uri">The ETP server URI.</param>
        /// <param name="etpVersion">The ETP version for the session.</param>
        /// <param name="encoding">The ETP encoding for the session.</param>
        /// <param name="info">The client's information.</param>
        /// <param name="parameters">The client's parameters.</param>
        /// <param name="authorization">The client's authorization details.</param>
        /// <param name="headers">The WebSocket headers.</param>
        public EtpClient(string uri, EtpVersion etpVersion, EtpEncoding encoding, EtpEndpointInfo info, EtpEndpointParameters parameters, Security.Authorization authorization = null, IDictionary <string, string> headers = null)
            : base(etpVersion, encoding, info, parameters, headers, true, null, false)
        {
            Headers.SetAuthorization(authorization);

            _socket = new W4N.WebSocket(uri,
                                        subProtocol: EtpFactory.GetSubProtocol(EtpVersion),
                                        cookies: null,
                                        customHeaderItems: Headers.ToList(),
                                        userAgent: info.ApplicationName);
        }