Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var uname = Request.QueryString["uanme"] ?? null;

            if (uname != null)
            {
                uname = Request.QueryString["uanme"].ToString();
                var encString = AESEncryptionUtil.DecryptTextFromBase64String(uname, SharedConst.HELICA_DEFAULT_CYPHER_KEY);
                Response.Write(encString);
            }
        }
Exemplo n.º 2
0
 protected void btnEncrypt_ServerClick(object sender, EventArgs e)
 {
     ValidateForm();
     try
     {
         var stringToDecrypt = AESEncryptionUtil.EncryptTextToBase64String(this.txtEncyptDecrypt.Value.Trim(), SharedConst.HELICA_DEFAULT_CYPHER_KEY);
         //stringToDecrypt = stringToDecrypt.TrimEnd('=').Replace('+', '-').Replace('/', '_');
         this.rchTxtOutput.Value = stringToDecrypt;
     }
     catch (Exception ex)
     {
         divAlert.Visible = true;
         lblError.Text    = ex.Message;
     }
 }
Exemplo n.º 3
0
 protected void btnDecrypt_ServerClick(object sender, EventArgs e)
 {
     ValidateForm();
     try
     {
         if (this.txtEncyptDecrypt.Value.Length % 4 > 0)
         {
             this.txtEncyptDecrypt.Value += new string('=', 4 - this.txtEncyptDecrypt.Value.Length);
         }
         var stringToDecrypt = AESEncryptionUtil.DecryptTextFromBase64String(this.txtEncyptDecrypt.Value.Trim(), SharedConst.HELICA_DEFAULT_CYPHER_KEY);
         this.rchTxtOutput.Value = stringToDecrypt;
     }
     catch (Exception ex)
     {
         divAlert.Visible = true;
         lblError.Text    = ex.Message;
     }
 }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    if (base.Error.Count > 0)
                    {
                        divAlert.Visible = true;
                        lblErrorMsg.Text = base.Error[0];
                        return;
                    }

                    _helicaInstallationPath = SharedConst.HELICA_INSTALLATION_PATH ?? null;
                    if (_helicaInstallationPath == null || _helicaInstallationPath.Length < 1)
                    {
                        divAlert.Visible = true;
                        lblErrorMsg.Text = "Cant load the query builder! please contact system administrator";
                    }
                }

                //Get the user name of the currently logged in user and decrypt it and the UseDefault property value
                currentUser = Request.QueryString[SharedConst.QUERY_STRING_USER_NAME] ?? null;

                if (!String.IsNullOrWhiteSpace(currentUser))
                {
                    currentUser = Request.QueryString[SharedConst.QUERY_STRING_USER_NAME];
                    _useDefault = Request.QueryString["usedefault"] ?? null;

                    //Get the users role and company i.e user institution
                    var user = new TCoreUsersObject()
                    {
                        user_name = currentUser
                    };

                    List <VRTNUserDeptRoleForQbObject> units = _tCoreUser.Roles(user);
                    if (units == null || units.Count < 1)
                    {
                        //_stringToencrypt = $"username={currentUser}|role={_defaultRole}|company={_companyName}";
                        _stringToencrypt = $"username={currentUser}|role={SharedConst.HELICA_DEFAULT_ROLENAME}";
                    }
                    else
                    {
                        foreach (var unit in units)
                        {
                            if (_defaultRole == "")
                            {
                                _defaultRole = $"{unit.role_name}";
                            }
                            else
                            {
                                _defaultRole = $"{_defaultRole},{unit.role_name}";
                            }
                        }

                        _stringToencrypt = $"username={currentUser}|role={_defaultRole.TrimEnd(',')}";
                    }

                    //if (_useDefault == null || _useDefault.Length < 1)
                    //{
                    //    //_stringToencrypt = $"username={currentUser}|role={_defaultRole}|company={_companyName}";
                    //    //_stringToencrypt = $"username={currentUser}|role={SharedConst.HELICA_DEFAULT_ROLENAME}";
                    //}

                    //if (_useDefault.Equals("true") == true)
                    //{

                    //}
                    //else
                    //    return;
                }
                else
                {
                    divAlert.Visible      = true;
                    this.lblErrorMsg.Text = "Username can't be decoded or helica insight cant be found! please contact the administrator";
                    this.qbNew.Disabled   = true;
                    return;
                }

                //The aes cryptographic key
                if (SharedConst.HELICA_DEFAULT_CYPHER_KEY != null && SharedConst.HELICA_DEFAULT_CYPHER_KEY.Length > 0)
                {
                    //Encrypt the currently logged-in username using aes encryption
                    var encToken = AESEncryptionUtil.EncryptTextToBase64String(_stringToencrypt, SharedConst.HELICA_DEFAULT_CYPHER_KEY);

                    //Transform the encrypted string to a URL safe string
                    _urlSafeencToken = encToken.TrimEnd('=').Replace('+', '-').Replace('/', '_');
                    var helicaUrlStringBuilder = $"{_helicaInstallationPath}?authToken={_urlSafeencToken}";

                    lblerror.Text   = helicaUrlStringBuilder;
                    this.qbNew.HRef = helicaUrlStringBuilder;

                    Response.Redirect(helicaUrlStringBuilder, false);
                    //ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", $"loadTab({_helicaInstallationPath})", true);
                }
            }
            catch (Exception ex)
            {
                LogUtitlity.LogToText(SharedConst.Ad_HOC_LOG_PATH, ex.ToString());
            }
        }
        public static object HelicaRun(string username)
        {
            var        response         = new ResponseHandler();
            TCoreUsers _tCoreUser       = new TCoreUsers();
            string     _stringToencrypt = string.Empty;

            try
            {
                string _helicaInstallationPath = ConfigurationManager.AppSettings["HelicaInstallPath"];
                if (_helicaInstallationPath == null || _helicaInstallationPath.Length < 1)
                {
                    response.Status  = 0;
                    response.Message = "Cant load the query builder/BI tool! please contact system administrator";
                    return(response);
                }

                //Get the user name of the currently logged in user and decrypt it and the UseDefault property value
                //string currentUser = username;

                if (!String.IsNullOrWhiteSpace(username))
                {
                    string _useCompany = (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["company"])) ? "CBN_NDIC" : ConfigurationManager.AppSettings["company"];

                    //Get the users role and company i.e user institution
                    var user = new TCoreUsersObject()
                    {
                        user_name = username
                    };

                    List <VRTNUserDeptRoleForQbObject> units = _tCoreUser.Roles(user);
                    if (units == null || units.Count < 1)
                    {
                        //if current user doesn't belong to a role
                        //Assign a deault role ROLE_USER to the role parameter on helica insight
                        _stringToencrypt = $"username={username}|role={SharedConst.HELICA_DEFAULT_ROLENAME}";
                    }
                    else
                    {
                        string _roles = "";
                        foreach (var unit in units)
                        {
                            if (_roles == "")
                            {
                                _roles = $"{unit.role_name}";
                            }
                            else
                            {
                                _roles = $"{_roles},{unit.role_name}";
                            }
                        }

                        _stringToencrypt = $"username={username}|role={_roles.TrimEnd(',')}";

                        if (_useCompany != null)
                        {
                            //Get the user company name if it exists - example CBN or NDIC
                            //and modify the helica SSO string accordingly
                            if (!string.IsNullOrWhiteSpace(_tCoreUser.UserInst(username)))
                            {
                                _stringToencrypt = $"username={username}|role={_roles.TrimEnd(',')}|company={_useCompany}";
                            }
                        }
                    }
                }
                else
                {
                    response.Status  = 0;
                    response.Message = "Username cant be empty";
                    return(response);
                }

                //Check if the encryption key is available for use
                //else throw and log an error - encryption key not available
                if (SharedConst.HELICA_DEFAULT_CYPHER_KEY != null && SharedConst.HELICA_DEFAULT_CYPHER_KEY.Length > 0)
                {
                    //Encrypt the currently logged-in username using aes encryption
                    var encToken = AESEncryptionUtil.EncryptTextToBase64String(_stringToencrypt, SharedConst.HELICA_DEFAULT_CYPHER_KEY);

                    //Transform the encrypted string to a URL safe string

                    string _urlSafeencToken       = encToken.TrimEnd('=').Replace('+', '-').Replace('/', '_');
                    var    helicaUrlStringBuilder = $"{_helicaInstallationPath}?authToken={_urlSafeencToken}";

                    response.Status  = 1;
                    response.Message = helicaUrlStringBuilder;
                    return(response);
                }
                else
                {
                    LogUtitlity.LogToText("The encryption key cant be located");
                }
            }
            catch (Exception ex)
            {
                LogUtitlity.LogToText(ex.ToString());
            }

            return(response);
        }