Example #1
0
        private static void CreateSysAdminUser(AuthorityGroup adminGroup, SetupCommandLine cmdLine, IPersistenceContext context, TextWriter log)
        {
            try
            {
                // create the sa user, if doesn't already exist
                IUserBroker userBroker = context.GetBroker<IUserBroker>();
                UserSearchCriteria where = new UserSearchCriteria();
				where.UserName.EqualTo(cmdLine.SysAdminUserName);
                userBroker.FindOne(where);

				log.WriteLine(string.Format("User '{0}' already exists.", cmdLine.SysAdminUserName));
            }
            catch (EntityNotFoundException)
            {
                HashedSet<AuthorityGroup> groups = new HashedSet<AuthorityGroup>
                                                       {
                                                           adminGroup
                                                       };

                // create sa user using initial password, set to expire never
                User saUser = User.CreateNewUser(
					new UserInfo(cmdLine.SysAdminUserName, cmdLine.SysAdminDisplayName, null, null, null),
					Password.CreatePassword(cmdLine.SysAdminInitialPassword, null),
                    groups);
                context.Lock(saUser, DirtyState.New);
            }
        }
Example #2
0
        private static void CreateSysAdminUser(AuthorityGroup adminGroup, SetupCommandLine cmdLine, IPersistenceContext context, TextWriter log)
        {
            try
            {
                // create the sa user, if doesn't already exist
                IUserBroker userBroker = context.GetBroker <IUserBroker>();
                UserSearchCriteria where = new UserSearchCriteria();
                where.UserName.EqualTo(cmdLine.SysAdminUserName);
                userBroker.FindOne(where);

                log.WriteLine(string.Format("User '{0}' already exists.", cmdLine.SysAdminUserName));
            }
            catch (EntityNotFoundException)
            {
                HashedSet <AuthorityGroup> groups = new HashedSet <AuthorityGroup>
                {
                    adminGroup
                };

                // create sa user using initial password, set to expire never
                User saUser = User.CreateNewUser(
                    new UserInfo(cmdLine.SysAdminUserName, cmdLine.SysAdminDisplayName, null, null, null),
                    Password.CreatePassword(cmdLine.SysAdminInitialPassword, null),
                    groups);
                context.Lock(saUser, DirtyState.New);
            }
        }
Example #3
0
        public void RunApplication(string[] args)
        {
            SetupCommandLine cmdLine = new SetupCommandLine();

            try
            {
                cmdLine.Parse(args);

                using (PersistenceScope scope = new PersistenceScope(PersistenceContextType.Update))
                {
                    ((IUpdateContext)PersistenceScope.CurrentContext).ChangeSetRecorder.OperationName = GetType().FullName;

                    // import authority tokens
                    AuthorityTokenImporter tokenImporter = new AuthorityTokenImporter();
                    IList <AuthorityToken> allTokens     = tokenImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);


                    // create the sys admin group, which has all tokens assigned by default
                    string[] tokenStrings = CollectionUtils.Map <AuthorityToken, string, List <string> >(allTokens,
                                                                                                         t => t.Name).ToArray();
                    AuthorityGroupDefinition adminGroupDef = new AuthorityGroupDefinition(cmdLine.SysAdminGroup, cmdLine.SysAdminGroup, false,
                                                                                          tokenStrings);
                    AuthorityGroupImporter groupImporter = new AuthorityGroupImporter();

                    IList <AuthorityGroup> groups =
                        groupImporter.Import(new AuthorityGroupDefinition[] { adminGroupDef }, (IUpdateContext)PersistenceScope.CurrentContext);

                    // find the admin group entity that was just created
                    AuthorityGroup adminGroup = CollectionUtils.SelectFirst(groups,
                                                                            g => g.Name == cmdLine.SysAdminGroup);

                    // create the "sa" user
                    CreateSysAdminUser(adminGroup, cmdLine, PersistenceScope.CurrentContext, Console.Out);

                    // optionally import other default authority groups defined in other plugins
                    if (cmdLine.ImportDefaultAuthorityGroups)
                    {
                        groupImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);
                    }

                    scope.Complete();
                }
            }
            catch (CommandLineException e)
            {
                Console.WriteLine(e.Message);
                cmdLine.PrintUsage(Console.Out);
            }
        }
