コード例 #1
0
        public ADCST(string arg, Logger Logger, IConfiguration config, IAuthenticationProvidor authProvidor, IAzureADFunctions azureAdFunctions, IOnPremADHelper onPremAdHelper, IOnPremAdFunctions onPremAdFunctions)
        {
            if (string.IsNullOrEmpty(arg))
            {
                StartSync(Logger, config, authProvidor, azureAdFunctions, onPremAdHelper, onPremAdFunctions, false);
            }
            else
            {
                switch (arg.ToLower())
                {
                case @"/h":
                case @"--h":
                case @"-h":
                case @"h":
                    ShowHelp();
                    break;

                case @"/d":
                case @"--d":
                case @"-d":
                case @"d":
                    StartSync(Logger, config, authProvidor, azureAdFunctions, onPremAdHelper, onPremAdFunctions, true);
                    break;

                default:
                    StartSync(Logger, config, authProvidor, azureAdFunctions, onPremAdHelper, onPremAdFunctions, false);
                    break;
                }
            }
        }
コード例 #2
0
ファイル: AzureADFunctions.cs プロジェクト: wain77/ADCST
        public ActiveDirectoryClient ADClient(IConfiguration Configuration, IAuthenticationProvidor authProvidor, Logger Logger)
        {
            ActiveDirectoryClient activeDirectoryClient;

            try
            {
                Logger.Debug(@"Connecting to Azure Active Directory GraphAPI to get ClientSession");
                activeDirectoryClient = authProvidor.GetActiveDirectoryClientAsApplication(Configuration);

                if (activeDirectoryClient != null)
                {
                    return(activeDirectoryClient);
                }
                else
                {
                    return(null);
                }
            }
            catch (AuthenticationException ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Acquiring a token failed with the following error: {0}", ex.Message);
                Logger.Error(String.Format(@"Could not aquire Azure active Directory Authentication Token {0}", ex.Message));

                if (ex.InnerException != null)
                {
                    //InnerException Message will contain the HTTP error status codes mentioned in the link above
                    Console.WriteLine("Error detail: {0}", ex.InnerException.Message);
                    Logger.Error(String.Format(@"Error detail {0}", ex.InnerException));
                }
                Console.ResetColor();
                return(null);
            }
        }
コード例 #3
0
ファイル: ADCST.cs プロジェクト: spSlaine/ADCST
        public ADCST(string arg, Logger Logger, IConfiguration config, IAuthenticationProvidor authProvidor, IAzureADFunctions azureAdFunctions, IOnPremADHelper onPremAdHelper, IOnPremAdFunctions onPremAdFunctions)
        {
            if (string.IsNullOrEmpty(arg))
            {
                StartSync(Logger, config, authProvidor, azureAdFunctions, onPremAdHelper, onPremAdFunctions, false);
            }
            else
            {
                switch (arg.ToLower())
                {
                    case @"/h":
                    case @"--h":
                    case @"-h":
                    case @"h":
                        ShowHelp();
                        break;

                    case @"/d":
                    case @"--d":
                    case @"-d":
                    case @"d":
                        StartSync(Logger, config, authProvidor, azureAdFunctions, onPremAdHelper, onPremAdFunctions, true);
                        break;

                    default:
                        StartSync(Logger, config, authProvidor, azureAdFunctions, onPremAdHelper, onPremAdFunctions, false);
                        break;
                }
            }
        }
コード例 #4
0
ファイル: AzureADFunctions.cs プロジェクト: spSlaine/ADCST
        public ActiveDirectoryClient ADClient(IConfiguration Configuration, IAuthenticationProvidor authProvidor, Logger Logger)
        {
            ActiveDirectoryClient activeDirectoryClient;
            try
            {
                Logger.Debug(@"Connecting to Azure Active Directory GraphAPI to get ClientSession");
                activeDirectoryClient = authProvidor.GetActiveDirectoryClientAsApplication(Configuration);

                if (activeDirectoryClient != null)
                {
                    return activeDirectoryClient;
                }
                else
                {
                    return null;
                }
            }
            catch (AuthenticationException ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Acquiring a token failed with the following error: {0}", ex.Message);
                Logger.Error(String.Format(@"Could not aquire Azure active Directory Authentication Token {0}", ex.Message));

                if (ex.InnerException != null)
                {
                    //InnerException Message will contain the HTTP error status codes mentioned in the link above
                    Console.WriteLine("Error detail: {0}", ex.InnerException.Message);
                    Logger.Error(String.Format(@"Error detail {0}", ex.InnerException));

                }
                Console.ResetColor();
                return null;
            }
        }
