Beispiel #1
0
        //get IP address of the client
        //from: http://stackoverflow.com/questions/13889463/get-client-ip-address-in-self-hosted-signalr-hub

        //delete message, need to control
        public void DeleteMessage(int messageId, int moduleId)
        {
            //todo: look to see if we should get user information from DNN somehow - CJH 3/5/2014
            var section       = (MachineKeySection)ConfigurationManager.GetSection("system.web/machineKey");
            var validationKey = section.ValidationKey;

            var listOfRoles = (string)Clients.Caller.userroles;

            if (listOfRoles != null)
            {
                var roles = listOfRoles.Split(',');

                var pc = new PortalSecurity();

                foreach (var r in roles)
                {
                    var thisRole = pc.Decrypt(validationKey, r);
                    //TODO: need to remove the hard coded administrators role here, make this a module setting - CJH 3/6/2014
                    if (thisRole == "Administrators" || thisRole == "SuperUser")
                    {
                        var mc = new MessageController();
                        mc.DeleteMessage(messageId, moduleId);

                        //get the message and send it back so that we can remove it from the proper room
                        var m = mc.GetMessage(messageId, moduleId);
                        Clients.Group(m.RoomId.ToString()).deleteMessage(m);
                    }
                }
            }
        }
 public static string DecryptParameter(string value, string encryptionKey)
 {
     PortalSecurity objSecurity = new PortalSecurity();
     value = value.Replace("_", "/");
     value = value.Replace("-", "+");
     value = value.Replace("%3d", "=");
     return objSecurity.Decrypt(encryptionKey, value);
 }
Beispiel #3
0
        public static string DecryptParameter(string Value)
        {
            PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
            string         strKey          = _portalSettings.GUID.ToString(); // restrict the key to 6 characters to conserve space
            PortalSecurity objSecurity     = new PortalSecurity();

            return(objSecurity.Decrypt(strKey, Value));
        }
Beispiel #4
0
        public static string DecryptParameter(string value, string encryptionKey)
        {
            var objSecurity = new PortalSecurity();

            //[DNN-8257] - Can't do URLEncode/URLDecode as it introduces issues on decryption (with / = %2f), so we use a modifed Base64
            value = value.Replace("_", "/");
            value = value.Replace("-", "+");
            value = value.Replace("%3d", "=");
            return(objSecurity.Decrypt(encryptionKey, value));
        }
Beispiel #5
0
        public static String Decrypt(String value, String passkey = "")
        {
            var objSec = new PortalSecurity();

            if (value == null)
            {
                return("");
            }
            if (passkey == "")
            {
                var ps = GetCurrentPortalSettings();
                passkey = ps.GUID.ToString();
            }
            return(objSec.Decrypt(passkey, value));
        }
Beispiel #6
0
        private EventMessage DeserializeMessage(string filePath, string subscriberId)
        {
            EventMessage message       = new EventMessage();
            StreamReader oStreamReader = File.OpenText(filePath);
            string       messageString = oStreamReader.ReadToEnd();

            if (messageString.IndexOf("EventMessage") < 0)
            {
                PortalSecurity oPortalSecurity = new PortalSecurity();
                messageString = oPortalSecurity.Decrypt(EventQueueConfiguration.GetConfig().EventQueueSubscribers[subscriberId].PrivateKey, messageString);
            }
            message.Deserialize(messageString);
            oStreamReader.Close();

            //remove the persisted message from the queue if it has expired
            if (message.ExpirationDate < DateTime.Now)
            {
                File.Delete(filePath);
            }

            return(message);
        }
