using System; using System.Configuration; using System.Data; using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Reflection; using System.Security.Claims; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using System.Web.Mvc; using Hangfire; using IdentityModel; using Kreta.BusinessLogic; using Kreta.BusinessLogic.Helpers; using Kreta.BusinessLogic.Helpers.SystemSettings; using Kreta.BusinessLogic.Utils; using Kreta.Client.CoreApi.Configuration; using Kreta.Client.Eugyintezes; using Kreta.Client.Eugyintezes.Configuration; using Kreta.Client.KGR.Configuration; using Kreta.Client.Leltar.Configuration; using Kreta.Client.SzirApi.Configuration; using Kreta.Core; using Kreta.Core.Configuratiaton; using Kreta.Core.Configuratiaton.Interface; using Kreta.Core.Elearning.Nexius; using Kreta.Core.FeatureToggle; using Kreta.Core.FeatureToggle.Configuration; using Kreta.Core.FileService; using Kreta.Core.FileService.Configuration; using Kreta.Core.KIR.Factory; using Kreta.Core.KIR.Factory.Interface; using Kreta.Core.KIR.Infrastructure.Interface; using Kreta.Core.Logic; using Kreta.Core.SAP; using Kreta.Job.Tasks; using Kreta.Job.Tasks.Core; using Kreta.Web.Classes; using Kreta.Web.Configuration; using Kreta.Web.HangfireJobActivator; using Kreta.Web.Helpers; using Kreta.Web.Logger; using Kreta.Web.Logging.Logger; using Kreta.Web.Security; using Microsoft.AspNet.Identity; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.Owin; using Microsoft.Owin.Host.SystemWeb; using Microsoft.Owin.Security; using Microsoft.Owin.Security.Cookies; using Microsoft.Owin.Security.Notifications; using Microsoft.Owin.Security.OpenIdConnect; using Newtonsoft.Json; using Owin; using SimpleInjector; using SimpleInjector.Integration.Web.Mvc; using SimpleInjector.Integration.WebApi; using CoreConstants = Kreta.Core.Constants; using HangfireGlobalConfiguration = Hangfire.GlobalConfiguration; using HttpGlobalConfiguration = System.Web.Http.GlobalConfiguration; using Poszeidon = Kreta.Core.Iktato.Poszeidon; [assembly: OwinStartup(typeof(Kreta.Web.App_Start.Startup))] namespace Kreta.Web.App_Start { public class Startup { public void Configuration(IAppBuilder app) { log4net.Config.XmlConfigurator.Configure(); var idpConfiguration = (IdpConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.IdpConfiguration); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, CookieName = "kreta.application", CookieSecure = CookieSecureOption.Always, CookieSameSite = SameSiteMode.None }); if (idpConfiguration.LoginEnabled) { var openIdConnectAuthenticationOptions = new OpenIdConnectAuthenticationOptions { SignInAsAuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, Authority = idpConfiguration.Authority, ClientId = idpConfiguration.ClientId, //ClientSecret = "secret", Scope = idpConfiguration.Scope, //RequireHttpsMetadata = false, UseTokenLifetime = false, RedeemCode = true, //SaveTokens = true, ResponseType = OpenIdConnectResponseType.Code, ResponseMode = OpenIdConnectResponseMode.FormPost, CookieManager = new SecureCookieManager(new SystemWebCookieManager()), Notifications = new OpenIdConnectAuthenticationNotifications { RedirectToIdentityProvider = n => { string instituteCode = CommonUtils.GetOrganizationIdentifier(); if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication) { string encodedInstituteData = GetEncodedInstituteData(); if (idpConfiguration.RequirePkce) { // generate code verifier and code challenge string codeVerifier = CryptoRandom.CreateUniqueId(32); string codeChallenge; using (var sha256 = SHA256.Create()) { byte[] challengeBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(codeVerifier)); codeChallenge = Base64Url.Encode(challengeBytes); } // set code_challenge parameter on authorization request n.ProtocolMessage.SetParameter("code_challenge", codeChallenge); n.ProtocolMessage.SetParameter("code_challenge_method", "S256"); // remember code_verifier (adapted from OWIN nonce cookie) RememberCodeVerifier(n, codeVerifier); } n.ProtocolMessage.Parameters["institute_code"] = instituteCode; n.ProtocolMessage.Parameters["institute_data"] = encodedInstituteData; n.ProtocolMessage.Prompt = OpenIdConnectPrompt.Login; n.ProtocolMessage.RedirectUri = string.Format(idpConfiguration.RedirectUri, instituteCode); } else if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.Logout) { string idToken = n.OwinContext.Authentication.User.FindFirst("id_token")?.Value; n.ProtocolMessage.IdTokenHint = idToken; n.ProtocolMessage.PostLogoutRedirectUri = string.Format(idpConfiguration.PostLogoutRedirectUri, instituteCode); } return Task.CompletedTask; }, //MessageReceived = n => //{ // return Task.CompletedTask; //}, AuthorizationCodeReceived = n => { if (idpConfiguration.RequirePkce) { // get code_verifier string codeVerifier = RetrieveCodeVerifier(n); // attach code_verifier n.TokenEndpointRequest.SetParameter("code_verifier", codeVerifier); } string instituteCode = CommonUtils.GetOrganizationIdentifier(); n.TokenEndpointRequest.RedirectUri = string.Format(idpConfiguration.RedirectUri, instituteCode); return Task.CompletedTask; }, //SecurityTokenReceived = n => //{ // return Task.CompletedTask; //}, //SecurityTokenValidated = n => //{ // return Task.CompletedTask; //}, TokenResponseReceived = n => { var accessToken = new JwtSecurityToken(n.TokenEndpointResponse.AccessToken); string instituteCode = CommonUtils.GetOrganizationIdentifier(); string instituteCodeFromToken = accessToken.Claims.FirstOrDefault(c => c.Type == "kreta:institute_code")?.Value; if (!string.Equals(instituteCode, instituteCodeFromToken, StringComparison.InvariantCultureIgnoreCase)) { throw new Exception($"A tokenben szereplő intézmény ({instituteCodeFromToken}) és az aktuális intézmény ({instituteCode}) nem egyezik!"); } string userNameFromToken = accessToken.Claims.First(c => c.Type == "kreta:user_name").Value; string GetClientIP() { var clientIp = n.Request.RemoteIpAddress.Trim(); try { var xForwardedFor = n.Request.Headers["X-Forwarded-For"]; if (!string.IsNullOrWhiteSpace(xForwardedFor)) { clientIp = xForwardedFor; } return clientIp; } catch { return clientIp; } } using (var loginManager = new LoginManager()) { ClaimsIdentity claimsIdentity = loginManager.LoginByIdp(userNameFromToken, GetClientIP()); claimsIdentity.AddClaim(new Claim("id_token", n.TokenEndpointResponse.IdToken)); n.OwinContext.Authentication.AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(claimsIdentity), new AuthenticationProperties() { IsPersistent = false }); // ha IsPersistent true akkor belépve marad a felhasználó } // Dashboard popup üzenetekhez: var popupCookie = new System.Web.HttpCookie("DisplayedPopups") { HttpOnly = true, SameSite = System.Web.SameSiteMode.None, Secure = true }; System.Web.HttpContext.Current.Response.Cookies.Add(popupCookie); return Task.CompletedTask; }, AuthenticationFailed = context => { context.HandleResponse(); KretaServer.KretaServer.Instance.Logger.ExceptionThrown(context.Exception); var urlHelper = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext); context.Response.Redirect(urlHelper.Action("Index", "Home", new { area = string.Empty })); return Task.FromResult(0); } } }; app.UseOpenIdConnectAuthentication(openIdConnectAuthenticationOptions); } var featureContext = FeatureContext.Instance; var container = new Container(); container.Options.DefaultScopedLifestyle = Lifestyle.CreateHybrid(new SimpleInjector.Integration.Web.WebRequestLifestyle(), new SimpleInjector.Lifestyles.AsyncScopedLifestyle()); container.Register(Lifestyle.Transient); container.Register(Lifestyle.Transient); container.Register(Lifestyle.Transient); container.Register(() => (IktatoServiceConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.KretaPoszeidonConfig), Lifestyle.Singleton); container.Register(() => (IktatasJobConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.IktatasJobConfig), Lifestyle.Singleton); container.Register(() => new Poszeidon.Infrastructure.WcfServiceContext() { CorrelationId = Guid.NewGuid().ToString() }, Lifestyle.Scoped); container.Register(Lifestyle.Scoped); container.Register(Lifestyle.Transient); container.Register(Lifestyle.Transient); container.Register(Lifestyle.Transient); container.Register(() => (KretaJobConfig)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.KretaJobConfig), Lifestyle.Singleton); container.Register(() => featureContext, Lifestyle.Singleton); container.Register(Lifestyle.Transient); container.Register(() => (UploadFileValidationConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.UploadFileValidation), Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(() => (NexiusCourseServiceConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.NexiusCourseService), Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Transient); container.Register(() => (EugyintezesClientConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.EugyintezesClientConfiguration), Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Transient); container.Register(() => (FileServiceConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FileServiceConfiguration), Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(() => (SapConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.SapConfiguration), Lifestyle.Singleton); container.Register(Lifestyle.Transient); container.Register(Lifestyle.Transient); container.Register(Lifestyle.Transient); container.Register(() => (KirConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.KirConfiguration), Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(() => idpConfiguration, Lifestyle.Singleton); container.Register(() => (LepConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.LEPKozpontiKretaConfig), Lifestyle.Singleton); container.Register(() => (TananyagtarConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.TananyagtarConfiguration), Lifestyle.Singleton); container.Register(() => (MkbBankszamlaIgenylesConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.MkbBankszamlaIgenylesConfiguration), Lifestyle.Singleton); container.Register(() => (OtpBankszamlaIgenylesConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.OtpBankszamlaIgenylesConfiguration), Lifestyle.Singleton); container.Register(Lifestyle.Transient); container.Register(Lifestyle.Transient); container.Register(() => ConfigurationLogic.GetConfigurationSection(CoreConstants.ConfigurationSectionNames.CoreApiClientConfiguration), Lifestyle.Singleton); container.Register(() => ConfigurationLogic.GetConfigurationSection(CoreConstants.ConfigurationSectionNames.KGRClientConfiguration), Lifestyle.Singleton); container.Register(() => ConfigurationLogic.GetConfigurationSection(CoreConstants.ConfigurationSectionNames.LeltarClientConfiguration), Lifestyle.Singleton); container.Register(() => ConfigurationLogic.GetConfigurationSection(CoreConstants.ConfigurationSectionNames.SzirApiClientConfiguration), Lifestyle.Singleton); container.Register(Lifestyle.Transient); container.Register(Lifestyle.Transient); container.Register(() => (EESZTConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.EESZTConfig), Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(() => (FirebaseConfiguration)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FirebaseConfiguration), Lifestyle.Singleton); container.Register(Lifestyle.Transient); container.Register(Lifestyle.Transient); container.Register(() => TraceLoggerFactory.Create(System.Web.HttpContext.Current), Lifestyle.Scoped); container.InjectBusinessLogic(); container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); container.RegisterWebApiControllers(HttpGlobalConfiguration.Configuration); container.Verify(); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); HttpGlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container); HangfireLogger.SerilogGlobalConfiguration(); HangfireGlobalConfiguration.Configuration.UseActivator(new ContainerJobActivator(container)); HangfireGlobalConfiguration.Configuration.UseSqlServerStorage(Core.Constants.General.HangfireConnectionString); HangfireGlobalConfiguration.Configuration.UseSerilogLogProvider(); app.UseHangfireDashboard(); if (featureContext.IsEnabled(Core.Constants.FeatureName.HangfireServer)) { app.UseHangfireServer(); } var sendErtekelesNotificationFeature = new SendErtekelesNotificationFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (sendErtekelesNotificationFeature.IsEnabled) { RecurringJob.AddOrUpdate("ErtekelesPush", n => n.SendErtekelesNotification(), GetCronMinuteIntervalWithStartAndEndHour(sendErtekelesNotificationFeature.SendItervalInMinute, sendErtekelesNotificationFeature.RunningIntervalStartHour, sendErtekelesNotificationFeature.RunningIntervalEndHour)); } else { RecurringJob.RemoveIfExists("ErtekelesPush"); } var sendHazifeladatNotificationFeature = new SendHazifeladatNotificationFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (sendHazifeladatNotificationFeature.IsEnabled) { RecurringJob.AddOrUpdate("HazifeladatPush", n => n.SendHazifeladatNotification(), GetCronMinuteIntervalWithStartAndEndHour(sendHazifeladatNotificationFeature.SendItervalInMinute, sendHazifeladatNotificationFeature.RunningIntervalStartHour, sendHazifeladatNotificationFeature.RunningIntervalEndHour)); } else { RecurringJob.RemoveIfExists("HazifeladatPush"); } var sendRendszerUzenetNotificationFeature = new SendRendszerUzenetNotificationFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (sendRendszerUzenetNotificationFeature.IsEnabled) { RecurringJob.AddOrUpdate("RendszerUzenetPush", n => n.SendRendszerUzenetNotification(), GetCronMinuteIntervalWithStartAndEndHour(sendRendszerUzenetNotificationFeature.SendItervalInMinute, sendRendszerUzenetNotificationFeature.RunningIntervalStartHour, sendRendszerUzenetNotificationFeature.RunningIntervalEndHour)); } else { RecurringJob.RemoveIfExists("RendszerUzenetPush"); } var sendMulasztasNotificationFeature = new SendMulasztasNotificationFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (sendMulasztasNotificationFeature.IsEnabled) { RecurringJob.AddOrUpdate("MulasztasPush", n => n.SendMulasztasNotification(), GetCronMinuteIntervalWithStartAndEndHour(sendMulasztasNotificationFeature.SendItervalInMinute, sendMulasztasNotificationFeature.RunningIntervalStartHour, sendMulasztasNotificationFeature.RunningIntervalEndHour)); } else { RecurringJob.RemoveIfExists("MulasztasPush"); } var sendBejelentettSzamonkeresNotificationFeature = new SendBejelentettSzamonkeresNotificationFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (sendBejelentettSzamonkeresNotificationFeature.IsEnabled) { RecurringJob.AddOrUpdate("BejelentettSzamonkeresPush", n => n.SendBejelentettSzamonkeresNotification(), GetCronMinuteIntervalWithStartAndEndHour(sendBejelentettSzamonkeresNotificationFeature.SendItervalInMinute, sendBejelentettSzamonkeresNotificationFeature.RunningIntervalStartHour, sendBejelentettSzamonkeresNotificationFeature.RunningIntervalEndHour)); } else { RecurringJob.RemoveIfExists("BejelentettSzamonkeresPush"); } var sendFeljegyzesNotificationFeature = new SendFeljegyzesNotificationFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (sendFeljegyzesNotificationFeature.IsEnabled) { RecurringJob.AddOrUpdate("FeljegyzesPush", n => n.SendFeljegyzesNotification(), GetCronMinuteIntervalWithStartAndEndHour(sendFeljegyzesNotificationFeature.SendItervalInMinute, sendFeljegyzesNotificationFeature.RunningIntervalStartHour, sendFeljegyzesNotificationFeature.RunningIntervalEndHour)); } else { RecurringJob.RemoveIfExists("FeljegyzesPush"); } var sendKozelgoFogadooraMailFeature = new SendKozelgoFogadooraMailFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (sendKozelgoFogadooraMailFeature.IsEnabled) { RecurringJob.AddOrUpdate("KozelgoFogadooraMail", n => n.SendKozelgoFogadooraMail(), Cron.Daily(8, 0)); } else { RecurringJob.RemoveIfExists("KozelgoFogadooraMail"); } var sendNemNaplozottTanorakMailFeature = new SendNemNaplozottTanorakMailFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (sendNemNaplozottTanorakMailFeature.IsEnabled) { RecurringJob.AddOrUpdate("SendNemNaplozottTanorakMail", n => n.SendNemNaplozottTanorakMail(), sendNemNaplozottTanorakMailFeature.CustomCronExpression); } else { RecurringJob.RemoveIfExists("SendNemNaplozottTanorakMail"); } var sendOrarendValtozasNotificationFeature = new SendOrarendValtozasNotificationFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (sendOrarendValtozasNotificationFeature.IsEnabled) { RecurringJob.AddOrUpdate("OrarendValtozasPush", n => n.SendOrarendValtozasNotification(null), sendOrarendValtozasNotificationFeature.CustomCronExpression); } else { RecurringJob.RemoveIfExists("OrarendValtozasPush"); } var deleteInvalidLinks = new DeleteInvalidLinksFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (deleteInvalidLinks.IsEnabled) { RecurringJob.AddOrUpdate("DeleteInvalidLinks", n => n.DeleteInvalidLinks(), Cron.Weekly(DayOfWeek.Sunday, 03, 30)); } else { RecurringJob.RemoveIfExists("DeleteInvalidLinks"); } var updateCOVIDFlag = new UpdateCOVIDFlagFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (updateCOVIDFlag.IsEnabled) { RecurringJob.AddOrUpdate("UpdateCOVIDFlag", n => n.UpdateCOVIDFlag(), Cron.Daily(1, 0)); } else { RecurringJob.RemoveIfExists("UpdateCOVIDFlag"); } var sapSync = new sapSyncFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (sapSync.IsEnabled) { RecurringJob.RemoveIfExists("SapTavolletSync"); //El lesz távolítva... //RecurringJob.AddOrUpdate("SapTavolletSync", n => n.SyncJobKeretEsTavollet(), Cron.Weekly(DayOfWeek.Saturday, 02)); RecurringJob.AddOrUpdate("TavolletDokSync", n => n.SyncTavolletIktatott(), Cron.MinuteInterval(15)); RecurringJob.AddOrUpdate("SendOutTavolletReminderEmails", n => n.SendOutTavolletReminderEmails(), Cron.Monthly(25)); } else { RecurringJob.RemoveIfExists("SapTavolletSync"); RecurringJob.RemoveIfExists("TavolletDokSync"); } RecurringJob.AddOrUpdate("SzakkepzesiJuttatasUpdate", n => n.UpdateSzakkepzesiJuttatasok(), Cron.Monthly(16)); //jöhetne ez a 4-es konfigból esetleg :) RecurringJob.AddOrUpdate("ConnectionStringCacheSync", n => n.ResetAllConnectionString(), Cron.Daily(4)); // RecurringJob.AddOrUpdate("SendFogadooraNotification", n => n.SendFogadooraNotification(), Cron.Daily(1, 0)); if (featureContext.IsEnabled(Core.Constants.FeatureName.EESZTInterfaceUsage)) { RecurringJob.AddOrUpdate("EESZTInterfaceJob", x => x.GetEESZTAllomany(), Cron.Daily(1, 0)); } else { RecurringJob.RemoveIfExists("EESZTInterfaceJob"); } if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/bin/Aspose.Total.lic"))) { Aspose.Pdf.License license = new Aspose.Pdf.License(); license.SetLicense("Aspose.Total.lic"); Aspose.Cells.License licenseCells = new Aspose.Cells.License(); licenseCells.SetLicense("Aspose.Total.lic"); Aspose.Words.License licenseWords = new Aspose.Words.License(); licenseWords.SetLicense("Aspose.Total.lic"); Aspose.BarCode.License barCodeLicense = new Aspose.BarCode.License(); barCodeLicense.SetLicense("Aspose.Total.lic"); } var mkbBankszamlaIgenyles = new MkbBankszamlaIgenylesFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (mkbBankszamlaIgenyles.IsEnabled) { RecurringJob.AddOrUpdate("MkbBankszamlaIgenylesJob", n => n.MkbBankszamlaIgenyles(), Cron.Daily(02, 00)); } else { RecurringJob.RemoveIfExists("MkbBankszamlaIgenylesJob"); } var otpBankszamlaIgenyles = new OtpBankszamlaIgenylesFeature((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (otpBankszamlaIgenyles.IsEnabled) { RecurringJob.AddOrUpdate("OtpBankszamlaIgenylesJob", n => n.OtpBankszamlaIgenyles(), Cron.Daily(03, 30)); } else { RecurringJob.RemoveIfExists("OtpBankszamlaIgenylesJob"); } var updateTanuloDualisSzerzodesei = new UpdateTanuloDualisSzerzodesei((FeatureConfigurationSection)ConfigurationManager.GetSection(CoreConstants.ConfigurationSectionNames.FeatureConfig)); if (updateTanuloDualisSzerzodesei.IsEnabled) { RecurringJob.AddOrUpdate("UpdateTanuloDualisSzerzodesei", n => n.UpdateTanuloDualisSzerzodesei(), Cron.Daily(00, 00)); } else { RecurringJob.RemoveIfExists("UpdateTanuloDualisSzerzodesei"); } } private void RememberCodeVerifier(RedirectToIdentityProviderNotification n, string codeVerifier) { var properties = new AuthenticationProperties(); properties.Dictionary.Add("cv", codeVerifier); n.Options.CookieManager.AppendResponseCookie( n.OwinContext, GetCodeVerifierKey(n.ProtocolMessage.State), Convert.ToBase64String(Encoding.UTF8.GetBytes(n.Options.StateDataFormat.Protect(properties))), new CookieOptions { SameSite = SameSiteMode.None, HttpOnly = true, Secure = true, //n.Request.IsSecure, Expires = DateTime.UtcNow.AddDays(1) // DateTime.UtcNow + n.Options.ProtocolValidator.NonceLifetime }); } private string RetrieveCodeVerifier(AuthorizationCodeReceivedNotification n) { string key = GetCodeVerifierKey(n.ProtocolMessage.State); string codeVerifierCookie = n.Options.CookieManager.GetRequestCookie(n.OwinContext, key); if (codeVerifierCookie != null) { var cookieOptions = new CookieOptions { SameSite = SameSiteMode.None, HttpOnly = true, Secure = true, //n.Request.IsSecure }; n.Options.CookieManager.DeleteCookie(n.OwinContext, key, cookieOptions); AuthenticationProperties cookieProperties = n.Options.StateDataFormat.Unprotect(Encoding.UTF8.GetString(Convert.FromBase64String(codeVerifierCookie))); cookieProperties.Dictionary.TryGetValue("cv", out var codeVerifier); return codeVerifier; } return null; } private string GetCodeVerifierKey(string state) { using (var hash = SHA256.Create()) { return OpenIdConnectAuthenticationDefaults.CookiePrefix + "cv." + Convert.ToBase64String(hash.ComputeHash(Encoding.UTF8.GetBytes(state))); } } private string GetEncodedInstituteData() { var systemSettingsHelper = new SystemSettingsHelper(ConnectionTypeExtensions.GetOrganizationConnectionType()); var csokkentettGondviseloEnable = systemSettingsHelper .GetSystemSettingValue(Enums.RendszerBeallitasTipusEnum.Csokkentett_gondviselok_kezelese); var intemzenyRovidnevBeallitasa = systemSettingsHelper .GetSystemSettingValue(Enums.RendszerBeallitasTipusEnum.Intezmeny_rovid_nevenek_beallitasa); var intezmenyHelper = new IntezmenyHelper(ConnectionTypeExtensions.GetOrganizationConnectionType()); var loginData = intezmenyHelper.GetOrganizationNameAndCode(); var isSuccessAuthorizedDate = !intezmenyHelper.IsSuccessAuthorizedDate(); string institute_data = JsonConvert.SerializeObject(new { next_update_date_time = new AdminHelper(ConnectionTypeExtensions.GetOrganizationConnectionType()).GetKovTelepitesDatum().ToString("yyyy.MM.dd. HH:mm"), is_szir_institute = loginData.Tables[0].Rows[0].Field("IsSzirIntezmeny_BOOL"), is_licence_valid = (loginData.Tables[0].Rows[0][2].ToString() == "F"), is_archive = loginData.Tables[0].Rows[0].Field("IsArchivIntezmeny_BOOL"), is_csokkentett_gondviselo = csokkentettGondviseloEnable, is_intezmeny_rovidnev = intemzenyRovidnevBeallitasa, is_success_authorized_date = isSuccessAuthorizedDate }); byte[] plainTextBytes = Encoding.UTF8.GetBytes(institute_data); return Convert.ToBase64String(plainTextBytes); } private string GetCronMinuteIntervalWithStartAndEndHour(int interval, int? startHour, int? endHour) { if (startHour.HasValue && endHour.HasValue) { return $"*/{interval} {startHour.Value}-{endHour.Value} * * *"; } return Cron.MinuteInterval(interval); } } }