Ejemplo n.º 1
0
        public static CloudConnection CreateAndImplersonateUser(string username, string password)
        {
            string target        = ConfigurationManager.AppSettings["target"];
            string adminUser     = ConfigurationManager.AppSettings["adminUsername"].ToString();
            string adminPassword = ConfigurationManager.AppSettings["adminPassword"].ToString();

            CloudCredentialsEncryption encryptor = new CloudCredentialsEncryption();
            SecureString encryptedPassword       = CloudCredentialsEncryption.GetSecureString(adminPassword);

            Uhuru.CloudFoundry.Connection.CloudClient cloudClient = new Connection.CloudClient();
            try
            {
                cloudClient.CreateUser(adminUser, adminPassword, @"http://" + target);
            }
            catch (Uhuru.CloudFoundry.Connection.CloudClientException)
            {
            }
            CloudManager    cloudManager    = CloudManager.Instance();
            CloudTarget     cloudTarget     = new CloudTarget(adminUser, encryptedPassword, new Uri(@"http://" + target));
            CloudConnection cloudConnection = cloudManager.GetConnection(cloudTarget);

            cloudConnection.CreateUser(username, password);

            SecureString newPassword = CloudCredentialsEncryption.GetSecureString(password);

            cloudTarget = new CloudTarget(username, newPassword, new Uri(@"http://" + target));

            cloudConnection = cloudManager.GetConnection(cloudTarget);

            return(cloudConnection);
        }
Ejemplo n.º 2
0
        public static void DeleteUser(string username, List <string> directoriesCreated)
        {
            string target = ConfigurationManager.AppSettings["target"];
            CloudCredentialsEncryption encryptor = new CloudCredentialsEncryption();
            string          adminPassword        = ConfigurationManager.AppSettings["adminPassword"].ToString();
            SecureString    encryptedPassword    = CloudCredentialsEncryption.GetSecureString(adminPassword);
            CloudManager    cloudManager         = CloudManager.Instance();
            CloudTarget     cloudTarget          = new CloudTarget(ConfigurationManager.AppSettings["adminUsername"].ToString(), encryptedPassword, new Uri("http://" + target));
            CloudConnection cloudConnection      = cloudManager.GetConnection(cloudTarget);

            User tempUser = cloudConnection.Users.First(usr => usr.Email == username);

            tempUser.Delete();
            foreach (string str in directoriesCreated)
            {
                Directory.Delete(str, true);
            }
        }