コード例 #5
0
        private void StartSync(Logger Logger, IConfiguration config, IAuthenticationProvidor authProvidor, IAzureADFunctions azureAdFunctions, IOnPremADHelper onPremAdHelper,
                               IOnPremAdFunctions onPremAdFunctions, bool ShowDiagnostics)
        {
            ActiveDirectoryClient ClientSession = azureAdFunctions.ADClient(config, authProvidor, Logger);

            //Show Azure Tennant Diagnostics if requested.
            if (ShowDiagnostics)
            {
                Console.WriteLine(azureAdFunctions.TenantDetails(ClientSession, Logger, config));
            }
            //TODO RE-ENABLE THE BELOW METHOD!
            //We're done outputting debug info - Call the applications main logic.
            _objContactManagement.ContactSync(Logger, config, authProvidor, azureAdFunctions, onPremAdHelper, onPremAdFunctions, ClientSession);
            _objGroupManagement.GroupSync(Logger, config, authProvidor, azureAdFunctions, onPremAdHelper, onPremAdFunctions, ClientSession);
        }
コード例 #6
0
ファイル: ADCST.cs プロジェクト: spSlaine/ADCST
        private void StartSync(Logger Logger, IConfiguration config, IAuthenticationProvidor authProvidor,  IAzureADFunctions azureAdFunctions, IOnPremADHelper onPremAdHelper, 
                                     IOnPremAdFunctions onPremAdFunctions, bool ShowDiagnostics)
        {
            ActiveDirectoryClient ClientSession = azureAdFunctions.ADClient(config, authProvidor, Logger);

            //Show Azure Tennant Diagnostics if requested.
            if(ShowDiagnostics)
            {
                Console.WriteLine(azureAdFunctions.TenantDetails(ClientSession, Logger, config));
            }
            //TODO RE-ENABLE THE BELOW METHOD!
            //We're done outputting debug info - Call the applications main logic.
            _objContactManagement.ContactSync(Logger, config, authProvidor, azureAdFunctions, onPremAdHelper, onPremAdFunctions, ClientSession);
            _objGroupManagement.GroupSync(Logger, config, authProvidor, azureAdFunctions, onPremAdHelper, onPremAdFunctions, ClientSession);
        }