Example #4
0
        public void RunApplication(string[] args)
        {
			SetupCommandLine cmdLine = new SetupCommandLine();
			try
			{
				cmdLine.Parse(args);

				using (PersistenceScope scope = new PersistenceScope(PersistenceContextType.Update))
				{
					((IUpdateContext)PersistenceScope.CurrentContext).ChangeSetRecorder.OperationName = GetType().FullName;

					// import authority tokens
					AuthorityTokenImporter tokenImporter = new AuthorityTokenImporter();
					IList<AuthorityToken> allTokens = tokenImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);


					// create the sys admin group, which has all tokens assigned by default
					string[] tokenStrings = CollectionUtils.Map<AuthorityToken, string, List<string>>(allTokens,
					                                                                                  t => t.Name).ToArray();
                    AuthorityGroupDefinition adminGroupDef = new AuthorityGroupDefinition(cmdLine.SysAdminGroup, cmdLine.SysAdminGroup, false,
				                                                                          tokenStrings);
					AuthorityGroupImporter groupImporter = new AuthorityGroupImporter();

					IList<AuthorityGroup> groups = 
						groupImporter.Import(new AuthorityGroupDefinition[] { adminGroupDef }, (IUpdateContext)PersistenceScope.CurrentContext);

					// find the admin group entity that was just created
					AuthorityGroup adminGroup = CollectionUtils.SelectFirst(groups,
					                                                        g => g.Name == cmdLine.SysAdminGroup);

					// create the "sa" user
					CreateSysAdminUser(adminGroup, cmdLine, PersistenceScope.CurrentContext, Console.Out);

					// optionally import other default authority groups defined in other plugins
					if (cmdLine.ImportDefaultAuthorityGroups)
					{
						groupImporter.ImportFromPlugins((IUpdateContext) PersistenceScope.CurrentContext);
					}

					scope.Complete();
				}
			}
			catch (CommandLineException e)
			{
				Console.WriteLine(e.Message);
				cmdLine.PrintUsage(Console.Out);
			}
        }
        public void RunApplication(string[] args)
        {
            var cmdLine = new SetupCommandLine();

            try
            {
                cmdLine.Parse(args);

                using (var scope = new PersistenceScope(PersistenceContextType.Update))
                {
                    ((IUpdateContext)PersistenceScope.CurrentContext).ChangeSetRecorder.OperationName = GetType().FullName;

                    // import authority tokens
                    var tokenImporter = new AuthorityTokenImporter();
                    var allTokens     = tokenImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);
                    var tokenStrings  = CollectionUtils.Map <AuthorityToken, string, List <string> >(allTokens, t => t.Name).ToArray();

                    // import built-in groups
                    var builtInAuthorityGroups = new[]
                    {
                        GetSysAdminGroupDefinition(tokenStrings),
                        BuiltInAuthorityGroups.SystemAccounts
                    };

                    var groupImporter = new AuthorityGroupImporter();
                    var groups        = groupImporter.Import(builtInAuthorityGroups, (IUpdateContext)PersistenceScope.CurrentContext);

                    // create the "sa" user
                    var adminGroup = CollectionUtils.SelectFirst(groups, g => g.Name == BuiltInAuthorityGroups.Administrators.Name);
                    CreateSysAdminUser(adminGroup, cmdLine, PersistenceScope.CurrentContext, Console.Out);

                    // optionally import other default authority groups defined in other plugins
                    if (cmdLine.ImportDefaultAuthorityGroups)
                    {
                        groupImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);
                    }

                    scope.Complete();
                }
            }
            catch (CommandLineException e)
            {
                Console.WriteLine(e.Message);
                cmdLine.PrintUsage(Console.Out);
            }
        }
		public void RunApplication(string[] args)
		{
			var cmdLine = new SetupCommandLine();
			try
			{
				cmdLine.Parse(args);

				using (var scope = new PersistenceScope(PersistenceContextType.Update))
				{
					((IUpdateContext)PersistenceScope.CurrentContext).ChangeSetRecorder.OperationName = GetType().FullName;

					// import authority tokens
					var tokenImporter = new AuthorityTokenImporter();
					var allTokens = tokenImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);
					var tokenStrings = CollectionUtils.Map<AuthorityToken, string, List<string>>(allTokens, t => t.Name).ToArray();

					// import built-in groups
					var builtInAuthorityGroups = new[]
					{
						GetSysAdminGroupDefinition(tokenStrings),
						BuiltInAuthorityGroups.SystemAccounts
					};

					var groupImporter = new AuthorityGroupImporter();
					var groups = groupImporter.Import(builtInAuthorityGroups, (IUpdateContext)PersistenceScope.CurrentContext);

					// create the "sa" user
					var adminGroup = CollectionUtils.SelectFirst(groups, g => g.Name == BuiltInAuthorityGroups.Administrators.Name);
					CreateSysAdminUser(adminGroup, cmdLine, PersistenceScope.CurrentContext, Console.Out);

					// optionally import other default authority groups defined in other plugins
					if (cmdLine.ImportDefaultAuthorityGroups)
					{
						groupImporter.ImportFromPlugins((IUpdateContext)PersistenceScope.CurrentContext);
					}

					scope.Complete();
				}
			}
			catch (CommandLineException e)
			{
				Console.WriteLine(e.Message);
				cmdLine.PrintUsage(Console.Out);
			}
		}