protected void btnTest_Click(object sender, EventArgs e)
        {
            string returnValue;
            t = Token.Request_WithTenantID("http://198.61.199.47:35357/", "admin", "password", "tenant1");

            //Create User
            u = Trinity.OpenStack.User.Add("http://198.61.199.47:35357", "Bill", "Bob", "True", "123", "*****@*****.**", t.token_id);
            lblAddUsername.Text = "Username: "******"Email: " + u.email;
            lblAddEnabled.Text = "Enabled: " + u.enabled;
            //Successful Update
            Trinity.OpenStack.User.Update(t.token_id, u.id, "Billy", "*****@*****.**", "False", u.tenantid, "http://198.61.199.47:35357");
            lblUpdateUsername.Text = "Username: Billy";
            lblUpdateEmail.Text = "Email: [email protected]";
            lblUpdateEnabled.Text = "Enabled: False";
            //Invalid Admin Token
            returnValue = Trinity.OpenStack.User.Update("123", u.id, "Billy", "*****@*****.**", "False", u.tenantid, "http://198.61.199.47:35357");
            lblAdminToken.Text = returnValue;
            //Invalid User ID
            returnValue = Trinity.OpenStack.User.Update(t.token_id, "321", "Billy", "*****@*****.**", "False", u.tenantid, "http://198.61.199.47:35357");
            lblUserID.Text = returnValue;
            //Invalid TenantID
            returnValue = Trinity.OpenStack.User.Update(t.token_id, u.id, "Billy", "*****@*****.**", "False", "451", "http://198.61.199.47:35357");
            lblTenantID.Text = returnValue;
            //Invalid URL
            returnValue = Trinity.OpenStack.User.Update(t.token_id, u.id, "Billy", "*****@*****.**", "False", u.tenantid, "http://198.61.199.48:35357");
            lblURL.Text = returnValue;
            //Delete User
            string deleteRet = Trinity.OpenStack.User.Delete("http://198.61.199.47:35357", u.id, t.token_id);
            lblDeleteUser.Text = deleteRet;
        }
Beispiel #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (LoginSession.userToken != null)
         t = LoginSession.userToken;
     else
         //Response.Redirect("~/Account/Login.aspx");
         t = Token.Request_WithTenantID("http://saturn.cs.trinity.edu:5000", "admin", "trinitytu", "student");
 }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (LoginSession.userToken != null)
                t = LoginSession.userToken;
            else
                //Response.Redirect("~/Account/Login.aspx");
                t = Token.Request_WithTenantID("http://saturn.cs.trinity.edu:5000", "admin", "trinitytu", "student");

            try
            {
                rolelist = Role.List(txtbURL.Text, t.token_id);
            }
            catch (Exception x)
            {
                lstbxRoles.Items.Add(x.Message);
            }
            lstbxRoles.SelectedIndexChanged += new EventHandler(lstbxRoles_SelectedIndexChanged);
        }
