private static void RestTrace(HttpWebRequest webRequest, byte[] body) { var sb = new StringBuilder(); sb.AppendFormat("request:\n"); sb.AppendLine(); sb.AppendFormat("{0}:{1}", webRequest.Method, webRequest.RequestUri.AbsoluteUri); sb.AppendLine(); sb.AppendFormat("Host: {0}", webRequest.Host); sb.AppendLine(); sb.AppendFormat("Type: {0}, Length: {1}", webRequest.ContentType, webRequest.ContentLength); sb.AppendLine(); if (body != null) { sb.AppendFormat("Body: {0}", Encoding.UTF8.GetString(body)); sb.AppendLine(); } var frame = new StackFrame(1); var method = frame.GetMethod(); var type = method.DeclaringType; var name = string.Empty; if (type != null) { name = type.Name; } var source = string.Format("{0}.{1}", name, method.Name); SecucardTrace.InfoSource(source, sb.ToString().Replace("{", "{{").Replace("}", "}}")); }
public override ObjectList <T> RequestList <T>(ChannelRequest request) { var stompRequest = StompRequest.Create(request, _channelId, _configuration.ReplyTo, _configuration.Destination); var returnMessage = SendMessage(stompRequest); SecucardTrace.InfoSource("StompChannel.RequestList", returnMessage.EscapeCurlyBracets()); var response = new Response(returnMessage); return(JsonSerializer.DeserializeJson <ObjectList <T> >(response.Data)); }
internal static void Info(string fmt, params object[] param) { var frame = new StackFrame(1); var method = frame.GetMethod(); var type = method.DeclaringType; var name = string.Empty; if (type != null) { name = type.Name; } var source = string.Format("{0}.{1}", name, method.Name); SecucardTrace.InfoSource(source, fmt, param); }
public string GetToken(bool allowInteractive) { var token = GetCurrent(); var authenticate = false; if (token == null) { // no token, authenticate first authenticate = true; } else if (token.IsExpired()) { // try refresh if just expired, authenticate new if no refresh possible or failed SecucardTrace.InfoSource("Token expired: {0} , original:{1}", token.ExpireTime?.ToString() ?? "null", token.OrigExpireTime == null ? "null" : token.OrigExpireTime.ToString()); if (token.RefreshToken == null) { SecucardTrace.Info("No token refresh possible, try obtain new."); authenticate = true; } else { try { Refresh(token, ClientAuthDetails.GetClientCredentials()); SetCurrentToken(token); } catch (System.Exception ex) { SecucardTrace.Info("Token refresh failed, try obtain new. {0}", ex); authenticate = true; } } } else { // we should have valid token in cache, no new auth necessary if (_config.ExtendExpire) { SecucardTrace.Info("Extend token expire time."); token.SetExpireTime(); SetCurrentToken(token); } SecucardTrace.Info("Return current token: {0}", token); } if (authenticate) { var credentials = ClientAuthDetails.GetCredentials(); if (credentials is AnonymousCredentials) { return(null); } // new authentication is needed but only if allowed if ((credentials is AppUserCredentials || credentials is DeviceCredentials) && !allowInteractive) { throw new AuthFailedException("Invalid access token, please authenticate again."); } token = Authenticate(credentials); token.SetExpireTime(); token.Id = credentials.Id; SetCurrentToken(token); SecucardTrace.Info("Return new token: {0}", token); OnTokenManagerStatusUpdateEvent(new TokenManagerStatusUpdateEventArgs { Status = AuthStatusEnum.Ok, Token = token }); } return(token.AccessToken); }