public InfoPlusResponse OnActionClicking(InfoPlusEvent e) { string method = string.Format("OnStep{0}Action{1}Clicking", AbstractMessenger.ToFirstUpper(e.Step.StepCode), AbstractMessenger.ToFirstUpper(e.ActionCode)); return(this.CallEventMethodWrapper(method, e)); }
public InfoPlusResponse OnStepWithdrawn(InfoPlusEvent e) { if (string.IsNullOrEmpty(e.ActionCode)) { string method = string.Format("OnStep{0}Withdrawn", AbstractMessenger.ToFirstUpper(e.Step.StepCode)); return(this.CallEventMethodWrapper(method, e)); } else { string method = string.Format("OnStep{0}Action{1}Withdrawn", AbstractMessenger.ToFirstUpper(e.Step.StepCode), AbstractMessenger.ToFirstUpper(e.ActionCode)); return(this.CallEventMethodWrapper(method, e)); } }
public InfoPlusResponse OnActionDone(InfoPlusEvent e) { var methods = new List <string>(); var stepCode = AbstractMessenger.ToFirstUpper(e.Step.StepCode); var actionCode = AbstractMessenger.ToFirstUpper(e.ActionCode); methods.Add(string.Format("OnStep{0}Action{1}Done", stepCode, actionCode)); if (null != e.NextSteps) { foreach (var step in e.NextSteps) { methods.Add(string.Format("ToStep{0}Done", AbstractMessenger.ToFirstUpper(step.StepCode))); } } if (null != e.EndStep) { methods.Add(string.Format("ToStep{0}Done", AbstractMessenger.ToFirstUpper(e.EndStep.StepCode))); } bool called = false; var response = this.Update(e); foreach (string method in methods) { var r2 = this.CallEventMethod(method, e); if (null != r2) { called = true; response += r2; } } if (false == called) { System.Diagnostics.Trace.WriteLine("All Methods in (" + string.Join(",", methods.ToArray()) + ") are not found."); } return(response); }
public object Create(object parent, object configContext, XmlNode section) { lock (_lock) { // 1. Parse services we invoke. var nodes = section.SelectNodes("services"); string serviceId = (string)this.parseAttribute <string>(nodes[0], "identification", null); // default domain ApplicationSettings._DEFAULT_DOMAIN = (string)this.parseAttribute <string>(nodes[0], "domain", "localhost"); // auth endpoint string _AuthEndPoint = (string)this.parseAttribute <string>(nodes[0], "authorize", null); // for "Insecure" sevice type only ApplicationSettings._INFOPLUS_MAGIC = (string)this.parseAttribute <string>(nodes[0], "secret", "INFOPLUS_MAGIC"); // service type var typeAttr = nodes[0].Attributes["type"]; ApplicationSettings._ServiceType = ServiceType.Entitle; var sType = null == typeAttr ? string.Empty : typeAttr.Value; if (Enum.IsDefined(typeof(ServiceType), sType)) { ApplicationSettings._ServiceType = (ServiceType)Enum.Parse(typeof(ServiceType), sType, true); } nodes = section.SelectNodes("services/service"); SERVICES = new List <EndPointDescription>(); foreach (XmlNode s in nodes) { EndPointDescription ep = new EndPointDescription(); ep.Identification = serviceId; ep.Address = s.Attributes["address"].Value; SERVICES.Add(ep); if ((bool)this.parseAttribute <bool>(nodes[0], "trustAllCert", false)) { ServicePointManager.ServerCertificateValidationCallback = TrustAllCertHandler; } } // let's choose one. int i = DICE.Next(ApplicationSettings.SERVICES.Count); ApplicationSettings.SERVICE = ApplicationSettings.SERVICES[i]; // 2. Parse messengers we provide. nodes = section.SelectNodes("messengers"); // compatable 1 if (null == nodes || nodes.Count == 0) { nodes = section.SelectNodes("workflows/workflow"); } ApplicationSettings.MESSENGERS = new List <AbstractMessenger>(); foreach (XmlNode ms in nodes) { string subscriber = (string)this.parseAttribute <string>(ms, "address", null); bool requireVerification = (bool)this.parseAttribute <bool>(ms, "requireVerification", true); var code = (string)this.parseAttribute <string>(ms, "code", null); var secret = (string)this.parseAttribute <string>(ms, "secret", null); var scope = (string)this.parseAttribute <string>(ms, "scope", null); var release = (bool)this.parseAttribute <bool>(ms, "release", true); var minVersion = (long)this.parseAttribute <long>(ms, "minVersion", 0); var maxVersion = (long)this.parseAttribute <long>(ms, "maxVersion", long.MaxValue); // compatable 2 if (string.IsNullOrEmpty(code) && ApplicationSettings.ServiceType != ServiceType.Entitle) { throw new ConfigurationErrorsException("workflow code is not set.", ms); } InfoPlusApplication app = null; if (null != code) { app = new InfoPlusApplication(code, secret, scope, _AuthEndPoint, release, minVersion, maxVersion); ApplicationSettings.workflows[app.FullCode] = app; } foreach (XmlNode m in ms) { string type = m.Attributes["type"].Value; InfoPlusApplication appOverride = null; var code2 = (string)this.parseAttribute <string>(m, "workflow", null); var secret2 = (string)this.parseAttribute <string>(m, "secret", null); var scope2 = (string)this.parseAttribute <string>(m, "scope", null); var release2 = (bool)this.parseAttribute <bool>(m, "release", true); var minVersion2 = (long)this.parseAttribute <long>(m, "minVersion", 0); var maxVersion2 = (long)this.parseAttribute <long>(m, "maxVersion", long.MaxValue); if (false == string.IsNullOrEmpty(code2)) { appOverride = new InfoPlusApplication(code2, secret2, scope2, _AuthEndPoint, release2, minVersion2, maxVersion2); ApplicationSettings.workflows[appOverride.FullCode] = appOverride; } if (null == app && null == appOverride) { throw new ConfigurationErrorsException("app not set.", ms); } // Cache timeout int timeout = (int)this.parseAttribute <int>(m, "timeout", 0); if (timeout < 0) { timeout = 10; } if (string.IsNullOrEmpty(subscriber)) { continue; } string[] splits = type.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);; string assembly = "App_Code"; if (splits.Length > 1) { assembly = splits[1]; } AbstractMessenger messenger = (AbstractMessenger)Assembly.Load(assembly).CreateInstance(splits[0]); messenger.Subscriber = subscriber; messenger.Workflow = app ?? appOverride; messenger.RequireVerification = requireVerification; messenger.Timeout = timeout; ApplicationSettings.MESSENGERS.Add(messenger); System.Diagnostics.Trace.WriteLine("Create messenger:" + type); } } // 3.Mashups nodes = section.SelectNodes("mashups"); mashups = new Dictionary <string, string>(); foreach (XmlNode ms in nodes) { string bs = ms.Attributes["base"].Value; foreach (XmlNode m in ms) { string key = m.Attributes["key"].Value; string val = m.Attributes["value"].Value; mashups[key] = bs + val; } } // return nothing. we'v already saved this section to ApplicationSettings. return(null); } }
public InfoPlusResponse OnStepExpired(InfoPlusEvent e) { string method = string.Format("OnStep{0}Expired", AbstractMessenger.ToFirstUpper(e.Step.StepCode)); return(this.CallEventMethodWrapper(method, e)); }
/// <summary> /// Check verify here and return Application that send the request. /// null if parameter invalid. /// </summary> ResponseEntity CheckParameters(AbstractMessenger messenger, string verify, string version, params object[] args) { string log = "[Subscriber][OnEvent]"; bool valid = false; string details = string.Empty; try { /* * try * { * System.Diagnostics.StackTrace stack = new System.Diagnostics.StackTrace(); * log += "["; * log += (stack.FrameCount > 1 ? stack.GetFrame(1).GetMethod().Name : "Unknown Method"); * log += "]Called with parameters:"; * log += string.Format("version:{0},apikey:{1},args:{2}", version, verify, * string.Join(",", args.Select(a => (null == a) ? "null" : a.ToString()).ToArray())); * } * catch { } */ switch (ApplicationSettings.ServiceType) { case ServiceType.Entitle: throw new NotSupportedException("Entitle ATK dependence removed since 2017/10/18"); /* * string key = SJTU.SJTURight.ApplicationToolkit.EntitleServices.ClientKey; * ServerTicket ticket = new ServerTicket(key, this.Context.Request.UserHostAddress); * * string reason; * Invoker invoker = ticket.Validate(verify, (int)ValidateLevels.Expire, out reason, args); * * details = string.Format("expire:{0}|clientId:{1}|clientIP:{2}|session:{3}|reason:{4}", * invoker.ExpireStamp, invoker.InvokerId, invoker.InvokerIP, invoker.SessionKey, reason); * * valid = invoker.IsValid; * break; */ case ServiceType.OAuth2: var authorization = HttpContext.Current.Request.Headers["Authorization"]; verify = ApplicationSettings.StringCut(authorization, "response=\"", "\""); var method = HttpContext.Current.Request.HttpMethod; var uri1 = ApplicationSettings.StringCut(authorization, "uri=\"", "\"");; /* uri check is useless, disable it, by marstone * var uri2 = HttpContext.Current.Request.Url.AbsoluteUri; * if (false == uri2.Equals(uri1, StringComparison.CurrentCultureIgnoreCase)) * { * valid = false; * details = string.Format("expectUri:{0},actualUri:{1}", uri2, uri1); * break; * } */ var nonce = ApplicationSettings.StringCut(authorization, "nonce=\"", "\""); if (null == nonce || this.nonceCache.Contains(nonce)) { valid = false; details = string.Format("nonce '{0}' invalid or replayed.", nonce); break; } var now = DateTime.Now; var future = now.AddMinutes(20); var index = nonce.LastIndexOf('-'); if (index > 0) { var timeStr = nonce.Substring(index + 1); int timestamp; if (true == int.TryParse(timeStr, out timestamp)) { var then = UnixTime.ToDateTime(timestamp); var timespan = now - then; if ((-DEVIATION) >= timespan.TotalMinutes || timespan.TotalMinutes > DEVIATION) { valid = false; details = string.Format("expectTime:{0},actualTime:{1}", now, then); break; } } } // We calcuate use UTF-8 encoding, // however it's a shortcoming that RFC didn't defines the encoding for Http Basic Auth Digest. var expect = messenger.Workflow.CalculateDigest(method, uri1, nonce); valid = expect.Equals(verify, StringComparison.CurrentCultureIgnoreCase); if (valid) { // cache nonce var policy = new CacheItemPolicy(); policy.AbsoluteExpiration = now.AddMinutes(20); this.nonceCache.Add(nonce, string.Empty, policy); } details = string.Format("expect:{0},actual:{1}", expect, verify); break; } log += (valid ? "[Authenticated successfully]:" : "[Authenticated FAILED]:"); log += string.Format("auth:[{0}]", details); return(new ResponseEntity(valid ? 0 : 1, log)); } catch (Exception ex) { valid = false; System.Diagnostics.Debug.WriteLine(ex.Message); log += string.Format("[Exception][{0}]", ex.Message); return(new ResponseEntity(-1, log)); } finally { System.Diagnostics.Trace.WriteLine(log); } }