Esempio n. 1
0
        private void RegisterIRelationshipsAuthorizationContextDataProviders(IWindsorContainer container)
        {
            // Register all context data providers
            var relationshipContextDataProviderTypes = _assembliesProvider.GetAssemblies()
                                                       .Where(a => a.IsExtensionAssembly() || a.IsStandardAssembly())
                                                       .SelectMany(a =>
            {
                _logger.Info(
                    $"Processing assembly '{a.GetName().Name}' for relationship-based authorization context data providers.");

                var contextDataProviderTypes = a.GetTypes()
                                               .Where(t => !t.IsAbstract &&
                                                      typeof(IRelationshipsAuthorizationContextDataProvider <,>).IsAssignableFromGeneric(t))
                                               .ToArray();

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug($@"Found {contextDataProviderTypes.Count()} types:
    {string.Join(Environment.NewLine + "    ", contextDataProviderTypes.Select(t => t.FullName))}");
                }
                else
                {
                    _logger.Info($"Found {contextDataProviderTypes.Count()} types.");
                }

                return(contextDataProviderTypes);
            })
                                                       .ToList();

            // Register all context data providers including any defined in extension assemblies.
            // NOTE: If there is no entries for relationshipContextDataProviderTypes this means that the EdFi.Ods.Standard.Security assembly is not loaded.
            // and this can be resolved by calling AssemblyLoader.EnsureLoaded<Marker_EdFi_Ods_Standard_Security>(); in your configuration
            if (!relationshipContextDataProviderTypes.Any())
            {
                throw new ConfigurationErrorsException(
                          "Unable to find any relationship-based authorization context providers dynamically.");
            }

            foreach (var providerType in relationshipContextDataProviderTypes)
            {
                var partiallyClosedInterfaceType =
                    providerType.GetInterfaces()
                    .SingleOrDefault(i => i.Name == typeof(IRelationshipsAuthorizationContextDataProvider <,>).Name);

                var modelType = partiallyClosedInterfaceType?.GetGenericArguments()[0];

                var closedInterfaceType =
                    typeof(IRelationshipsAuthorizationContextDataProvider <,>)
                    .MakeGenericType(modelType, GetRelationshipBasedAuthorizationStrategyContextDataType());

                var closedServiceType =
                    providerType
                    .MakeGenericType(GetRelationshipBasedAuthorizationStrategyContextDataType());

                container.Register(
                    Component.For(closedInterfaceType)
                    .ImplementedBy(closedServiceType));
            }
        }
        private IDictionary <string, XsdFileInformation> ParseAssemblies()
        {
            var assemblies = _assembliesProvider.GetAssemblies()
                             .Where(x => !x.IsDynamic)
                             .ToList();

            var assemblySchemaInformationByUriSegment =
                new Dictionary <string, XsdFileInformation>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var assembly in assemblies)
            {
                string[] manifestResourceNames = assembly.GetManifestResourceNames();
                string   assemblyName          = assembly.GetName().Name;

                _logger.Debug($"Checking assembly '{assemblyName}'");

                string apiModelFileName          = $"{assemblyName}.Artifacts.Metadata.ApiModel.json";
                string extensionApiModelFileName = $"{assemblyName}.Artifacts.Metadata.ApiModel-EXTENSION.json";

                if (!manifestResourceNames.Any(
                        x => x.ContainsIgnoreCase(apiModelFileName) || x.ContainsIgnoreCase(extensionApiModelFileName)))
                {
                    continue;
                }

                _logger.Debug($"Assembly '{assemblyName} has an 'ApiModel.json'");

                var stream = manifestResourceNames.Any(x => x.ContainsIgnoreCase(apiModelFileName))
                    ? new StreamReader(assembly.GetManifestResourceStream(apiModelFileName))
                    : new StreamReader(assembly.GetManifestResourceStream(extensionApiModelFileName));

                var apiModel = JsonConvert.DeserializeObject <Dictionary <string, object> >(stream.ReadToEnd());

                var schemaInfo = apiModel["schemaDefinition"].ToDictionary();

                var assemblySchemaInformation = new XsdFileInformation(
                    assemblyName,
                    schemaInfo["version"].ToString(),
                    _schemaNameMapProvider.GetSchemaMapByLogicalName(schemaInfo["logicalName"].ToString()),
                    manifestResourceNames
                    .Where(x => x.StartsWithIgnoreCase($"{assemblyName}.Artifacts.Schemas"))
                    .Select(x => x.Replace($"{assemblyName}.Artifacts.Schemas.", string.Empty))
                    .ToArray()
                    );

                _logger.Debug(assemblySchemaInformation);

                assemblySchemaInformationByUriSegment.Add(
                    assemblySchemaInformation.SchemaNameMap.UriSegment, assemblySchemaInformation);
            }

            return(assemblySchemaInformationByUriSegment);
        }