Beispiel #7
0
        /// <summary>
        /// Obtain Authentication settings from database
        /// </summary>
        /// <remarks>
        ///  Setting records are stored in ModuleSettings table, separately for each portal,
        /// this method allows each portal could have different accessing method to Windows Active Directory
        /// </remarks>
        public Configuration()
        {
            PortalSettings        _portalSettings        = PortalController.GetCurrentPortalSettings();
            ProviderConfiguration _providerConfiguration = ProviderConfiguration.GetProviderConfiguration(AUTHENTICATION_KEY);

            mPortalId = _portalSettings.PortalId;

            PortalSecurity objSecurity = new PortalSecurity();

            try
            {
                if (_providerConfiguration.DefaultProvider == null)
                {
                    // No provider specified, so disable authentication feature
                    return;
                }
                else
                {
                    ModuleController objModules    = new ModuleController();
                    ModuleInfo       objModuleInfo = objModules.GetModuleByDefinition(mPortalId, "Site Settings");
                    Hashtable        settings      = PortalSettings.GetModuleSettings(objModuleInfo.ModuleID);

                    mWindowsAuthentication = Convert.ToBoolean(Null.GetNull(settings["WindowsAuthentication"], mWindowsAuthentication));
                    mSynchronizeRole       = Convert.ToBoolean(Null.GetNull(settings["SynchronizeRole"], mSynchronizeRole));
                    mSynchronizePassword   = Convert.ToBoolean(Null.GetNull(settings["SynchronizePassword"], mSynchronizePassword));
                    mRootDomain            = Convert.ToString(Null.GetNull(settings["RootDomain"], mRootDomain));
                    mEmailDomain           = Convert.ToString(Null.GetNull(settings["EmailDomain"], mEmailDomain));
                    mUserName           = Convert.ToString(Null.GetNull(settings["UserName"], mUserName));
                    mProviderTypeName   = Convert.ToString(Null.GetNull(settings["ProviderTypeName"], mProviderTypeName));
                    mAuthenticationType = Convert.ToString(Null.GetNull(settings["AuthenticationType"], mAuthenticationType));
                    // Since DNN 3.0, HostSettings("EncryptionKey") is empty string, so we handle by AUTHENTICATION_KEY
                    mPassword = objSecurity.Decrypt(AUTHENTICATION_KEY, Convert.ToString(Null.GetNull(settings["AuthenticationPassword"], mPassword.ToString())));
                    //mPassword = objSecurity.Decrypt(CStr(_portalSettings.HostSettings("EncryptionKey")), CType(GetValue(settings("AuthenticationPassword"), mPassword.ToString), String))
                }
            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        /// TransferUsers transfers legacy users to the new ASP.NET MemberRole Architecture
        /// </summary>
        /// <remarks>
        /// </remarks>
        ///	<param name="PortalID">Id of the Portal</param>
        ///	<param name="arrUsers">An ArrayList of the Users</param>
        ///	<param name="SuperUsers">A flag indicating whether the users are SuperUsers</param>
        /// <history>
        /// 	[cnurse]	11/6/2004	documented
        ///     [cnurse]    12/15/2005  Moved to MembershipProvider
        /// </history>
        private void TransferUsers( int PortalID, ArrayList arrUsers, bool SuperUsers )
        {
            UserController objUserCont = new UserController();
            try
            {
                //Set the MemberRole API ApplicationName
                if( SuperUsers )
                {
                    HtmlUtils.WriteFeedback( HttpContext.Current.Response, 0, "Start Transferring SuperUsers to MemberRole:<br>" );
                }
                else
                {
                    HtmlUtils.WriteFeedback( HttpContext.Current.Response, 0, "Start Transferring Portal Users to MemberRole: PortalId= " + PortalID.ToString() + "<br>" );
                }

                IDataReader dr;
                string EncryptionKey = "";
                dr = DotNetNuke.Data.DataProvider.Instance().GetHostSetting( "EncryptionKey" );
                if( dr.Read() )
                {
                    EncryptionKey = dr["SettingValue"].ToString();
                }
                dr.Close();

                int i;
                int iMin = 1;
                int iMax = 100;
                for( i = 0; i <= arrUsers.Count - 1; i++ )
                {
                    if( i%100 == 0 )
                    {
                        if( iMin > arrUsers.Count )
                        {
                            iMin = arrUsers.Count;
                        }
                        if( iMax > arrUsers.Count )
                        {
                            iMax = arrUsers.Count;
                        }

                        HtmlUtils.WriteFeedback( HttpContext.Current.Response, 0, "Transferring Users:" + iMin.ToString() + " to " + iMax.ToString() + "<br>" );

                        iMin = iMin + 100;
                        iMax = iMax + 100;
                    }

                    UserInfo objUser;
                    objUser = (UserInfo)arrUsers[i];
                    MembershipCreateStatus objStatus;
                    string strPassword;
                    PortalSecurity objPortalSecurity = new PortalSecurity();
                    strPassword = objPortalSecurity.Decrypt( EncryptionKey, objUser.Membership.Password );
                    if( objUser.IsSuperUser )
                    {
                        objUser.Membership.Approved = true;
                    }
                    MembershipUser objMembershipUser;
                    objMembershipUser = System.Web.Security.Membership.CreateUser( objUser.Username, strPassword, objUser.Email, null, null, objUser.Membership.Approved, out objStatus );
                    if( objStatus != MembershipCreateStatus.Success )
                    {
                        Exceptions.LogException( new Exception( objStatus.ToString() ) );
                    }
                    else
                    {
                        try
                        {
                            ProfileBase objProfile;
                            objProfile = ProfileBase.Create( objUser.Username, true );
                            objProfile["FirstName"] = objUser.Profile.FirstName;
                            objProfile["LastName"] = objUser.Profile.LastName;
                            objProfile["Unit"] = objUser.Profile.Unit;
                            objProfile["Street"] = objUser.Profile.Street;
                            objProfile["City"] = objUser.Profile.City;
                            objProfile["Region"] = objUser.Profile.Region;
                            objProfile["PostalCode"] = objUser.Profile.PostalCode;
                            objProfile["Country"] = objUser.Profile.Country;
                            objProfile["Telephone"] = objUser.Profile.Telephone;
                            objProfile.Save();
                        }
                        catch( Exception exc )
                        {
                            Exceptions.LogException( exc );
                        }

                        RoleController objDNNRoles = new RoleController();
                        string[] arrUserRoles = objDNNRoles.GetRolesByUser( objUser.UserID, PortalID );
                        if( arrUserRoles != null )
                        {
                            try
                            {
                                System.Web.Security.Roles.AddUserToRoles( objUser.Username, arrUserRoles );
                            }
                            catch( Exception exc )
                            {
                                Exceptions.LogException( exc );
                            }
                        }
                    }
                }
            }
            finally
            {
            }

            if( SuperUsers )
            {
                HtmlUtils.WriteFeedback( HttpContext.Current.Response, 0, "Finish Transferring SuperUsers to MemberRole:<br>" );
            }
            else
            {
                HtmlUtils.WriteFeedback( HttpContext.Current.Response, 0, "Finish Transferring Portal Users to MemberRole: PortalId= " + PortalID.ToString() + "<br>" );
            }
        }
        /// <summary>
        /// Obtain Authentication settings from database
        /// </summary>
        /// <remarks>
        ///  Setting records are stored in ModuleSettings table, separately for each portal,
        /// this method allows each portal could have different accessing method to Windows Active Directory
        /// </remarks>
        public Configuration()
        {
            PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
            ProviderConfiguration _providerConfiguration = ProviderConfiguration.GetProviderConfiguration(AUTHENTICATION_KEY);

            mPortalId = _portalSettings.PortalId;

            PortalSecurity objSecurity = new PortalSecurity();
            try
            {
                if (_providerConfiguration.DefaultProvider == null)
                {
                    // No provider specified, so disable authentication feature
                    return;
                }
                else
                {
                    ModuleController objModules = new ModuleController();
                    ModuleInfo objModuleInfo = objModules.GetModuleByDefinition(mPortalId, "Site Settings");
                    Hashtable settings = PortalSettings.GetModuleSettings(objModuleInfo.ModuleID);

                    mWindowsAuthentication = Convert.ToBoolean(Null.GetNull(settings["WindowsAuthentication"], mWindowsAuthentication));
                    mSynchronizeRole = Convert.ToBoolean(Null.GetNull(settings["SynchronizeRole"], mSynchronizeRole));
                    mSynchronizePassword = Convert.ToBoolean(Null.GetNull(settings["SynchronizePassword"], mSynchronizePassword));
                    mRootDomain = Convert.ToString(Null.GetNull(settings["RootDomain"], mRootDomain));
                    mEmailDomain = Convert.ToString(Null.GetNull(settings["EmailDomain"], mEmailDomain));
                    mUserName = Convert.ToString(Null.GetNull(settings["UserName"], mUserName));
                    mProviderTypeName = Convert.ToString(Null.GetNull(settings["ProviderTypeName"], mProviderTypeName));
                    mAuthenticationType = Convert.ToString(Null.GetNull(settings["AuthenticationType"], mAuthenticationType));
                    // Since DNN 3.0, HostSettings("EncryptionKey") is empty string, so we handle by AUTHENTICATION_KEY
                    mPassword = objSecurity.Decrypt(AUTHENTICATION_KEY, Convert.ToString(Null.GetNull(settings["AuthenticationPassword"], mPassword.ToString())));
                    //mPassword = objSecurity.Decrypt(CStr(_portalSettings.HostSettings("EncryptionKey")), CType(GetValue(settings("AuthenticationPassword"), mPassword.ToString), String))
                }
            }
            catch (Exception)
            {
            }
        }