コード例 #7
0
ファイル: Contact Management.cs プロジェクト: spSlaine/ADCST
        public void ContactSync(Logger Logger, IConfiguration config, IAuthenticationProvidor authProvidor, IAzureADFunctions azureAdFunctions, IOnPremADHelper onPremAdHelper, IOnPremAdFunctions onPremAdFunctions, ActiveDirectoryClient AzureClientSession)
        {
            //Get Entry into On-prem Active Directory Contacts OU.
            DirectoryEntry _OnPremContactsDirectoryEntry = onPremAdHelper.GetADDirectoryEntry(config.FQDomainName, config.ContactsDestinationOUDN, Logger);

            //Gather User Objects for the Work we intend to do later:
            Group _AzureUsersgroup = azureAdFunctions.GetADGroup(AzureClientSession, config.AzureADUserGroup, Logger);
            if (_AzureUsersgroup != null)
            {
                List<Tuple<string, IDirectoryObject>> _AzureGroupMembers = azureAdFunctions.GetAdGroupMembers(_AzureUsersgroup, config, Logger);

                if (_AzureGroupMembers.Any(members => members.Item1 == "user"))
                {
                    List<IUser> _AzureGroupUsers = _AzureGroupMembers.Where(member => member.Item1.Equals("user"))
                                                                     .Select(member => member.Item2)
                                                                     .Select(member => member as IUser)
                                                                     .ToList();

                    List<DirectoryEntry> _OnPremContactObjects = onPremAdFunctions.GetOUContactObjects(config.FQDomainName, config.ContactsDestinationOUDN, onPremAdHelper, Logger);

                    #region Add Contact Objects to AD Contacts OU
                    //foreach user in Cloud check if they reside onprem and add them if they dont.

                    if (config.AllowCreationOfADObjects)
                    {
                        Dictionary<string, IUser> azureUsers = _AzureGroupUsers.Where(x => x.Mail != null)
                                                                               .ToDictionary(x => x.Mail.ToLower(), x => x);

                        foreach (string OnPremUser in _OnPremContactObjects.Where(x => x.Properties["Mail"].Value != null)
                                                                           .Select(x => x.Properties["Mail"].Value.ToString()))
                        {
                            azureUsers.Remove(OnPremUser.ToLower());
                        }

                        int CreatedUsers = onPremAdFunctions.CreateADUserContacts(Logger, config, _OnPremContactsDirectoryEntry, onPremAdHelper, azureUsers);

                        Logger.Debug(String.Format("Created {0} user(s) in On-Prem Active Directory", CreatedUsers.ToString()));
                        Console.WriteLine("Created {0} user(s) in On-Prem Active Directory", CreatedUsers.ToString());

                    }
                    #endregion

                    #region Delete Contact Objects from AD OU
                    //foreach user onprem check if they reside in cloud - delete them from AD if they dont (Make this over-rideable with a key)
                    if (config.AllowDeletionOfADObjects)
                    {
                        Dictionary<string, DirectoryEntry> onpremUsers = _OnPremContactObjects.Where(y => y.Properties["Mail"].Value != null)
                                                                                              .ToDictionary(y => y.Properties["Mail"].Value.ToString().ToLower(), y => y);

                        foreach (string AzureUser in _AzureGroupUsers.Where(y => y.Mail != null)
                                                                     .Select(y => y.Mail.ToLower()))
                        {
                            onpremUsers.Remove(AzureUser.ToLower());
                        }

                        int DeletedUsers = onPremAdFunctions.DeleteADContacts(Logger, config, _OnPremContactsDirectoryEntry, onpremUsers);

                        Logger.Debug(String.Format("Deleted {0} user(s) in On-Prem Active Directory", DeletedUsers.ToString()));
                        Console.WriteLine("Deleted {0} user(s) in On-Prem Active Directory", DeletedUsers.ToString());
                    }
                }
                else
                {
                    Console.WriteLine("Could not find any USER objects in group {0}", config.AzureADUserGroup);
                    Logger.Error(String.Format("Could not find any USER objects in group {0}", config.AzureADUserGroup));
                }

            }
            else
            {
                Console.WriteLine("Could not find Group in Azure ({0} to enumerate users from", config.AzureADUserGroup);
                Logger.Error(String.Format("Could not find Group in Azure ({0} to enumerate users from", config.AzureADUserGroup));
            }

            //Close AD Directory Entry Handle
            onPremAdHelper.DisposeADDirectoryEntry(_OnPremContactsDirectoryEntry, Logger);

            Console.WriteLine("Contact Creation/Deletion complete - Changes will be reflected on Office365 Sync on Next Dir-Sync Cycle but may not appear in Address book until the following day.");
            Logger.Debug(@"Contact Creation/Deletion complete - Changes will be reflected on Office365 upon next DirSync.");

            #endregion
        }
