コード例 #1
0
        public SsoAuthorizationDTO GetApplicationAuthorizations(ApplicationFilterDTO filter)
        {
            var authorization = new SsoAuthorizationDTO();

            try
            {
                if (string.IsNullOrEmpty(filter.ApplicationCode))
                {
                    throw new ServiceException(CommonExceptionType.ParameterException, "ApplicationCode");
                }

                //Get application and its profiles
                var ssoApp = GetSsoApplication(filter);

                if (ssoApp != default(SsoApplication))
                {
                    authorization.Claims  = ssoApp.GetClaims();
                    authorization.IsValid = (authorization.Claims.Count > 0);
                }
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionAndThrow(ex);
            }

            return(authorization);
        }
コード例 #2
0
        public ApplicationDTO GetApplication(ApplicationFilterDTO filter)
        {
            var dto = default(ApplicationDTO);

            try
            {
                if (string.IsNullOrEmpty(filter.ApplicationCode))
                {
                    throw new ServiceException(CommonExceptionType.ParameterException, "ApplicationCode");
                }

                if (string.IsNullOrEmpty(filter.SpecificDatabase.ToString()))
                {
                    throw new ServiceException(CommonExceptionType.ParameterException, "Specific Database");
                }

                InitializeUnitOfWork(filter.SpecificDatabase);

                //Select application and its profiles
                var ssoApp = GetSsoApplication(filter);

                //Initialize the DTO to return
                dto = ssoApp.Map <SsoApplication, ApplicationDTO>();

                //Set profiles, services and groups names
                foreach (var pro in ssoApp.Profiles)
                {
                    var workerIds = pro.ProfilesAndWorkers.Select(paw => paw.WorkerOrEmployeeId);
                    var workers   = _workerRepo.SelectWhere(w => workerIds.Contains(w.Id)).ToList();

                    //Selects profile to update some properties
                    var selectedProfile = dto.Profiles.First(p => p.Id == pro.Id);
                    selectedProfile.SourceDatabase = filter.SpecificDatabase.ToString();

                    //Copy worker list to the specified profile inside Dto
                    selectedProfile.Users =
                        pro.ProfilesAndWorkers
                        .Select(paw => new Alcoa.Framework.Contract.DTOs.Sso.SsoUserDTO
                    {
                        Id = paw.WorkerOrEmployeeId,
                        NameOrDescription = workers.FirstOrDefault(w => w.Id == paw.WorkerOrEmployeeId).Login,
                    })
                        .ToList();
                }
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionAndThrow(ex);
            }

            return(dto);
        }
コード例 #3
0
        private SsoApplication GetSsoApplication(ApplicationFilterDTO filter)
        {
            //Select application
            var ssoApp = _ssoApplicationRepo.Get(app =>
                                                 app.Id.ToLower() == filter.ApplicationCode.ToLower() ||
                                                 app.Mnemonic.ToLower() == filter.ApplicationCode.ToLower());

            ssoApp.Validate();
            if (ssoApp.Validation.HasErrors)
            {
                throw new ServiceException(ssoApp.Validation.Results);
            }

            var query = new List <Expression <Func <SsoProfile, bool> > >();

            if (!string.IsNullOrEmpty(filter.ApplicationCode))
            {
                query.Add(sp => sp.ApplicationId.ToLower() == filter.ApplicationCode.ToLower());
            }

            //Load options
            var loadOptions = new List <string>();

            if (filter.LoadUsersProfiles)
            {
                loadOptions.Add("ProfilesAndWorkers");
            }

            //Gets profile and workers
            ssoApp.Profiles = _ssoProfileRepo.SelectWhere(query.BuildExpression(), loadOptions.ToArray()).ToList();

            //Validates profile basic properties and adds to validation list
            var validations = new List <ValidationResult>();

            ssoApp.Profiles.AsParallel().ForAll(po => { po.Validate(); validations.AddRange(po.Validation.Results); });

            //Throw validation messages
            if (validations.Any())
            {
                throw new ServiceException(validations);
            }

            return(ssoApp);
        }
