Ejemplo n.º 1
0
        // -----------------------------------------------------------------------------
        async Task DoGroupStuff(ADX.DTO.ADEvent adEvent, CancellationToken cancellationToken)
        {
            var groupDTO = adEvent.GetADObject() as ADX.DTO.Group;

            if (groupDTO != null)
            {
                var serverName = adEvent.Sender.ServerName;

                var group = _adObjectFactory.TryGetGroup(groupDTO.objectGuid, serverName);

                if (group != null)
                {
                    // Do something with group ...
                    //_logger.LogTrace($"Group handler => [{group.ToString()}]");
                }
            }

            await Task.Yield();
        }
Ejemplo n.º 2
0
        // -----------------------------------------------------------------------------
        async Task DoUserStuff(ADX.DTO.ADEvent adEvent, CancellationToken cancellationToken)
        {
            try
            {
                string operation = null;

                switch (adEvent.ADEventType)
                {
                case ADX.DTO.ADEventType.Create:
                case ADX.DTO.ADEventType.Raw:
                    operation = "UPDATE";
                    break;

                case ADX.DTO.ADEventType.Ping:
                    operation = "UPDATE";
                    break;

                case ADX.DTO.ADEventType.Update:
                    operation = "UPDATE";
                    break;

                case ADX.DTO.ADEventType.Delete:
                    operation = "DELETE";
                    break;
                }

                if (operation != null)
                {
                    var userDTO = adEvent.GetADObject() as ADX.DTO.User;
                    if (userDTO != null)
                    {
                        var serverName = adEvent.Sender.ServerName;
                        var uuid       = userDTO.objectGuid.ToString().ToLower();

                        var user = _adObjectFactory.TryGetUser(userDTO.objectGuid, serverName);
                        if (user != null)
                        {
                            var sdb     = new SDBService(Configuration.GetValue <string>("SDBUrl"));
                            var stsUser = sdb.InspectUser(uuid, user.dn);
                            if (stsUser == null || stsUser._objectID.Equals(Guid.Empty))
                            {
                                throw new Exception("Could not find user in SDB: " + uuid);
                            }

                            // dirty hack to detect users moved outside "main ou hierarchy"
                            if (!stsUser.WithinScope)
                            {
                                operation = "DELETE";
                            }

                            Organisation.BusinessLayer.DTO.Registration.UserRegistration userReg = new Organisation.BusinessLayer.DTO.Registration.UserRegistration();
                            userReg.Person.Cpr  = stsUser.CPR;
                            userReg.Person.Name = stsUser.Name;
                            userReg.Timestamp   = DateTime.Now;
                            userReg.UserId      = stsUser.UserId;
                            userReg.ShortKey    = stsUser.UserShortKey;
                            userReg.Uuid        = uuid;

                            foreach (var address in stsUser.Addresses)
                            {
                                switch (address.Type)
                                {
                                case SDBServices.STS.DTO.AddressType.Email:
                                    userReg.Email = address._text;
                                    break;

                                case SDBServices.STS.DTO.AddressType.Telefon:
                                    userReg.PhoneNumber = address._text;
                                    break;

                                case SDBServices.STS.DTO.AddressType.Placering:
                                    userReg.Location = address._text;
                                    break;
                                }
                            }

                            if (stsUser.Position != null)
                            {
                                userReg.Positions.Add(new Organisation.BusinessLayer.DTO.Registration.Position()
                                {
                                    Name        = stsUser.Position._text,
                                    OrgUnitUuid = stsUser.Position.OUID.ToString().ToLower()
                                });
                            }

                            // not in SDB yet
                            userReg.RacfID = null;

                            var userDao = new Organisation.SchedulingLayer.UserDao();
                            userDao.Save(userReg, "DELETE".Equals(operation) ? Organisation.SchedulingLayer.OperationType.DELETE : Organisation.SchedulingLayer.OperationType.UPDATE, Configuration.GetValue <string>("Municipality"));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            await Task.Yield();
        }
Ejemplo n.º 3
0
 // -----------------------------------------------------------------------------
 public async Task HandleEvent(ADX.DTO.ADEvent adEvent, CancellationToken cancellationToken)
 {
     await DoGroupStuff(adEvent, cancellationToken);
 }
Ejemplo n.º 4
0
        // -----------------------------------------------------------------------------
        async Task DoOUStuff(ADX.DTO.ADEvent adEvent, CancellationToken cancellationToken)
        {
            string operation = null;

            switch (adEvent.ADEventType)
            {
            case ADX.DTO.ADEventType.Create:
            case ADX.DTO.ADEventType.Raw:
                operation = "UPDATE";
                break;

            case ADX.DTO.ADEventType.Ping:
                operation = "UPDATE";
                break;

            case ADX.DTO.ADEventType.Update:
                operation = "UPDATE";
                break;

            case ADX.DTO.ADEventType.Delete:
                operation = "DELETE";
                break;
            }

            if (operation != null)
            {
                var ouDTO = adEvent.GetADObject() as ADX.DTO.OU;

                if (ouDTO != null)
                {
                    var serverName = adEvent.Sender.ServerName;
                    var uuid       = ouDTO.objectGuid.ToString().ToLower();

                    var ou = _adObjectFactory.TryGetOU(ouDTO.objectGuid, serverName);
                    if (ou != null)
                    {
                        var sdb   = new SDBService(Configuration.GetValue <string>("SDBUrl"));
                        var stsOu = sdb.InspectOrgUnit(uuid, ou.dn);

                        if (stsOu == null || stsOu._objectID.Equals(Guid.Empty))
                        {
                            throw new Exception("OU did not exists in SDB: " + uuid);
                        }

                        if (!stsOu.WithinScope)
                        {
                            operation = "DELETE";
                        }

                        Organisation.BusinessLayer.DTO.Registration.OrgUnitRegistration ouReg = new Organisation.BusinessLayer.DTO.Registration.OrgUnitRegistration();
                        ouReg.Name = stsOu.Name;
                        ouReg.ParentOrgUnitUuid = stsOu._parentID?.ToString()?.ToLower();
                        ouReg.PayoutUnitUuid    = stsOu._payoutUnitID?.ToString()?.ToLower();
                        ouReg.ShortKey          = stsOu.ShortKey;
                        ouReg.Timestamp         = DateTime.Now;
                        ouReg.Type = Organisation.BusinessLayer.DTO.Registration.OrgUnitRegistration.OrgUnitType.DEPARTMENT;
                        ouReg.Uuid = uuid;

                        foreach (var address in stsOu.Addresses)
                        {
                            switch (address.Type)
                            {
                            case SDBServices.STS.DTO.AddressType.Email:
                                ouReg.Email = address._text;
                                break;

                            case SDBServices.STS.DTO.AddressType.EmailBemaerkning:
                                ouReg.EmailRemarks = address._text;
                                break;

                            case SDBServices.STS.DTO.AddressType.Telefon:
                                ouReg.PhoneNumber = address._text;
                                break;

                            case SDBServices.STS.DTO.AddressType.TelefonAabningstid:
                                ouReg.PhoneOpenHours = address._text;
                                break;

                            case SDBServices.STS.DTO.AddressType.Placering:
                                ouReg.Location = address._text;
                                break;

                            case SDBServices.STS.DTO.AddressType.EAN:
                                ouReg.Ean = address._text;
                                break;

                            case SDBServices.STS.DTO.AddressType.HenvendelseAabningstid:
                                ouReg.ContactOpenHours = address._text;
                                break;

                            case SDBServices.STS.DTO.AddressType.HenvendelsesAdresse:
                                ouReg.Contact = address._text;
                                break;

                            case SDBServices.STS.DTO.AddressType.LOSKaldenavnKort:
                                ouReg.LOSShortName = address._text;
                                break;

                            case SDBServices.STS.DTO.AddressType.PostAdresse:
                                ouReg.Post = address._text;
                                break;

                            case SDBServices.STS.DTO.AddressType.PostReturAdresse:
                                ouReg.PostReturn = address._text;
                                break;
                            }
                        }

                        var orgUnitDao = new Organisation.SchedulingLayer.OrgUnitDao();
                        orgUnitDao.Save(ouReg, "DELETE".Equals(operation) ? Organisation.SchedulingLayer.OperationType.DELETE : Organisation.SchedulingLayer.OperationType.UPDATE, Configuration.GetValue <string>("Municipality"));
                    }
                }
            }

            await Task.Yield();
        }