public UserAccess GetUserAccess(CloudIdentity identity, bool forceCacheRefresh = false) { if (identity == null) { identity = _defaultIdentity; } var rackspaceCloudIdentity = identity as RackspaceCloudIdentity; if (rackspaceCloudIdentity == null) { rackspaceCloudIdentity = new RackspaceCloudIdentity(identity); } var userAccess = _userAccessCache.Get(string.Format("{0}/{1}", rackspaceCloudIdentity.CloudInstance, rackspaceCloudIdentity.Username), () => { var auth = AuthRequest.FromCloudIdentity(identity); var response = ExecuteRESTRequest <AuthenticationResponse>(identity, "/v2.0/tokens", HttpMethod.POST, auth, isTokenRequest: true); if (response == null || response.Data == null || response.Data.UserAccess == null || response.Data.UserAccess.Token == null) { return(null); } return(response.Data.UserAccess); }, forceCacheRefresh); return(userAccess); }
protected void CIProviderDefaultRegion() { string CloudIdentityUserName = (string)(Session["CloudIdentityUserName"]); string CloudIdentityApiKey = (string)(Session["CloudIdentityApiKey"]); RackspaceCloudIdentity identity = new RackspaceCloudIdentity() { Username = CloudIdentityUserName, APIKey = CloudIdentityApiKey }; CloudIdentityProvider identityProvider = new net.openstack.Providers.Rackspace.CloudIdentityProvider(identity); IEnumerable <User> ListUsers = identityProvider.ListUsers(identity); IEnumerable <Tenant> ListTenants = identityProvider.ListTenants(identity); var DefaultRegion_SB = new StringBuilder(); foreach (var i in ListUsers) { DefaultRegion_SB.Append(Path.Combine(i.Username, i.DefaultRegion) + "<br />"); } Lbl_DefaultRegion.Text = DefaultRegion_SB.ToString(); Lbl_DefaultRegion.Visible = true; LblDefaultRegionPrefab.Visible = true; }
public static void Init(TestContext context) { _testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity); _testAdminIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestAdminIdentity); _testDomainIdentity = new ExtendedRackspaceCloudIdentity(Bootstrapper.Settings.TestDomainIdentity); var provider = BuildProvider(); _userDetails = provider.GetUserByName(_testIdentity.Username, _testIdentity); _adminUserDetails = provider.GetUserByName(_testAdminIdentity.Username, _testAdminIdentity); }
public static void Init(TestContext context) { _testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity); _testAdminIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestAdminIdentity); _testDomainIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestDomainIdentity); var provider = BuildProvider(); _userDetails = provider.GetUserByName(_testIdentity.Username, _testIdentity); _adminUserDetails = provider.GetUserByName(_testAdminIdentity.Username, _testAdminIdentity); }
public static void Init(TestContext context) { _testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity); var file = Path.Combine(Directory.GetCurrentDirectory(), saveFileNane1); if(File.Exists(file)) File.Delete(file); file = Path.Combine(Directory.GetCurrentDirectory(), saveFileNane2); if (File.Exists(file)) File.Delete(file); }
public static CloudBlockStorageProvider blockStorageProvider() { string CloudIdentityUserName = (string)(HttpContext.Current.Session["CloudIdentityUserName"]); string CloudIdentityApiKey = (string)(HttpContext.Current.Session["CloudIdentityApiKey"]); RackspaceCloudIdentity identity = new RackspaceCloudIdentity() { Username = CloudIdentityUserName, APIKey = CloudIdentityApiKey }; CloudBlockStorageProvider CloudBlockStorageProvider = new net.openstack.Providers.Rackspace.CloudBlockStorageProvider(identity); return(CloudBlockStorageProvider); }
protected CloudFilesProvider filesProvider() { string CloudIdentityUserName = (string)(Session["CloudIdentityUserName"]); string CloudIdentityApiKey = (string)(Session["CloudIdentityApiKey"]); RackspaceCloudIdentity identity = new RackspaceCloudIdentity() { Username = CloudIdentityUserName, APIKey = CloudIdentityApiKey }; CloudFilesProvider CloudFilesProvider = new net.openstack.Providers.Rackspace.CloudFilesProvider(identity); return(CloudFilesProvider); }
public static void Init(TestContext context) { _testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity); var file = Path.Combine(Directory.GetCurrentDirectory(), saveFileNane1); if (File.Exists(file)) { File.Delete(file); } file = Path.Combine(Directory.GetCurrentDirectory(), saveFileNane2); if (File.Exists(file)) { File.Delete(file); } }
public void Should_Throw_Error_When_Authenticating_With_Invalid_Password() { var identity = new RackspaceCloudIdentity() { Username = _testIdentity.Username, Password = "******" }; IIdentityProvider serviceProvider = new CloudIdentityProvider(identity); try { var userAccess = serviceProvider.Authenticate(); throw new Exception("This code path is invalid, exception was expected."); } catch (net.openstack.Core.Exceptions.Response.ResponseException) { Assert.IsTrue(true); } }
public void Should_Throw_Error_When_Authenticating_With_Invalid_Username() { var identity = new RackspaceCloudIdentity() { Username = "******", APIKey = "bad api key" }; IIdentityProvider serviceProvider = new CloudIdentityProvider(identity); try { var userAccess = serviceProvider.Authenticate(); throw new Exception("This code path is invalid, exception was expected."); } catch (net.openstack.Core.Exceptions.Response.ResponseException) { Assert.IsTrue(true); } }
public void Should_Throw_Error_When_Authenticating_With_Invalid_Password() { var identity = new RackspaceCloudIdentity() { Username = _testIdentity.Username, Password = "******", Domain = _testIdentity.Domain, }; IIdentityProvider serviceProvider = new CloudIdentityProvider(identity); try { var userAccess = serviceProvider.Authenticate(); throw new Exception("This code path is invalid, exception was expected."); } catch (net.openstack.Core.Exceptions.Response.ResponseException) { Assert.IsTrue(true); } }
/// <summary> /// Gets the authentication token for the specified impersonation identity. If necessary, the /// identity is authenticated on the server to obtain a token. /// </summary> /// <remarks> /// If <paramref name="forceCacheRefresh"/> is <see langword="false"/> and a cached <see cref="IdentityToken"/> /// is available for the specified <paramref name="identity"/>, this method may return the cached /// value without performing an authentication against the server. If <paramref name="forceCacheRefresh"/> /// is <see langword="true"/>, this method always authenticates the identity with the server. /// </remarks> /// <param name="identity">The identity of the user to authenticate. If this value is <see langword="null"/>, the authentication is performed with the <see cref="DefaultIdentity"/>.</param> /// <param name="forceCacheRefresh">If <see langword="true"/>, the user is always authenticated against the server; otherwise a cached <see cref="IdentityToken"/> may be returned.</param> /// <returns>The user's authentication token.</returns> /// <exception cref="ArgumentNullException">If <paramref name="identity"/> is <see langword="null"/>.</exception> /// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception> /// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <see langword="null"/> and no default identity is available for the provider.</exception> /// <exception cref="ResponseException">If the authentication request failed.</exception> protected virtual UserAccess Impersonate(RackspaceImpersonationIdentity identity, bool forceCacheRefresh) { if (identity == null) { throw new ArgumentNullException("identity"); } var impToken = TokenCache.Get(string.Format("{0}:{1}/imp/{2}/{3}", UrlBase, identity.Username, identity.UserToImpersonate.Domain == null ? "none" : identity.UserToImpersonate.Domain.Name, identity.UserToImpersonate.Username), () => { const string urlPath = "/v2.0/RAX-AUTH/impersonation-tokens"; var request = BuildImpersonationRequestJson(identity.UserToImpersonate.Username, 600); var parentIdentity = new RackspaceCloudIdentity(identity); var response = ExecuteRESTRequest <UserImpersonationResponse>(parentIdentity, new Uri(UrlBase, urlPath), HttpMethod.POST, request); if (response == null || response.Data == null || response.Data.UserAccess == null) { return(null); } IdentityToken impersonationToken = response.Data.UserAccess.Token; if (impersonationToken == null) { return(null); } var userAccess = ValidateToken(impersonationToken.Id, identity: parentIdentity); if (userAccess == null) { return(null); } var endpoints = ListEndpoints(impersonationToken.Id, parentIdentity); var serviceCatalog = BuildServiceCatalog(endpoints); return(new UserAccess(userAccess.Token, userAccess.User, serviceCatalog)); }, forceCacheRefresh); return(impToken); }
/// <inheritdoc/> public virtual UserAccess GetUserAccess(CloudIdentity identity, bool forceCacheRefresh = false) { CheckIdentity(identity); if (identity == null) { identity = DefaultIdentity; } if (identity is RackspaceImpersonationIdentity) { return(Impersonate(identity as RackspaceImpersonationIdentity, forceCacheRefresh)); } var rackspaceCloudIdentity = identity as RackspaceCloudIdentity; if (rackspaceCloudIdentity == null) { rackspaceCloudIdentity = new RackspaceCloudIdentity(identity); } var userAccess = TokenCache.Get(string.Format("{0}:{1}/{2}", UrlBase, rackspaceCloudIdentity.Domain, rackspaceCloudIdentity.Username), () => { var auth = new AuthRequest(identity); var response = ExecuteRESTRequest <AuthenticationResponse>(identity, new Uri(UrlBase, "/v2.0/tokens"), HttpMethod.POST, auth, isTokenRequest: true); if (response == null || response.Data == null || response.Data.UserAccess == null || response.Data.UserAccess.Token == null) { return(null); } return(response.Data.UserAccess); }, forceCacheRefresh); return(userAccess); }
protected void CILogin_Click(object sender, EventArgs e) { string CloudIdentityUserName = CIUsernameText.Text; string CloudIdentityApiKey = CIApiKeyText.Text; try { RackspaceCloudIdentity identity = new RackspaceCloudIdentity() { Username = CloudIdentityUserName, APIKey = CloudIdentityApiKey }; CloudIdentityProvider identityProvider = new net.openstack.Providers.Rackspace.CloudIdentityProvider(identity); var userAccess = Identity.identityProvider().Authenticate(identity); if (userAccess.User != null) { Session["CloudIdentityUserName"] = CIUsernameText.Text; Session["CloudIdentityApiKey"] = CIApiKeyText.Text; CIUsernameText.Text = string.Empty; CIApiKeyText.Text = string.Empty; Response.Redirect(Request.RawUrl); } else { LblInfo.Text = "Username or Password is Incorrect. Please try again."; } } catch (Exception ex) { MessageCatchException("Username or Password is Incorrect. Please try again."); } }
public static void Init(TestContext context) { _testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity); }
public static void Main(string[] args) { Boolean containerExists = false; if (args.Length < 4 || args.Length > 5) { Console.WriteLine("Usage: {0} username api_key target_container path_to_file [region (US|UK)]", Environment.CommandLine); Environment.Exit(1); } RackspaceCloudIdentity auth = new RackspaceCloudIdentity(); IEnumerable <Container> containerList = null; auth.Username = args[0]; auth.APIKey = args[1]; targetContainer = args[2]; filePath = args[3]; if (args.Length == 5) { if (args[4] != "UK" && args[4] != "US") { Console.WriteLine("region must be either US or UK", Environment.CommandLine); Environment.Exit(1); } switch (args[4]) { case "UK": { auth.CloudInstance = CloudInstance.UK; }; break; case "US": { auth.CloudInstance = CloudInstance.Default; }; break; } } try { IIdentityProvider identityProvider = new CloudIdentityProvider(); var userAccess = identityProvider.Authenticate(auth); } catch (ResponseException ex2) { Console.WriteLine("Authentication failed with the following message: {0}", ex2.Message); Environment.Exit(1); } try { var cloudFilesProvider = new CloudFilesProvider(auth); containerList = cloudFilesProvider.ListContainers(); foreach (Container container in containerList) { if (container.Name == targetContainer) { containerExists = true; break; } } if (!containerExists) { Console.WriteLine("Container \"{0}\" does not exist on the provided CloudFiles account.", targetContainer); Environment.Exit(1); } if (!File.Exists(filePath)) { Console.WriteLine("The file specified ({0}) does not exist", filePath); Environment.Exit(1); } cloudFilesProvider.CreateObjectFromFile(targetContainer, @filePath, Path.GetFileName(filePath)); } catch (Exception ex2) { Console.WriteLine(ex2.Message); Environment.Exit(1); } Console.WriteLine("*SUCCESS* File: \"{0}\" uploaded to \"{1}\"", filePath, targetContainer); }