コード例 #4
0
        private SsoApplication GetSsoApplication(ApplicationFilterDTO filter)
        {
            //Select application and its profiles
            SsoApplication ssoApp = _ssoApplicationRepo.Get(app =>
                                                            app.Id.ToLower() == filter.ApplicationCode.ToLower() ||
                                                            app.Mnemonic.ToLower() == filter.ApplicationCode.ToLower());

            ssoApp.Validate();
            if (ssoApp.Validation.HasErrors)
            {
                throw new ServiceException(ssoApp.Validation.Results);
            }

            var validations = new List <ValidationResult>();

            //Gets profile, services and workers
            ssoApp.Profiles = _ssoProfileRepo.SelectWhere(sp => sp.ApplicationId.ToLower() == ssoApp.Id.ToLower(),
                                                          "ProfilesAndActiveDirectories",
                                                          "ProfilesAndActiveDirectories.AdGroup",
                                                          "ProfilesAndServices",
                                                          "ProfilesAndServices.Service",
                                                          "ProfilesAndServices.Service.SsoGroup")
                              .ToList();

            //Validates profile basic properties and adds to validation list
            ssoApp.Profiles.AsParallel().ForAll(po => { po.Validate(); validations.AddRange(po.Validation.Results); });

            //Load profiles for all users and validate errors
            var profilesWorkersList = default(List <SsoProfileAndWorker>);

            if (filter.LoadUsersProfiles)
            {
                profilesWorkersList = _ssoProfileWorkerRepo.SelectWhere(spw => spw.ApplicationId.ToLower() == ssoApp.Id.ToLower()).ToList();
                profilesWorkersList.AsParallel().ForAll(po => { po.Validate(); validations.AddRange(po.Validation.Results); });
            }

            //Throw validation messages
            if (validations.Any())
            {
                throw new ServiceException(validations);
            }

            var adGroupTempCache = new Hashtable();

            //Set profiles dependencies on profile list
            foreach (var pl in ssoApp.Profiles)
            {
                pl.ProfilesAndActiveDirectories
                .ForEach(pad =>
                {
                    if (pad.AdGroup != null && !string.IsNullOrEmpty(pad.AdGroup.NameOrDescription))
                    {
                        var tempKey = pad.AdGroup.NameOrDescription.Clone();
                        pad.AdGroup = ((ActiveDirectoryGroup)adGroupTempCache[tempKey] ?? _adRepo.GetGroup(pad.AdGroup.NameOrDescription, filter.LoadActiveDirectoryExtraInfo).Map <BaseActiveDirectoryGroup, ActiveDirectoryGroup>());
                        adGroupTempCache[tempKey] = pad.AdGroup;
                    }
                    else
                    {
                        pad.AdGroup = new ActiveDirectoryGroup {
                            Users = new List <BaseIdentification>()
                        }
                    };
                });

                pl.ProfilesAndServices
                .AsParallel().ForAll(pas =>
                {
                    if (pas.Service == null)
                    {
                        pas.Service = new SsoServices {
                            SsoGroup = new SsoGroup()
                        }
                    }
                    ;
                    else if (pas.Service.SsoGroup == null)
                    {
                        pas.Service.SsoGroup = new SsoGroup();
                    }
                });

                if (filter.LoadUsersProfiles)
                {
                    pl.ProfilesAndWorkers = profilesWorkersList
                                            .Where(pw => pw.ProfileId == pl.Id && pw.ApplicationId == pl.ApplicationId)
                                            .ToList();
                }
            }

            //Load translations for profiles and nested objects
            if (filter.LoadTranslations)
            {
                var appIds = new List <string> {
                    ssoApp.Id.ToLower()
                };
                var translationParameters = new List <string>
                {
                    CommonTranslationParameter.TRANS_TP_EXC_APPL.ToString(),
                    CommonTranslationParameter.TRANS_TP_EXC_GRUPO.ToString(),
                    CommonTranslationParameter.TRANS_TP_EXC_SERVICO.ToString(),
                    CommonTranslationParameter.TRANS_TP_EXC_GRP_EXB.ToString()
                };

                var translations = LoadTranslations(appIds, translationParameters, filter.LanguageCultureName);

                ssoApp.AddTranslations(translations);
            }

            return(ssoApp);
        }
