예제 #1
0
        public AuthorizeRolesAttribute(UiConfigurationContext config)
        {
            if (config == null)
            {
                config = UiConfigurationContext.Current;
            }

            Roles      = string.Join(",", config.AuthorizedAdminRoles.Concat(config.AuthorizedEditorRoles).Distinct());
            IsReusable = false;
        }
예제 #2
0
        /// <summary>
        /// Use this method if you want to add AdminUI component to your application. This is just a part of the setup. You will also need to mount the
        /// component. Use other method (will leave it up to you to figure out which).
        /// </summary>
        /// <param name="services">Collection of the services (Microsoft approach for DI).</param>
        /// <param name="setup">UI setup context will be passed in, so you can do some customization on that object to influence how AdminUI behaves.</param>
        /// <returns>The same service collection - so you can do chaining.</returns>
        public static IServiceCollection AddDbLocalizationProviderAdminUI(
            this IServiceCollection services,
            Action <UiConfigurationContext> setup = null)
        {
            var context = new UiConfigurationContext();

            setup?.Invoke(context);

            services.AddSingleton(_ => context);

            // this is required for dynamic endpoint routing (if one is used in the app)
            services.AddSingleton <AdminUIDynamicRouteValueTransformer>();

            // add support for admin ui razor class library pages
            services.Configure <RazorPagesOptions>(_ =>
            {
                _.Conventions.AuthorizeAreaPage("4D5A2189D188417485BF6C70546D34A1", "/AdminUI", AccessPolicy.Name);
                _.Conventions.AddAreaPageRoute("4D5A2189D188417485BF6C70546D34A1", "/AdminUI", context.RootUrl);

                _.Conventions.AuthorizeAreaPage("4D5A2189D188417485BF6C70546D34A1", "/AdminUITree", AccessPolicy.Name);
                _.Conventions.AddAreaPageRoute("4D5A2189D188417485BF6C70546D34A1", "/AdminUITree", context.RootUrl + "/tree");
            });

            if (context.AccessPolicyOptions != null)
            {
                services.AddAuthorization(options =>
                {
                    options.AddPolicy(AccessPolicy.Name, context.AccessPolicyOptions);
                });
            }
            else
            {
                services.AddAuthorization(options =>
                {
                    options.AddPolicy(AccessPolicy.Name,
                                      policy => policy.AddRequirements(new CheckAdministratorsRoleRequirement()));
                });
            }

            return(services);
        }
 public ServiceController(UiConfigurationContext config)
 {
     _config = config;
 }
예제 #4
0
 public ServiceController(UiConfigurationContext config, ICommandExecutor commandExecutor, IQueryExecutor queryExecutor)
 {
     _config          = config;
     _commandExecutor = commandExecutor ?? throw new ArgumentNullException(nameof(commandExecutor));
     _queryExecutor   = queryExecutor ?? throw new ArgumentNullException(nameof(queryExecutor));
 }