Example #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                PSDKPasswordRequest passRequest = new PSDKPasswordRequest();
                PSDKPassword        password;

                // Set passRequest hash variable
                passRequest.AppID             = "RESTExamples";
                passRequest.ConnectionPort    = 18923;
                passRequest.ConnectionTimeout = 30;
                passRequest.Safe   = "T-APP-CYBR-RESTAPI";
                passRequest.Folder = "Root";
                passRequest.Object = "Database-MicrosoftSQLServer-JG-sql01.joe-garcia.local-Svc_BambooHR";
                passRequest.Reason = "Testing Application - Connect to SQL";

                // Set required properties to be returned other than password
                passRequest.RequiredProperties.Add("PolicyId");
                passRequest.RequiredProperties.Add("UserName");
                passRequest.RequiredProperties.Add("Address");
                passRequest.RequiredProperties.Add("Database");
                passRequest.RequiredProperties.Add("Port");

                // Sending the request to get the password
                password = PasswordSDK.GetPassword(passRequest);

                // Initializes the variables to pass to the MessageBox.Show method
                string            message = "The Object's Name: " + passRequest.Object + "\n\n" + "The Object's Address: " + password.Address + "\n" + "The Object's Database: " + password.Database + "\n" + "The Object's Port: " + password.GetAttribute("PassProps.Port") + "\n\n" + "The Object's Username: "******"\n" + "The Object's Password: "******"\n" + "The Object's PlatformID: " + password.PolicyID;
                string            caption = "AIM .NET Example Results";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult      result;

                // Displays the MessageBox.
                result = MessageBox.Show(message, caption, buttons);

                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    // Closes the parent form.
                    this.Close();
                }
            }
            catch (PSDKException ex)
            {
                string            message = ex.Reason;
                string            caption = "Error";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult      result;

                result = MessageBox.Show(message, caption, buttons);

                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    // Closes the parent form.
                    this.Close();
                }
            }
        }
Example #2
0
        protected override void Execute(NativeActivityContext context)
        {
            try
            {
                string strAppId      = ApplicationId.Get(context);
                string strSafe       = Safe.Get(context);
                string strObjectName = ObjectName.Get(context);

                PSDKPasswordRequest passRequest = new PSDKPasswordRequest();
                PSDKPassword        psdkpassword;

                passRequest.AppID  = strAppId;      // "RESTExamples";
                passRequest.Safe   = strSafe;       // "T-APP-CYBR-RESTAPI";
                passRequest.Object = strObjectName; //"Database-MicrosoftSQLServer-JG-sql01.joe-garcia.local-Svc_BambooHR";

                // Set required properties to be returned other than password
                passRequest.RequiredProperties.Add("PolicyId");
                passRequest.RequiredProperties.Add("UserName");
                passRequest.RequiredProperties.Add("Address");

                // Sending the request to get the password
                psdkpassword = PasswordSDK.GetPassword(passRequest);

                string username = psdkpassword.UserName;
                string textPwd  = psdkpassword.Content;
                if (!string.IsNullOrEmpty(username))
                {
                    UserName.Set(context, username);
                }
                else
                {
                    Logger.Log.Logger.LogData("User name is null or empty in activity FetchSecurePassword", Logger.LogLevel.Info);
                }
                if (!string.IsNullOrEmpty(textPwd))
                {
                    SecureString strpwd = ToSecureString(textPwd);
                    if (strpwd != null)
                    {
                        Password.Set(context, strpwd);
                    }
                }
                else
                {
                    Logger.Log.Logger.LogData("Password is null or empty in activity FetchSecurePassword", Logger.LogLevel.Info);
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Logger.LogData(ex.Message + " in activity FetchSecurePassword", Logger.LogLevel.Error);
                if (!ContinueOnError)
                {
                    context.Abort();
                }
            }
        }
        private void getCPCreds(bool isDualAcct)
        {
            try
            {
                PSDKPasswordRequest passRequest = new
                                                  PSDKPasswordRequest();
                PSDKPassword password;
                string       dbPort = "";

                //Retreive values input by the user for items that exist in the vault
                passRequest.AppID             = txtAppId.Text;
                passRequest.ConnectionTimeout = 30;
                passRequest.Safe   = txtSafe.Text;
                passRequest.Folder = txtFolder.Text;

                //Are we retreiving a single or dual acct?
                if (isDualAcct)
                {
                    passRequest.Query = "VirtualUserName="******"userName");
                passRequest.RequiredProperties.Add("Address");
                passRequest.RequiredProperties.Add("Database");
                passRequest.RequiredProperties.Add("Port");

                // Sending the request to get the password
                password = PasswordSDK.GetPassword(passRequest);

                //set Port if available
                try {
                    dbPort = password.PasswordProperties["Port"].ToString();
                }
                catch
                {
                    dbPort = "1433";
                }

                //Build the connection string with values returned from the Credential Provider
                BuildConnString(password.Address, password.Database, password.UserName, password.Content, dbPort);
            }
            catch (PSDKException ex)
            {
                lblDBResult.Text = ex.Reason;
            }
        }