Exemplo n.º 1
0
        internal static void SetDefaults(FreshlyOptions D)
        {
            var AG = new ApplicationGroupsFactory();
            var AP = new ApplicationPoliciesFactory();
            var UG = new UserGroupsFactory();
            var GP = new GroupPoliciesFactory();
            var AU = new UserHelpers();

            var gs         = D?.Groups;
            var ps         = D?.Policies;
            var AdminGroup = "Administrator";

            (new DatabaseInitializer()).SetupDB();

            try { AG.AddGroup(AdminGroup); } catch (Exception ex) { };
            try {
                if (D?.DefaultUser != null)
                {
                    D.DefaultUser.CurrentStatus = AccountStatus.Active;
                    AU.CreateUser(D.DefaultUser, D.DefaultUser.Password);
                    UG.AddUserToGroup(D.DefaultUser.UserId, AdminGroup);
                }
            } catch (Exception ex) { }

            try { if (gs != null)
                  {
                      foreach (var s in gs)
                      {
                          if (!string.IsNullOrEmpty(s))
                          {
                              AG.AddGroup(s);
                          }
                      }
                  }
            } catch (Exception ex) { }
            try { if (ps != null)
                  {
                      foreach (var s in ps)
                      {
                          if (!string.IsNullOrEmpty(s))
                          {
                              AP.AddAccessPolicy(s); GP.AddGroupPolicy(AdminGroup, s);
                          }
                      }
                  }
            } catch (Exception ex) { }

            try {
                if (!string.IsNullOrEmpty(D?.DefaultUser.Groups))
                {
                    var ug = D?.DefaultUser?.Groups.Split(',');
                    var un = D?.DefaultUser.UserId;
                    foreach (var g in ug)
                    {
                        UG.AddUserToGroup(un, g);
                    }
                }
            } catch (Exception ex) { }

            try
            {
                //Create policies for all the access Policies
                LstPolicy = AP.GetApplicationPolicies();
            }
            catch (Exception ex) { }

            AP.Dispose(); AG.Dispose(); AU.Dispose(); GP.Dispose(); UG.Dispose();

            //AuthB.Services.AddDataProtection()
            //    .PersistKeysToFileSystem(new DirectoryInfo(@""))
            //    .ProtectKeysWithCertificate("thumbnail")
            //    .SetApplicationName("Freshly");
        }
Exemplo n.º 2
0
 public GroupManager()
 {
     AGF = new ApplicationGroupsFactory();
     GPF = new GroupPoliciesFactory();
     APF = new ApplicationPoliciesFactory();
 }