コード例 #8
0
ファイル: Group Management.cs プロジェクト: wain77/ADCST
        public void GroupSync(Logger Logger, IConfiguration config, IAuthenticationProvidor authProvidor, IAzureADFunctions azureAdFunctions, IOnPremADHelper onPremAdHelper, IOnPremAdFunctions onPremAdFunctions, ActiveDirectoryClient AzureClientSession)
        {
            //Get Entry into On-prem Active Directory Groups OU.
            DirectoryEntry _OnPremGroupsDirectoryEntry = onPremAdHelper.GetADDirectoryEntry(config.FQDomainName, config.GroupsDestinationOUDN, Logger);

            //Gather User Objects for the Work we intend to do later:
            Group _AzureUsersgroup = azureAdFunctions.GetADGroup(AzureClientSession, config.AzureADGroupsGroup, Logger);

            if (_AzureUsersgroup != null)
            {
                List <Tuple <string, IDirectoryObject> > _AzureGroupMembers = azureAdFunctions.GetAdGroupMembers(_AzureUsersgroup, config, Logger);

                if (_AzureGroupMembers.Any(members => members.Item1 == "group"))
                {
                    List <IGroup> _AzureGroupGroups = _AzureGroupMembers.Where(member => member.Item1.Equals("group"))
                                                      .Select(member => member.Item2)
                                                      .Select(member => member as IGroup)
                                                      .ToList();

                    List <DirectoryEntry> _OnPremContactObjects = onPremAdFunctions.GetOUContactObjects(config.FQDomainName, config.GroupsDestinationOUDN, onPremAdHelper, Logger);

                    #region Add Contact Objects to AD Contacts OU
                    //foreach group in Cloud check if they reside onprem and add them if they dont.

                    if (config.AllowCreationOfADObjects)
                    {
                        Dictionary <string, IGroup> azureGroups = _AzureGroupGroups.Where(x => x.Mail != null)
                                                                  .ToDictionary(x => x.Mail.ToLower(), x => x);

                        foreach (string OnPremUser in _OnPremContactObjects.Where(x => x.Properties["Mail"].Value != null)
                                 .Select(x => x.Properties["Mail"].Value.ToString()))
                        {
                            azureGroups.Remove(OnPremUser.ToLower());
                        }

                        int CreatedUsers = onPremAdFunctions.CreateADGroupContacts(Logger, config, _OnPremGroupsDirectoryEntry, onPremAdHelper, azureGroups);

                        Logger.Debug(String.Format("Created {0} group(s) in On-Prem Active Directory", CreatedUsers.ToString()));
                        Console.WriteLine("Created {0} group(s) in On-Prem Active Directory", CreatedUsers.ToString());
                    }
                    #endregion

                    #region Delete Group Objects from AD OU

                    //foreach group onprem check if they reside in cloud - delete them from AD if they dont (Make this over-rideable with a key)
                    if (config.AllowDeletionOfADObjects)
                    {
                        Dictionary <string, DirectoryEntry> onpremGroups = _OnPremContactObjects.Where(y => y.Properties["Mail"].Value != null)
                                                                           .ToDictionary(y => y.Properties["Mail"].Value.ToString().ToLower(), y => y);

                        foreach (string AzureUser in _AzureGroupGroups.Where(y => y.Mail != null)
                                 .Select(y => y.Mail.ToLower()))
                        {
                            onpremGroups.Remove(AzureUser.ToLower());
                        }

                        int DeletedGroups = onPremAdFunctions.DeleteADContacts(Logger, config, _OnPremGroupsDirectoryEntry, onpremGroups);

                        Logger.Debug(String.Format("Deleted {0} group(s) in On-Prem Active Directory", DeletedGroups.ToString()));
                        Console.WriteLine("Deleted {0} group(s) in On-Prem Active Directory", DeletedGroups.ToString());
                    }
                }
                else
                {
                    Console.WriteLine("Could not find any GROUP objects in group {0}", config.AzureADUserGroup);
                    Logger.Error(String.Format("Could not find any GROUP objects in group {0}", config.AzureADUserGroup));
                }
            }
            else
            {
                Console.WriteLine("Could not find Group in Azure ({0} to enumerate users from", config.AzureADUserGroup);
                Logger.Error(String.Format("Could not find Group in Azure ({0} to enumerate users from", config.AzureADUserGroup));
            }

            //Close AD Directory Entry Handle
            onPremAdHelper.DisposeADDirectoryEntry(_OnPremGroupsDirectoryEntry, Logger);

            Console.WriteLine("Group Creation/Deletion complete - Changes will be reflected on Office365 Sync on Next Dir-Sync Cycle but may not appear in Address book until the following day.");
            Logger.Debug(@"Group Creation/Deletion complete - Changes will be reflected on Office365 upon next DirSync.");

            #endregion
        }