Esempio n. 3
0
        public CoreApiInstaller(IAssembliesProvider assembliesProvider, IApiConfigurationProvider apiConfigurationProvider, IConfigValueProvider configValueProvider)
        {
            Preconditions.ThrowIfNull(assembliesProvider, nameof(assembliesProvider));
            _apiConfigurationProvider = Preconditions.ThrowIfNull(apiConfigurationProvider, nameof(apiConfigurationProvider));
            _configValueProvider      = Preconditions.ThrowIfNull(configValueProvider, nameof(configValueProvider));

            var installedAssemblies = assembliesProvider.GetAssemblies().ToList();

            _standardAssembly = installedAssemblies.SingleOrDefault(x => x.IsStandardAssembly());

            // TODO JSM - remove the calls using this once we move to the api assembly in ODS-2152. This makes it easy to find the specific locations in the file for now
            _apiAssembly = installedAssemblies.SingleOrDefault(x => x.GetName().Name.Equals("EdFi.Ods.Api"));
        }
Esempio n. 4
0
        private void RegisterProfileAssemblyControllers(IWindsorContainer container)
        {
            var profileAssemblies = _assembliesProvider.GetAssemblies()
                                    .Where(EdFiConventions.IsProfileAssembly)
                                    .ToList();

            foreach (Assembly profileAssembly in profileAssemblies)
            {
                container.Register(
                    Classes
                    .FromAssembly(profileAssembly)
                    .BasedOn <ApiController>()
                    .LifestyleScoped());
            }
        }
Esempio n. 5
0
        public IEnumerable <Type> FindClassesOfType(Type type)
        {
            var result = new List <Type>();

            foreach (var t in _assembliesProvider.GetAssemblies().SelectMany(assembly => assembly.GetExportedTypes()))
            {
                var typeInfo = t.GetTypeInfo();
                if (type.IsAssignableFrom(t) && typeInfo.IsClass)
                {
                    if (!typeInfo.IsInterface && !typeInfo.IsAbstract)
                    {
                        yield return(t);
                    }
                }
            }
        }
Esempio n. 6
0
            protected override void Arrange()
            {
                _systemUnderTest = new WindsorContainerEx();

                _assemblyProvider = Stub <IAssembliesProvider>();

                A.CallTo(() => _assemblyProvider.GetAssemblies())
                .Returns(
                    new []
                {
                    // Possible assembly from a nuget
                    Assembly.GetAssembly(typeof(IWindsorContainer)),

                    // Profile Assembly we are looking for.
                    Assembly.GetAssembly(typeof(Marker_EdFi_Ods_Profiles_Test)),

                    // EdFi.Ods.Common
                    Assembly.GetAssembly(typeof(IMappable))
                });
            }
        public EdFiExtensionsInstaller(IAssembliesProvider assembliesProvider, IEntityExtensionRegistrar registrar)
        {
            _registrar = registrar;

            Assemblies = assembliesProvider.GetAssemblies();
        }