Beispiel #4
0
 protected void btnTest_Click(object sender, EventArgs e)
 {
     string url = "http://198.61.199.47:35357/";
     t = Token.Request_WithTenantID(url, "admin", "password", "tenant1");
     //List Users
     lblFirstListCall.Text = Trinity.OpenStack.User.List(url, t.token_id);
     //Add Quincy1
     u = Trinity.OpenStack.User.Add(url, "Quincy1", "password", true.ToString(), "78f0f0f79cd241a2b6ade773f9ad5cf1", "*****@*****.**", t.token_id);
     lblAddQuincy.Text = u.name + " added.";
     //List Users again with Quincy1 this time
     lblSecondListCall.Text = Trinity.OpenStack.User.List(url, t.token_id);
     //Delete Quincy1
     lblDeleteQuincy.Text = Trinity.OpenStack.User.Delete(url, u.id, t.token_id);
     //List Users again without Quincy1 this time
     lblThirdListCall.Text = Trinity.OpenStack.User.List(url, t.token_id);
     //Try to call list with an invalid URL
     lblURL.Text = Trinity.OpenStack.User.List("http://198.61.199.48:35357/", t.token_id);
     //Try to call list with an invalid admin_token
     lblAdminToken.Text = Trinity.OpenStack.User.List(url, "1234");
 }
        //------------------------ Class Methods ----------------------------------------------//

        public static Token Request_NoTenant(string url, string user_name, string password)
        {
            string ret = string.Empty;
            Token _retrieved_token = new Token();

            String postData = "{\"auth\":{\"passwordCredentials\":{\"username\": \"" + user_name +
                              "\", \"password\": \"" + password + "\"}}}";
            StreamWriter requestWriter;
            try
            {
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
                webRequest.Method = "POST";
                webRequest.ServicePoint.Expect100Continue = false;
                webRequest.Timeout = 1000;

                webRequest.ContentType = "application/json";

                requestWriter = new StreamWriter(webRequest.GetRequestStream());
                requestWriter.Write(postData);
                requestWriter.Close();

                HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();
                Stream resStream = resp.GetResponseStream();
                StreamReader reader = new StreamReader(resStream);
                ret = reader.ReadToEnd();

                _retrieved_token = Token.Parse(ret);

                return _retrieved_token;


            }
            catch (Exception e)
            {

                _retrieved_token.token_error = e.ToString();
                return _retrieved_token; ;
            }
        }
        //=======================================================================================//
        //--                                 Request with tenantID                             --//
        //---------------------------------------------------------------------------------------//
        //--                                                                                   --//
        //--  Purpose : Send a Post request to the Keystone Service and recieved back a        --//
        //--            json string containing an access token                                 --//
        //--                                                                                   --//
        //--  Written By : Dr. Ed Boland                      Operating System : Windows 7     --//
        //--        Date : 9/25/2012                                  Language : VS 2012 C#    --//
        //=======================================================================================//
        public static Token Request_WithTenantID(string _url, string username, string password, string tenant)
        {
            string request_url = _url + "/v2.0/tokens";
            Token _retrieved_token = new Token();

            try
            {
                string ret = string.Empty;

                String catalogData = "{\"auth\":{\"passwordCredentials\":{\"username\": \"" + username +
                                            "\", \"password\": \"" + password + "\"},\"tenantName\":\"" + tenant + "\"}}";

                StreamWriter requestWriter;

                var webRequest = System.Net.WebRequest.Create(request_url) as HttpWebRequest;
                if (webRequest != null)
                {
                    webRequest.Method = "POST";
                    webRequest.ServicePoint.Expect100Continue = false;
                    webRequest.Timeout = 2000;

                    webRequest.ContentType = "application/json";
                    //POST the data.
                    using (requestWriter = new StreamWriter(webRequest.GetRequestStream()))
                    {
                        requestWriter.Write(catalogData);
                    }
                }

                HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();
                Stream resStream = resp.GetResponseStream();
                StreamReader reader = new StreamReader(resStream);
                ret = reader.ReadToEnd();

                _retrieved_token = Token.Parse(ret);

                return _retrieved_token;

            }
            catch (Exception e)
            {
                _retrieved_token.token_error = "Request_WithTenantID failed";
                return _retrieved_token;
            }
        }
        //=======================================================================================//
        //--                                Parse                                              --//
        //---------------------------------------------------------------------------------------//
        //--                                                                                   --//
        //--  Purpose : To extract the token from the CURL return for use in other commands.   --//
        //--                                                                                   --//
        //--                                                                                   --//
        //--  Written By : Dr. Ed Boland                      Operating System : Windows 7     --//
        //--        Date : 9/25/2012                                  Language : VS 2012 C#    --//
        //=======================================================================================//
        public static Token Parse(string string_to_parse)
        {
            Token _token = new Token();

            try
            {
                JObject oServerReturn = JObject.Parse(string_to_parse);
                String accessStr = oServerReturn["access"].ToString();

                JObject oAccess = JObject.Parse(accessStr);
                String tokenStr = oAccess["token"].ToString();
                String serviceCatalogStr = oAccess["serviceCatalog"].ToString();
                String userStr = oAccess["user"].ToString();

                JObject oToken = JObject.Parse(tokenStr);
                String strTokenExpires = oToken["expires"].ToString();
                String strTokenID = oToken["id"].ToString();

                JObject oUser = JObject.Parse(userStr);
                String strUserID = oUser["id"].ToString();
                String strUser_UserName = oUser["username"].ToString();
                String strUserName = oUser["name"].ToString();
                String strUserRoles = oUser["roles"].ToString();

                _token.token_expiration = strTokenExpires;
                _token.token_id = strTokenID;
                _token.user_id = strUserID;
                _token.user_name = strUserName;
                _token.user_roles = strUserRoles;
                _token.user_username = strUser_UserName;
                _token.token_error = "";

                /*switch (item_choice)
                {
                    case "token_expiration_date":
                        return strTokenExpires;
                    case "token_value":
                        return strTokenID;
                    case "user_name":
                        return strUserName;
                    case "user_username":
                        return strUser_UserName;
                    case "user_id":
                        return strUserID;
                    default:
                        return "Invalid Return Choice";
                }*/
                return _token;
            }
            catch
            {
                _token.token_error = "Token.Parse method failed.";
                return _token;
            }
        }
