/// <summary> /// Enables forms authentication for a module /// </summary> /// <param name="module">Module to add handlers to (usually "this")</param> /// <param name="configuration">Forms authentication configuration</param> public static void Enable(INancyModule module, FormsAuthenticationConfiguration configuration) { if (module == null) { throw new ArgumentNullException("module"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } configuration.EnsureConfigurationIsValid(); module.RequiresAuthentication(); currentConfiguration = configuration; module.Before.AddItemToStartOfPipeline(GetLoadAuthenticationHook(configuration)); if (!configuration.DisableRedirect) { module.After.AddItemToEndOfPipeline(GetRedirectToLoginHook(configuration)); } }
public dynamic Execute(dynamic parameters, INancyModule module) { module.RequiresAuthentication(); int page = int.Parse(module.Request.Query["page"]); int pageSize = int.Parse(module.Request.Query["pageSize"]); int totalResults; List <IFeed> feeds; using (ITransaction transaction = _store.BeginTransaction()) { feeds = transaction.Query <IFeed>().ToList(pageSize * page, pageSize, out totalResults); } feeds.Where(fd => !string.IsNullOrWhiteSpace(fd.ApiKeyHashed)).ToList().ForEach(fd => fd.HasApiKey = true); feeds.ForEach(fd => fd.ApiKeyHashed = null); //Temporary until API Key table is used feeds.ForEach(fd => fd.ApiKeySalt = null); //Temporary until API Key table is used var totalPages = (int)Math.Ceiling((double)totalResults / pageSize); return(new { TotalCount = totalResults, TotalPages = totalPages, Results = feeds }); }
/// <summary> /// Enables forms authentication for a module /// </summary> /// <param name="module">Module to add handlers to (usually "this")</param> /// <param name="configuration">Forms authentication configuration</param> public static void Enable(INancyModule module, FormsAuthenticationConfiguration configuration) { if (module == null) { throw new ArgumentNullException("module"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } configuration.EnsureConfigurationIsValid(); module.RequiresAuthentication(); currentConfiguration = configuration; module.Before.AddItemToStartOfPipeline(GetLoadAuthenticationHook(configuration)); if (!configuration.DisableRedirect) { module.After.AddItemToEndOfPipeline(GetRedirectToLoginHook(configuration)); } }
public dynamic Execute(dynamic parameters, INancyModule module) { module.RequiresAuthentication(); FeedSearchResponse response = new FeedSearchResponse(); using (ITransaction transaction = _store.BeginTransaction()) { string name = module.Request.Query.name; int totalResults; var feeds = transaction.Query <IFeed>().Where("Name like @feedName").Parameter("feedName", "%" + name + "%").ToList(0, 10, out totalResults); var category = new FeedSearchResponse.Category("Default"); response.Results.Add(category); string rootUrl = module.Request.Url.SiteBase + "/#feeds/view/{0}"; foreach (var feed in feeds) { category.Feeds.Add(new FeedSearchResponse.Category.FeedResult(feed.Name, string.Format(rootUrl, feed.Id))); } } return(response); }
public static void Enable(INancyModule module) { if (module == null) { throw new ArgumentNullException("module"); } module.RequiresAuthentication(); module.Before.AddItemToStartOfPipeline(GetCredentialRetrievalHook()); }
public static void Enable(INancyModule module) { if (module == null) { throw new ArgumentNullException("module"); } module.RequiresAuthentication(); module.Before.AddItemToStartOfPipeline(GetCredentialRetrievalHook()); }
public dynamic Execute(dynamic parameters, INancyModule module) { module.RequiresAuthentication(); using (ITransaction transaction = _store.BeginTransaction()) { var model = new SystemInformationStatistic(transaction).GetModel(); return(model); } }
public dynamic Execute(dynamic parameters, INancyModule module) { module.RequiresAuthentication(); IFeed feed; try { int feedId = int.Parse(parameters.id); feed = module.Bind <Feed>(); if (feedId != feed.Id) { return(HttpStatusCode.BadRequest); } ITransaction transaction = _store.BeginTransaction(); var existingFeedExists = transaction.Query <IFeed>().Where("Id = @feedId").Parameter("feedId", feedId).First(); if (existingFeedExists == null) { return(HttpStatusCode.NotFound); } if (!string.IsNullOrWhiteSpace(feed.ApiKey)) { ICryptoService cryptoService = new PBKDF2(); feed.ApiKeySalt = cryptoService.GenerateSalt(); feed.ApiKeyHashed = cryptoService.Compute(feed.ApiKey); } else if (feed.HasApiKey) { feed.ApiKeyHashed = existingFeedExists.ApiKeyHashed; //Temporary until API Key table is used feed.ApiKeySalt = existingFeedExists.ApiKeySalt; //Temporary until API Key table is used } transaction.Update(feed); transaction.Commit(); transaction.Dispose(); } catch (Exception ex) { return(HttpStatusCode.InternalServerError); } return(feed); }
/// <summary> /// Enables basic authentication for a module /// </summary> /// <param name="module">Module to add handlers to (usually "this")</param> /// <param name="configuration">Forms authentication configuration</param> public static void Enable(INancyModule module, BasicAuthenticationConfiguration configuration) { if (module == null) { throw new ArgumentNullException("module"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } module.RequiresAuthentication(); module.Before.AddItemToStartOfPipeline(GetCredentialRetrievalHook(configuration)); module.After.AddItemToEndOfPipeline(GetAuthenticationPromptHook(configuration)); }
/// <summary> /// Enables basic authentication for a module /// </summary> /// <param name="module">Module to add handlers to (usually "this")</param> /// <param name="configuration">Forms authentication configuration</param> public static void Enable(INancyModule module, BasicAuthenticationConfiguration configuration) { if (module == null) { throw new ArgumentNullException("module"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } module.RequiresAuthentication(); module.Before.AddItemToStartOfPipeline(GetCredentialRetrievalHook(configuration)); module.After.AddItemToEndOfPipeline(GetAuthenticationPromptHook(configuration)); }
public dynamic Execute(dynamic parameters, INancyModule module) { module.RequiresAuthentication(); IFeedConfiguration feedConfig; try { int feedId = int.Parse(parameters.id); feedConfig = module.Bind <FeedConfiguration>(); if (feedId != feedConfig.FeedId) { return(HttpStatusCode.BadRequest); } ITransaction transaction = _store.BeginTransaction(); var existingFeedExists = transaction.Query <IFeedConfiguration>().Where("FeedId = @feedId").Parameter("feedId", feedId).Count() > 0; if (!existingFeedExists) { return(HttpStatusCode.NotFound); } transaction.Update(feedConfig); transaction.Commit(); transaction.Dispose(); } catch (Exception ex) { return(HttpStatusCode.InternalServerError); } return(feedConfig); }
/// <summary>Enables forms authentication for a module</summary> /// <param name="module">Module to add handlers to (usually "this")</param> /// <param name="configuration">Forms authentication configuration</param> public static void Enable(INancyModule module, CustomAuthenticationConfiguration configuration) { if (module == null) { throw new ArgumentNullException("module"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } if (!configuration.IsValid) { throw new ArgumentException("Configuration is invalid", "configuration"); } module.RequiresAuthentication(); CustomAuthenticationProvider.currentConfiguration = configuration; module.Before.AddItemToStartOfPipeline(CustomAuthenticationProvider.GetLoadAuthenticationHook(configuration)); if (configuration.DisableRedirect) { return; } module.After.AddItemToEndOfPipeline(CustomAuthenticationProvider.GetRedirectToLoginHook(configuration)); }
public dynamic Execute(dynamic parameters, INancyModule module) { module.RequiresAuthentication(); using (ITransaction transaction = _store.BeginTransaction()) { int feedId = int.Parse(parameters.id); var feed = transaction.Query <IFeed>().Where("Id = @feedId").Parameter("feedId", feedId).First(); if (feed != null) { //Temporary until the API Key table is used if (!string.IsNullOrWhiteSpace(feed.ApiKeyHashed)) { feed.HasApiKey = true; } feed.ApiKeyHashed = null; //We don't want to expose this to the front end feed.ApiKeySalt = null; //We don't want to expose this to the front end } return(feed); } }
public dynamic Execute(dynamic parameters, INancyModule module) { var file = module.Request.Files.FirstOrDefault(); string feedName = parameters.feed; if (file == null) { var response = module.Response.AsText("Must provide package with valid id and version."); response.StatusCode = HttpStatusCode.BadRequest; return(response); } int feedId; IFeed feed; using (ITransaction transaction = Store.BeginTransaction()) { feed = transaction.Query <IFeed>().Where("Name = @feedName").Parameter("feedName", feedName).First(); if (feed == null) { var response = module.Response.AsText("Feed does not exist."); response.StatusCode = HttpStatusCode.BadRequest; return(response); } feedId = feed.Id; } if (RequiresApiKeyCheck(feed)) { if (!IsValidNuGetApiKey(module, feed)) { if (module.Request.Headers["Authorization"].FirstOrDefault() != null) { module.RequiresAuthentication(); } else { var response = module.Response.AsText("Invalid API key."); response.StatusCode = HttpStatusCode.Forbidden; return(response); } } } string temporaryFilePath; using (var stream = _fileSystem.CreateTemporaryFile(".nupkg", out temporaryFilePath)) { file.Value.CopyTo(stream); } try { IPackage package = FastZipPackage.Open(temporaryFilePath, new CryptoHashProvider()); if (string.IsNullOrWhiteSpace(package.Id) || package.Version == null) { var response = module.Response.AsText("Must provide package with valid id and version."); response.StatusCode = HttpStatusCode.BadRequest; return(response); } IInternalPackageRepository packageRepository = _packageRepositoryFactory.Create(feedId); var existingPackage = packageRepository.GetPackage(package.Id, package.Version); if (existingPackage != null) { var response = module.Response.AsText("A package with the same ID and version already exists. Overwriting packages is not enabled on this feed."); response.StatusCode = HttpStatusCode.Conflict; return(response); } IInternalPackage latestAbsoluteVersionPackage; IInternalPackage latestVersionPackage; GetCurrentLatestVersionPackages(feedId, package.Id, packageRepository, out latestAbsoluteVersionPackage, out latestVersionPackage); bool isUploadedPackageAbsoluteLatestVersion = true; bool isUploadedPackageLatestVersion = true; if (latestAbsoluteVersionPackage != null) { if (package.Version.CompareTo(latestAbsoluteVersionPackage.GetSemanticVersion()) <= 0) { isUploadedPackageAbsoluteLatestVersion = false; } } if (latestVersionPackage != null) { if (package.Version.CompareTo(latestVersionPackage.GetSemanticVersion()) <= 0) { isUploadedPackageLatestVersion = false; } else { if (!package.IsReleaseVersion()) { isUploadedPackageLatestVersion = false; } } } else { if (!package.IsReleaseVersion()) { isUploadedPackageLatestVersion = false; } } if (isUploadedPackageAbsoluteLatestVersion && latestAbsoluteVersionPackage != null) { latestAbsoluteVersionPackage.IsAbsoluteLatestVersion = false; using (ITransaction transaction = Store.BeginTransaction()) { transaction.Update(latestAbsoluteVersionPackage); transaction.Commit(); } } if (isUploadedPackageLatestVersion && latestVersionPackage != null) { latestVersionPackage.IsLatestVersion = false; using (ITransaction transaction = Store.BeginTransaction()) { transaction.Update(latestVersionPackage); transaction.Commit(); } } packageRepository.AddPackage(package, isUploadedPackageAbsoluteLatestVersion, isUploadedPackageLatestVersion); } finally { if (File.Exists(temporaryFilePath)) { _fileSystem.DeleteFile(temporaryFilePath); } } return(new Response { StatusCode = HttpStatusCode.Created }); }
public dynamic Execute(dynamic parameters, INancyModule module) { module.RequiresAuthentication(); int feedId = int.Parse(parameters.id); IFeed feed; IFeedConfiguration config; List <IInternalPackage> packages; using (ITransaction transaction = _store.BeginTransaction()) { feed = transaction.Query <IFeed>() .Where("Id = @feedId") .Parameter("feedId", feedId) .First(); } if (feed == null) { return(HttpStatusCode.NotFound); } using (ITransaction transaction = _store.BeginTransaction()) { config = transaction.Query <IFeedConfiguration>() .Where("FeedId = @feedId") .Parameter("feedId", feedId) .First(); } using (ITransaction transaction = _store.BeginTransaction()) { packages = transaction.Query <IInternalPackage>() .Where("FeedId = @feedId") .Parameter("feedId", feedId) .ToList(); } string packageDirectory = config.PackagesDirectory; using (ITransaction transaction = _store.BeginTransaction()) { foreach (var package in packages) { transaction.Delete(package); } transaction.Delete(feed); transaction.Delete(config); transaction.Commit(); } if (Directory.Exists(packageDirectory)) { try { Directory.Delete(packageDirectory); } catch (Exception ex) { } } return(module.Response.AsJson(new object())); }
public dynamic Execute(dynamic parameters, INancyModule module) { module.RequiresAuthentication(); IFeed feed; try { feed = module.Bind <Feed>(); ITransaction transaction = _store.BeginTransaction(); var existingFeedExists = transaction.Query <IFeed>().Where("Name = @feedName").Parameter("feedName", feed.Name).Count() > 0; if (existingFeedExists) { return(HttpStatusCode.Conflict); } if (!string.IsNullOrWhiteSpace(feed.ApiKey)) { ICryptoService cryptoService = new PBKDF2(); feed.ApiKeySalt = cryptoService.GenerateSalt(); feed.ApiKeyHashed = cryptoService.Compute(feed.ApiKey); } transaction.Insert(feed); transaction.Commit(); transaction.Dispose(); transaction = _store.BeginTransaction(); feed = transaction.Query <IFeed>() .Where("Name = @feedName") .Parameter("feedName", feed.Name) .First(); var appFolder = _home.InstallDirectory; var feedFolder = Path.Combine(appFolder, "Feeds", feed.Id.ToString()); IFeedConfiguration config = new FeedConfiguration { FeedId = feed.Id, PackagesDirectory = feedFolder }; transaction.Insert(config); transaction.Commit(); transaction.Dispose(); } catch (Exception ex) { return(HttpStatusCode.InternalServerError); } feed.ApiKeyHashed = null; //Temporary until API Key table is used feed.ApiKeySalt = null; //Temporary until API Key table is used return(feed); }