Ejemplo n.º 1
0
        public bool CreateNewUser()
        {
            try
            {
                cb.connect();
                ManagedObjectReference hostLocalAccountManager =
                    cb._connection._sic.accountManager;


                ManagedObjectReference hostAuthorizationManager =
                    cb._connection._sic.authorizationManager;

                String userName = GenerateRandomString();
                String password = GenerateRandomString();

                // Create an user
                HostAccountSpec hostAccountSpec = new HostAccountSpec();
                hostAccountSpec.id          = userName;
                hostAccountSpec.password    = password;
                hostAccountSpec.description = "User Description";
                cb._connection._service.CreateUser(hostLocalAccountManager,
                                                   hostAccountSpec);

                ManagedObjectReference rootFolder =
                    cb._connection._sic.rootFolder;

                Permission per = new Permission();
                per.group     = false;
                per.principal = userName;
                per.roleId    = -1;
                per.propagate = true;
                per.entity    = rootFolder;

                cb._connection._service.SetEntityPermissions(hostAuthorizationManager,
                                                             rootFolder,
                                                             new Permission[] { per });

                ICredentialStore csObj = CredentialStoreFactory.CreateCredentialStore();
                var createUserResult   = csObj.AddPassword(GetServerName(), userName, password.ToCharArray());
                if (createUserResult)
                {
                    Console.WriteLine("Successfully created user and populate the "
                                      + "credential store");
                    return(true);
                }

                return(false);
            }
            finally
            {
                cb.disConnect();
            }
        }
Ejemplo n.º 2
0
        public bool CreateNewUser()
        {
            try
            {
                cb.connect();
                ManagedObjectReference hostLocalAccountManager =
                   cb._connection._sic.accountManager;


                ManagedObjectReference hostAuthorizationManager =
                   cb._connection._sic.authorizationManager;

                String userName = GenerateRandomString();
                String password = GenerateRandomString();

                // Create an user
                HostAccountSpec hostAccountSpec = new HostAccountSpec();
                hostAccountSpec.id = userName;
                hostAccountSpec.password = password;
                hostAccountSpec.description = "User Description";
                cb._connection._service.CreateUser(hostLocalAccountManager,
                                                           hostAccountSpec);

                ManagedObjectReference rootFolder =
                   cb._connection._sic.rootFolder;

                Permission per = new Permission();
                per.group = false;
                per.principal = userName;
                per.roleId = -1;
                per.propagate = true;
                per.entity = rootFolder;

                cb._connection._service.SetEntityPermissions(hostAuthorizationManager,
                                                                     rootFolder,
                                                                     new Permission[] { per });

                ICredentialStore csObj = CredentialStoreFactory.CreateCredentialStore();
                var createUserResult = csObj.AddPassword(GetServerName(), userName, password.ToCharArray());
                if (createUserResult)
                {
                    Console.WriteLine("Successfully created user and populate the "
                                       + "credential store");
                    return true;
                }

                return false;
            }
            finally
            {
                cb.disConnect();
            }
        }