Exemplo n.º 1
0
        public static T DoWebCallString <T>(Uri uri, bool upload, string payload, WebHeaderCollection headers, out bool error, NLogLogger myLogger, bool ignoreResponse = false)
        {
            error = false;
            var webClient        = new CoudSuiteWebClient();
            var progressSettings = new ProgressConfiguration();

            for (var index = 0; index < headers.Count; index++)
            {
                webClient.Headers.Add(headers.AllKeys[index], headers[index]);
            }
            if (progressSettings.InforOverrideHttps)
            {
                myLogger.Trace("Over-riding HTTPS errors");
                ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
            }
            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
            try
            {
                var response = upload ? webClient.UploadString(uri, payload) : webClient.DownloadString(uri);
                return(ignoreResponse ? default(T) : JsonConvert.DeserializeObject <T>(response));
            }
            catch (Exception ex)
            {
                myLogger.ErrorException("Web Call Failed", ex);
                error = true;
            }
            finally
            {
                webClient.Dispose();
            }
            return(default(T));
        }
Exemplo n.º 2
0
 private PSStyle()
 {
     Formatting = new FormattingData();
     Progress   = new ProgressConfiguration();
     Foreground = new ForegroundColor();
     Background = new BackgroundColor();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                var progressConfiguration = new ProgressConfiguration();

                var properties = RunTimeProperties.GetStaticProperties();
                if (properties.SessionModel == SessionModelConstants.SessionManaged || progressConfiguration.InforProgressOwnsConnection)
                {
                    // Get a new instance of the Connection object each time
                    kernel.Bind <Connection>()
                    .To <Connection>()
                    .WithConstructorArgument(RunTimeProperties.GetStaticProperties());
                }
                else
                {
                    // This registration causes the Connection to act as a Pool and stays around for the lifetime of the application
                    kernel.Bind <Connection>()
                    .To <Connection>()
                    .InSingletonScope()
                    .WithConstructorArgument(RunTimeProperties.GetStaticProperties());
                }

                kernel.Bind(scanner => scanner.FromAssembliesMatching("General.Business.dll")
                            .SelectAllClasses()
                            .InheritedFrom <IService>().BindDefaultInterfaces());

                kernel.Bind(scanner => scanner.FromAssembliesMatching("Infor.Sxe.*.Data.dll")
                            .SelectAllClasses()
                            .InheritedFrom <IRepository>().BindDefaultInterfaces());

                RegisterServices(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
Exemplo n.º 4
0
        public static string Generate(NLogLogger myLogger)
        {
            if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return("");
            }
            var myprincipal = System.Web.HttpContext.Current.User as ServiceInterfacePrincipal;

            if (myprincipal?.TokenObject == null || myprincipal?.TokenObject.SessionidGuid == Guid.Empty)
            {
                return("");
            }
            var progressSettings = new ProgressConfiguration();

            if (string.IsNullOrEmpty(progressSettings.ApplicationEncryptKey) ||
                string.IsNullOrEmpty(progressSettings.ApplicationEncryptIv))
            {
                myLogger.Error("Encrypt Key and/or Encrypt IV are empty, the application will not operate.  Ensure they are set in the web.config");
                return("");
            }
            return(ApplicationCookieUtilities.ObjectToToken(myprincipal.TokenObject, progressSettings.ApplicationEncryptKey, progressSettings.ApplicationEncryptIv));
        }
Exemplo n.º 5
0
        private void DoBusinessRules(LoginResponseModel loginResponseModel)
        {
            if (loginResponseModel.Success)
            {
                string myhost;
                var    progressConfiguration = new ProgressConfiguration();
                var    tokenObject           = ApplicationCookieUtilities.Principal(HttpContext.Current.User, out myhost);
                this.rules = this.businessRules.GetConfigurationAtLogin(tokenObject.Cono);
                if (this.rules.Any())
                {
                    tokenObject.IdmConsumerKey  = progressConfiguration.InforIdmConsumerKey;
                    tokenObject.IdmSharedSecret = progressConfiguration.InforIdmSharedSecret;
                    tokenObject.InforIdmCacheExpirationAbsolute = progressConfiguration.InforIdmCacheExpirationAbsolute;

                    tokenObject.IdmUrl                         = this.ReturnRuleValue <string>("Infor.Webui-IDMUrl");
                    tokenObject.IonApiUrl                      = this.ReturnRuleValue <string>("Infor.Webui-IonApiUrl");
                    tokenObject.DefaultRecordLimit             = this.ReturnRuleValue <int>("Infor.Webui-UserSettings.DefaultRecordLimit");
                    tokenObject.ReportRecordLimit              = this.ReturnRuleValue <int>("Infor.Webui-UserSettings.ReportRecordLimit");
                    tokenObject.LookupMaxResults               = this.ReturnRuleValue <int>("Infor.Webui-UserSettings.LookupMaxResults");
                    loginResponseModel.DefaultRecordLimit      = this.ReturnRuleValue <int>("Infor.Webui-UserSettings.DefaultRecordLimit");
                    loginResponseModel.ReportRecordLimit       = this.ReturnRuleValue <int>("Infor.Webui-UserSettings.ReportRecordLimit");
                    loginResponseModel.LookupMaxResults        = this.ReturnRuleValue <int>("Infor.Webui-UserSettings.LookupMaxResults");
                    loginResponseModel.SuppressBusinessContext = this.ReturnRuleValue <bool>("Infor.Webui-Messaging.SuppressinforBusinessContext");
                    loginResponseModel.RestAccessUrl           = this.ReturnRuleValue <string>("Infor.Webui-RESTAccessURL");
                    loginResponseModel.PendoApiKey             = this.ReturnRuleValue <string>("Infor.Webui-PendoApiKey");
                    loginResponseModel.TryAndBuy               = this.ReturnRuleValue <string>("Infor.Webui-TryAndBuy");
                    loginResponseModel.ShowImages              = this.ReturnRuleValue <bool>("Infor.Webui-IDMShowImages");
                    loginResponseModel.CallRetryDelay          = this.ReturnRuleValue <int>("Infor.Webui-CallRetryDelay");
                    loginResponseModel.CallRetryLimit          = this.ReturnRuleValue <int>("Infor.Webui-CallRetryLimit");
                    tokenObject.RestAccessUrl                  = loginResponseModel.RestAccessUrl;
                }
                else
                {
                    _nLogLogger.Error("No Business Rules where returned - SASBRLoad - [category = CONFIG, nodenm = Infor.Webui]. The application will not perform correctly");
                }
            }
        }
Exemplo n.º 6
0
        public static string GetBearerToken(ILogger nLogger)
        {
            string bearerToken = null;

            nLogger?.Info("Begin GetBearerToken");

            //don't block login from completing if call fails
            try
            {
                var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
                var context         = (BootstrapContext)claimsPrincipal?.Identities.First().BootstrapContext;
                nLogger?.Info("Starting harvesting of OAuth2 token");
                if (context == null)
                {
                    nLogger?.Error("context is null");
                }
                var contextSecurityToken = context?.SecurityToken;
                if (contextSecurityToken == null)
                {
                    nLogger?.Info("context?.SecurityToken is null");
                }
                if (string.IsNullOrEmpty(context?.Token))
                {
                    nLogger?.Info("context?.Token is null or empty");
                }

                SecurityToken finalToken;

                if (contextSecurityToken == null && !string.IsNullOrEmpty(context?.Token))
                {
                    var handlers =
                        FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;
                    finalToken = handlers.ReadToken(new XmlTextReader(new StringReader(context.Token)));
                    if (finalToken == null)
                    {
                        nLogger?.Error("handlers security token is null");
                    }
                }
                else
                {
                    finalToken = contextSecurityToken;
                }

                var    progressConfiguration = new ProgressConfiguration();
                var    oauth = new OAuthBase();
                string rpEndpoint;
                string appliesTo;
                var    localTokenType = progressConfiguration.InforIonApiTokenType;
                nLogger?.Info($"localTokenType - {localTokenType}");

                var issuer = FederatedAuthentication.FederationConfiguration.WsFederationConfiguration.Issuer;
                nLogger?.Info($"issuer - {issuer}");

                //on-prem install
                if (issuer.Contains("adfs"))
                {
                    nLogger?.Info("contains adfs");
                    rpEndpoint = progressConfiguration.InforIonApiRpEndpoint;
                    appliesTo  = progressConfiguration.InforIonApiAppliesToEndpoint;
                    nLogger?.Info($"rpEndpoint - {rpEndpoint}");
                    nLogger?.Info($"appliesTo - {appliesTo}");
                }
                //ce install
                else
                {
                    nLogger?.Info("ce");
                    var uri     = new Uri(issuer);
                    var baseUri = uri.GetLeftPart(UriPartial.Authority);
                    nLogger?.Info($"baseUri - {baseUri}");
                    rpEndpoint = baseUri + progressConfiguration.InforIonApiRpEndpoint;
                    appliesTo  = baseUri + progressConfiguration.InforIonApiAppliesToEndpoint;
                    nLogger?.Info($"rpEndpoint - {rpEndpoint}");
                    nLogger?.Info($"appliesTo - {appliesTo}");
                }

                if (finalToken != null)
                {
                    var xmlTokenOauthToken =
                        (GenericXmlSecurityToken)
                        oauth.IssueOAuth2SecurityToken(finalToken, rpEndpoint, appliesTo, localTokenType,
                                                       out var rstr);
                    if (xmlTokenOauthToken != null)
                    {
                        var base64Token = xmlTokenOauthToken.TokenXml?.InnerText;
                        if (!string.IsNullOrEmpty(base64Token))
                        {
                            nLogger?.Info($"base64Token - {base64Token}");
                            var data = Convert.FromBase64String(base64Token);
                            nLogger?.Info($"data - {data}");
                            bearerToken = Encoding.UTF8.GetString(data);
                        }
                        else
                        {
                            nLogger?.Info("base64Token is empty");
                        }
                    }
                }
                else
                {
                    nLogger?.Info("Token Empty - Will not process further");
                }
            }
            catch (Exception e)
            {
                nLogger?.ErrorException("GetBearerToken", e);
            }
            nLogger?.Info("End GetBearerToken");
            return(bearerToken);
        }
Exemplo n.º 7
0
 public AoSharedService(ProgressConfiguration progressConfiguration)
 {
     this._progressConfiguration = progressConfiguration;
 }