Beispiel #8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     t = Token.Request_WithTenantID("http://198.61.199.47:5000/", "admin", "password", "tenant1");
 }
        public Boolean Set_Up_Delete_Endpoints_Test(string admin_url, string admin_token, string testTenantName, string testServiceName)
        {
            Boolean ret = true;
            string admin_url2 = admin_url + "/v2.0/";

            DisposableEndpoints = new List<Endpoint>();
            string testTenantId = String.Empty;
            string testUserName = "******";
            string testUserPw = "eptu123";
            string testServiceId = String.Empty;

              try
            {
                Create_Test_Tenant(ref testTenantId, testTenantName, admin_url2, admin_token);                       //Create Tenant

                endpoint_testTenantid = testTenantId;
                try
                {
                    Create_Test_Service(ref testServiceId, testServiceName, admin_url2, admin_token);                   //Create Service

                    endpoint_testServiceid = testServiceId;
                    User u = new User();
                    try
                    {
                        u = User.Add(admin_url, testUserName, testUserPw, "true", testTenantId, "null", admin_token);

                        endpoint_testUser = u;
                        EPTestToken = Token.Request_NoTenant(admin_url, testUserName, testUserPw);
                        if (EPTestToken.token_error.Equals(String.Empty))
                        {
                            em = new List<Endpoint>();
                            em = Endpoint.List_Endpoints(admin_url, admin_token, admin_token);
                            BaseCount = em.Count;

                            try
                            {
                                for (int i = 0; i < 10; i++)
                                {
                                    Endpoint ep = Endpoint.Create_Endpoint(admin_token, admin_token, admin_url, testServiceId, "testDeleteEndpoint111213_" + i, testServiceId, admin_url + ":5000", admin_url + ":5000", testTenantId);
                                    DisposableEndpoints.Add(ep);
                                }
                            }
                            catch (Exception x)
                            {
                                Tear_Down_Delete_Endpoints_Test(admin_url, admin_token, u, testServiceId, testTenantId);
                                return false;
                            }

                            return true;
                        }
                        else
                        {
                            Tear_Down_Delete_Endpoints_Test(admin_url, admin_token, u, testServiceId, testTenantId);
                            return false;
                        }

                    }
                    catch (Exception x)
                    {
                        try
                        {
                            Tear_Down_Delete_Endpoints_Test(admin_url, admin_token, u, testServiceId, testTenantId);
                        }
                        catch
                        {

                            Delete_Test_Service(testServiceId, admin_url2, admin_token);
                            Delete_Test_Tenant(testTenantId, admin_url2, admin_token);
                        }
                        throw x;
                    }
                }
                catch (Exception x)
                {
                    Delete_Test_Tenant(testTenantId, admin_url2, admin_token);
                    throw x;
                }
            }
            catch (Exception x)
            {
                throw x;
            }
            return true;
        }
        public Boolean setUp(string admin_url, string admin_token, string testTenantName, int iterations)
        {
            try
            {
                //create test tenant
                Create_Test_Tenant(testTenantName, admin_url + "/v2.0/", admin_token);

                try
                {
                    //create test user
                    string testUserName = "******";
                    string testUserPass = "******";
                    roleTestUser = User.Add(admin_url, testUserName, testUserPass, "true", role_testTenantid, "null", admin_token);

                    roleTestToken = Token.Request_NoTenant(admin_url, roleTestUser.name, roleTestUser.password);
                    if (roleTestToken.token_error.Equals(String.Empty))
                    {
                        //initialize list of test user roles
                        disposableRoles = User.List_Roles(admin_url, roleTestUser.id, role_testTenantid, admin_token);
                        BaseCount = disposableRoles.Count;

                        try
                        {
                            for (int i = 0; i < iterations; i++)
                            {
                                Role r = Role.Add(admin_url, "UserAddRoleTest" + i, admin_token);
                                User.AddRoleToUser(admin_url, roleTestUser.id, roleTestUser.tenantid, r.id, admin_token);
                                disposableRoles.Add(r);
                            }
                        }
                        catch (Exception x)
                        {
                            tearDown(admin_url, admin_token);
                            return false;
                        }
                    }
                    else
                    {
                        tearDown(admin_url, admin_token);
                    }
                }
                catch (Exception x)
                {
                    try
                    {
                        tearDown(admin_url, admin_token);
                    }
                    catch
                    {
                        Delete_Test_Tenant(admin_url + "/v2.0/", admin_token);
                    }
                    throw x;
                }
            }
            catch (Exception x)
            {
                throw x;
            }
            return true;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                retrieved_token = Trinity.OpenStack.Token.Request_WithTenantID("http://198.61.199.47:5000", "admin", "password", "tenant1");
                Session["token_value"] = retrieved_token.token_id.ToString();
                Session["stack_url"] = "http://198.61.199.47";
                Session["tenant_id"] = "78f0f0f79cd241a2b6ade773f9ad5cf1";

                txtToken.Text = Session["token_value"].ToString();
                txtURL.Text = Session["stack_url"].ToString();
                txtTenantId.Text = Session["tenant_id"].ToString();

                Panel2.Visible = false;
                Panel3.Visible = false;
                Panel4.Visible = false;
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     t = Token.Request_WithTenantID("http://saturn.cs.trinity.edu:5000/", "admin", "trinitytu", "student");
 }