Esempio n. 1
0
        private void HandleUserInput()
        {
            try
            {
                var option = (ApplicationOption)int.Parse(Console.ReadLine());

                if (option.Equals(ApplicationOption.TerminateApplication))
                {
                    Environment.Exit(0);
                }

                var application = applicationFactory.CreateApplication(option);
                application.Start();
            }
            catch (KeyNotFoundException)
            {
                Console.WriteLine("Option not available, try again!");
                Console.ReadLine();
            }
            catch (FormatException)
            {
                Console.WriteLine("Invalid input format. The format needs to be an integer number, try again!");
                Console.ReadLine();
            }
            finally
            {
                Display();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new <see cref="CPUser"/> instance using C-Access Security profile data.
        /// </summary>
        /// <param name="profile">The profile to use.</param>
        /// <returns>A new C-Access user account instance using the specified C-Access Security profile data if valid; otherwise, null.</returns>
        public static CPUser CreateUser(SecurityUserProfile profile)
        {
            CPUser user = null;

            if (profile != null)
            {
                user = CreateUser(Membership.GetUser(profile.UserName));
                if (user != null)
                {
                    user.DisplayName     = profile.DisplayName;
                    user.Cid             = profile.CandidateId;
                    user.PasswordExpired = profile.PasswordExpired;

                    // load additional user data
                    user.ElectionCycles.AddRange(CPSecurity.Provider.GetAuthorizedElectionCycles(user.UserName));
                    user.ImplicitElectionCycles = !SecurityService.GetExplicitElectionCycles(user.UserName).Any();
                    user.UserRights             = CPSecurity.Provider.GetUserRights(user.UserName);
                    using (CPSecurityEntities context = new CPSecurityEntities())
                    {
                        foreach (var app in context.SecuritySsoApplications)
                        {
                            if (user.UserRights.HasFlag((CPUserRights)app.UserRights))
                            {
                                user.Applications.Add(ApplicationFactory.CreateApplication(app));
                            }
                        }
                    }

                    // get CFIS source info
                    user.SourceType = Enum.IsDefined(typeof(EntityType), profile.CfisType) ? (EntityType)profile.CfisType : EntityType.Generic;
                    if (!string.IsNullOrWhiteSpace(profile.CfisCommitteeID))
                    {
                        user.SourceCommitteeID = profile.CfisCommitteeID.ToCharArray()[0];
                    }
                    byte liaisonID;
                    if (byte.TryParse(profile.CfisCommitteeContactID, out liaisonID))
                    {
                        user.SourceLiaisonID = liaisonID;
                        // attempt to determine election cycle of associated committee
                        if (user.SourceCommitteeID.HasValue)
                        {
                            char commID    = user.SourceCommitteeID.Value;
                            var  elections = from ec in CPProviders.DataProvider.GetActiveElectionCycles(profile.CandidateId, CPProviders.SettingsProvider.MinimumElectionCycle)
                                             let comm = CPProviders.DataProvider.GetAuthorizedCommittees(profile.CandidateId, ec)
                                                        where comm.Committees.ContainsKey(commID)
                                                        select ec;
                            if (elections.Any())
                            {
                                user.SourceElectionCycle = elections.First();
                            }
                        }
                    }
                    else
                    {
                        user.SourceElectionCycle = profile.CfisCommitteeContactID;
                    }
                }
            }
            return(user);
        }
Esempio n. 3
0
 /// <summary>
 /// Gets information about a specific SSO-enabled application.
 /// </summary>
 /// <param name="applicationID">The unique identifier of the application.</param>
 /// <returns>The application requested if found; otherwise, null.</returns>
 public Application GetApplication(byte applicationID)
 {
     using (CPSecurityEntities context = new CPSecurityEntities())
     {
         var app = context.SecuritySsoApplications.FirstOrDefault(a => a.ApplicationId == applicationID);
         return(ApplicationFactory.CreateApplication(app));
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Creates the test application for authentication.
 /// </summary>
 /// <param name="configureServices">An optional method to configure additional application services.</param>
 /// <returns>
 /// The test application to use for authentication.
 /// </returns>
 protected WebApplicationFactory <Program> CreateTestServer(Action <IServiceCollection>?configureServices = null)
 => ApplicationFactory.CreateApplication(this, configureServices);