Exemplo n.º 1
0
        public static void FeedComboBox(ComboBox c)
        {
            DataSet dataset = Permission.All();

            c.DataSource    = dataset.Tables[0];
            c.ValueMember   = "permission_id";
            c.DisplayMember = "permission_name";
        }
Exemplo n.º 2
0
 public void CheckMethodPermissions_5()
 {
     impersonate(new IDPasswordCredentials("user1", "thejake"));
     m_App.Authorize(Permission.All(
                         new TeztPermissionA(1),
                         new TeztPermissionB(1),//user1 does not have this one,
                         new TeztPermissionC(1)
                         ));
 }
Exemplo n.º 3
0
        public static void FeedComboBoxForEdit(ComboBox c, string permission_name)
        {
            DataSet dataset = Permission.All();

            c.DataSource    = dataset.Tables[0];
            c.ValueMember   = "permission_id";
            c.DisplayMember = "permission_name";
            int index = c.FindString(permission_name);

            c.SelectedIndex = index;
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(config =>
            {
                config.ModelBinderProviders.Insert(0, new Piranha.Manager.Binders.AbstractModelBinderProvider());
            });

            var defaultConnection = Configuration["ConnectionStrings:DefaultConnection"];

            services.AddDbContext <Db>(options => options.UseSqlServer(defaultConnection));

            // Add application services.
            services.AddSingleton <IStorage, FileStorage>();
            services.AddScoped <IDb, Db>();
            services.AddScoped <IApi, Api>();

            services.AddPiranhaManager();

            // Add addtional all available claims
            List <string[]> additionalClaims = new List <string[]>()
            {
                Piranha.Manager.Permission.All()
            };

            // Add Identity Security EF
            services.AddEfIdentitySecurity(o =>
            {
                o.ConnectionString = defaultConnection;
                o.InitialClaims    = additionalClaims;
                o.Users            = new[]
                {
                    new Piranha.AspNetCore.Identity.EF.Data.EfIdentityUser(true, Permission.All())
                    {
                        UserName  = "******",
                        Password  = "******",
                        FirstName = "Admin",
                        LastName  = "User",
                    }
                };
                o.EnableFirstLastNameClaim = true;
            });

            // Add Identity Security EF Manager
            services.AddEfIdentityManager();

            return(services.BuildServiceProvider());
        }
Exemplo n.º 5
0
    /// <summary>
    /// Adds the Piranha manager module.
    /// </summary>
    /// <param name="services">The current service collection</param>
    /// <param name="configurePolicy">The delegate that will be used to build the Piranha Manager named policies.</param>
    /// <returns>The services</returns>
    public static IServiceCollection AddPiranhaManager(this IServiceCollection services, Action <string, AuthorizationPolicyBuilder> configurePolicy)
    {
        // Add the manager module
        Piranha.App.Modules.Register <Piranha.Manager.Module>();

        // Add the manager services
        services.AddScoped <AliasService>();
        services.AddScoped <CommentService>();
        services.AddScoped <ConfigService>();
        services.AddScoped <ContentService>();
        services.AddScoped <ContentTypeService>();
        services.AddScoped <LanguageService>();
        services.AddScoped <MediaService>();
        services.AddScoped <ModuleService>();
        services.AddScoped <PageService>();
        services.AddScoped <PostService>();
        services.AddScoped <SiteService>();

        // Add localization service
        services.AddScoped <ManagerLocalizer>();

        // Add session support
        services.AddSession();

        // Add SignalR
        services.AddSignalR();

        // Setup authorization policies
        services.AddAuthorization(o =>
        {
            if (configurePolicy is not null)
            {
                //If custom AuthorizationOptions delegate is provided, invoke
                foreach (var permission in Permission.All())
                {
                    o.AddPolicy(permission, configure => configurePolicy.Invoke(permission, configure));
                }
            }
            else
            {
                //Else configure default Claims based Policies, using Piranha nested permissions structure
                //Add root (Admin) policy and Claims
                o.AddPolicy(Permission.PermissionsStructure.PermissionName, configure => { configure.RequireClaim(Permission.PermissionsStructure.PermissionName, Permission.PermissionsStructure.PermissionName); });

                foreach (var level1Permission in Permission.PermissionsStructure.ChildPermissions)
                {
                    //Add 1 level deep nested level policy and Claims
                    o.AddPolicy(level1Permission.PermissionName, configure =>
                    {
                        configure.RequireClaim(Permission.PermissionsStructure.PermissionName, Permission.PermissionsStructure.PermissionName);
                        configure.RequireClaim(level1Permission.PermissionName, level1Permission.PermissionName);
                    });

                    //Add 2 levels deep policy and Claims
                    foreach (var level2Permission in level1Permission.ChildPermissions)
                    {
                        o.AddPolicy(level2Permission.PermissionName, configure =>
                        {
                            configure.RequireClaim(Permission.PermissionsStructure.PermissionName, Permission.PermissionsStructure.PermissionName);
                            configure.RequireClaim(level1Permission.PermissionName, level1Permission.PermissionName);
                            configure.RequireClaim(level2Permission.PermissionName, level2Permission.PermissionName);
                        });
                    }
                }
            }
        });

        // Return the service collection
        return(services);
    }