コード例 #5
0
        private List <SsoApplication> GetUserApplications(UserFilterDTO userFilter, ApplicationFilterDTO appFilter)
        {
            var appList = default(List <SsoApplication>);
            var query   = new List <Expression <Func <SsoProfileAndWorker, bool> > > {
                wp => wp.Login.ToLower() == userFilter.Login.Trim().ToLower()
            };

            //Get distinct App ids
            var appDistinctIds = _ssoProfileWorkerRepo
                                 .SelectWhere(query.BuildExpression())
                                 .Select(paw => paw.ApplicationId.ToLower())
                                 .Distinct()
                                 .ToList();

            //Get all user related Applications
            appList = _ssoApplicationRepo
                      .SelectWhere(app => appDistinctIds.Contains(app.Id.ToLower()))
                      .ToList();

            //If an application code provided use to filter Profile querys.
            if (!string.IsNullOrEmpty(appFilter.ApplicationCode))
            {
                //Get application by Id, if not found try get by Mnemonic
                var ssoApp = appList.FirstOrDefault(app => app.Id.ToLower() == appFilter.ApplicationCode.ToLower());

                if (ssoApp == null)
                {
                    ssoApp = appList
                             .Where(app => app.Mnemonic != null)
                             .FirstOrDefault(app => app.Mnemonic.ToLower() == appFilter.ApplicationCode.ToLower());
                }

                if (ssoApp == null)
                {
                    throw new ServiceException(CommonExceptionType.ValidationException, "Application isn´t related to this user.");
                }

                query.Add(wp => wp.ApplicationId.ToLower() == ssoApp.Id.ToLower());
            }

            var allProfiles = new List <SsoProfile>();

            //Load User Profiles
            if (userFilter.LoadProfiles)
            {
                //Get profiles by workers
                var profilesWorkers = _ssoProfileWorkerRepo
                                      .SelectWhere(query.BuildExpression(),
                                                   "Profile",
                                                   "Profile.ProfilesAndActiveDirectories",
                                                   "Profile.ProfilesAndActiveDirectories.AdGroup",
                                                   "Profile.ProfilesAndServices",
                                                   "Profile.ProfilesAndServices.Service",
                                                   "Profile.ProfilesAndServices.Service.SsoGroup")
                                      .ToList();

                //Adds workers profiles to list
                allProfiles.AddRange(profilesWorkers.Select(paw => paw.Profile));
            }

            //Load Public Services, Groups and Profiles
            if (userFilter.LoadPublicServices)
            {
                //Get public services and nested objects
                var publicProfileServices = _ssoProfileServiceRepo
                                            .SelectWhere(ps => ps.Service.IsPublic == "S",
                                                         "Profile",
                                                         "Service",
                                                         "Service.SsoGroup")
                                            .ToList();

                //Adds public service profiles to list
                allProfiles.AddRange(publicProfileServices.Select(pps => pps.Profile));
            }

            //If profiles are loaded, put then under each app
            if (allProfiles.Any())
            {
                //Load translations for profiles and nested objects
                var translations = default(List <ApplicationTranslation>);
                if (appFilter.LoadTranslations)
                {
                    var translationParameters = new List <string>
                    {
                        CommonTranslationParameter.TRANS_TP_EXC_APPL.ToString(),
                        CommonTranslationParameter.TRANS_TP_EXC_GRUPO.ToString(),
                        CommonTranslationParameter.TRANS_TP_EXC_SERVICO.ToString(),
                        CommonTranslationParameter.TRANS_TP_EXC_GRP_EXB.ToString()
                    };

                    translations = LoadTranslations(appDistinctIds, translationParameters, appFilter.LanguageCultureName);
                }

                //Adds profiles to applications
                appList.AsParallel().ForAll(app =>
                {
                    app.AddProfilesAndDependencies(allProfiles);

                    if (appFilter.LoadTranslations)
                    {
                        app.AddTranslations(translations);
                    }
                });
            }

            return(appList);
        }
コード例 #6
0
        public ApplicationDTO GetApplication(ApplicationFilterDTO filter)
        {
            var dto = default(ApplicationDTO);

            try
            {
                if (string.IsNullOrEmpty(filter.ApplicationCode))
                {
                    throw new ServiceException(CommonExceptionType.ParameterException, "ApplicationCode");
                }

                //Select application and its profiles
                var ssoApp = GetSsoApplication(filter);

                //Initialize the DTO to return
                dto = ssoApp.Map <SsoApplication, ApplicationDTO>();

                //Set profiles, services and groups names
                foreach (var pro in ssoApp.Profiles)
                {
                    //Variables to use in loop
                    var profileId  = pro.Id;
                    var dtoProfile = dto.Profiles.FirstOrDefault(p => p.Id == profileId);
                    dtoProfile.SourceDatabase = CommonDatabase.P335.ToString();

                    if (dtoProfile != null)
                    {
                        //Copy AD group list to the specified profile inside Dto
                        dtoProfile.ActiveDirectoryGroups = pro.ProfilesAndActiveDirectories
                                                           .Where(pad => pad.ProfileId == profileId)
                                                           .Select(pad => pad.AdGroup)
                                                           .ToList()
                                                           .Map <List <ActiveDirectoryGroup>, List <ActiveDirectoryGroupDTO> >();

                        //Copy worker list to the specified profile inside Dto
                        dtoProfile.Users = pro.ProfilesAndWorkers
                                           .Select(paw => new SsoUserDTO
                        {
                            Id = paw.WorkerOrEmployeeId,
                            NameOrDescription = paw.Login,
                        })
                                           .ToList();

                        //Inverts the hierarchy between SSOGroup and SSOServices, putting SSOGroup as a container
                        dtoProfile.SsoGroups = pro.ProfilesAndServices
                                               .Where(p => p.ProfileId == profileId)
                                               .Select(p => new SsoGroupDTO
                        {
                            Id = p.Service.GroupId,
                            NameOrDescription = p.Service.SsoGroup.NameOrDescription,
                            Services          = pro.ProfilesAndServices
                                                .Where(ps => ps.ProfileId == profileId && ps.Service.GroupId == p.Service.GroupId)
                                                .Select(se => se.Service)
                                                .ToList()
                                                .Map <List <SsoServices>, List <SsoServicesDTO> >(),
                        })
                                               .Distinct(new EqualBy <SsoGroupDTO>((x, y) => x.Id == y.Id))
                                               .ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionAndThrow(ex);
            }

            return(dto);
        }