예제 #1
0
파일: Startup.cs 프로젝트: gacalves/GAC_ERP
        public void Configuration(IAppBuilder app)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel
                .Debug()
                .WriteTo
                .File(AppDomain.CurrentDomain.BaseDirectory + "Logs\\IdentityServerLog" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_" + DateTime.Now.Hour+"-" +DateTime.Now.Minute+"-"+DateTime.Now.Second+ ".txt")
                .CreateLogger();

            var globalConnString = ConfigurationManager.ConnectionStrings[
                ConfigurationManager.AppSettings[ Constantes.AppSettings.IdentityConnStrName]
                ];

            ConfigureAuth(app);

            string idProvider = ConfigurationManager.AppSettings[Constantes.AppSettings.IdentityProvider];

            var idMgrfactory = new IdentityManagerServiceFactory();

            var idSvrFactory = new IdentityServerServiceFactory();

            if(globalConnString!=null) {

                //Seleciona o provedor de identidade correto
                switch(idProvider) {

                    case Constantes.IdentityProviderTypes.AspNetIdentity:

                        Log.Logger.Information("Utilizando o Identity Provider AspNetIdentity.");

                        idMgrfactory.ConfigureIdMgrServiceForAspNetId(globalConnString.ConnectionString);

                        idSvrFactory.ConfigureIdSvrFactoryAspNet(globalConnString.ConnectionString);
                        idSvrFactory.ConfigureAspNetIdUserService(globalConnString.ConnectionString);
                        Log.Logger.Information("Identity Server Configurado.");

                        //Seta o AspNetIdentity como mecanismo de identidade
                        InitializeIdServer(app, globalConnString.ConnectionString, idSvrFactory);
                        Log.Logger.Information("Identity Server Inicializado.");

                        InitializeIdentityManager(app, globalConnString.ConnectionString, idMgrfactory);
                        Log.Logger.Information("Identity Manager configurado e inicializado.");

                        break;

                    case Constantes.IdentityProviderTypes.MembershipReboot:

                        Log.Logger.Information("Utilizando o Identity Provider MembershipReboot.");

                        idMgrfactory.ConfigureIdMgrServiceForMR(globalConnString.ConnectionString);

                        idSvrFactory.ConfigureIdSvrFactoryMR(globalConnString.ConnectionString);
                        idSvrFactory.ConfigureMRUserService(globalConnString.ConnectionString);
                        Log.Logger.Information("Identity Server Configurado.");

                        //Seta o MembershipReboot como mecanismo de identidade
                        InitializeIdServer(app, globalConnString.ConnectionString, idSvrFactory);
                        Log.Logger.Information("Identity Server Inicializado.");

                        InitializeIdentityManager(app, globalConnString.ConnectionString, idMgrfactory);
                        Log.Logger.Information("Identity Manager configurado e inicializado.");

                        break;

                    default:
                        Log.Logger.Fatal("Identity porvider: {0} é desconhecido. \nVerfique a chave {1} no seu Web.config.",
                            idProvider, Constantes.AppSettings.IdentityProvider);
                        break;
                }
            }
            else {
                Log.Logger.Fatal("A Connection String não foi configurada corretamente.\nVerifique no Web.config se há uma connection string com o mesmo nome especificado na chave {0} e se esta connection String é válida.", Constantes.AppSettings.IdentityConnStrName);
            }
        }