예제 #1
0
        private async Task <IActionResult> RedirectToLogOutAsync(SignOutValidationResult validatedResult)
        {
            var logoutMessage = new LogoutMessage()
            {
                ClientId              = validatedResult.Client?.ClientId,
                ClientName            = validatedResult.Client?.ClientName,
                SubjectId             = validatedResult.User?.GetSubjectId(),
                ClientIds             = validatedResult.ClientIds,
                PostLogoutRedirectUri = validatedResult.ReplyUrl
            };

            string id = null;

            if (logoutMessage.ClientId != null && logoutMessage.ClientIds.Any())
            {
                var msg = new Message <LogoutMessage>(logoutMessage, _clock.UtcNow.UtcDateTime);
                id = await _logoutMessageStore.WriteAsync(msg);
            }

            var redirectUrl = _options.UserInteraction.LogoutUrl;

            if (redirectUrl.IsLocalUrl())
            {
                redirectUrl = HttpContext.GetIdentityServerRelativeUrl(redirectUrl);
            }

            if (id != null)
            {
                redirectUrl = redirectUrl.AddQueryString(_options.UserInteraction.LogoutIdParameter, id);
            }

            return(Redirect(redirectUrl));
        }
예제 #2
0
        private static HttpMessageState ConfigureLogoutState(HttpMessageState s, Log log, string endPoint, string user)
        {
            var logoutMessage = new LogoutMessage();

            s.Name         = user + ", HttpMessageState::logout";
            s.Uri          = endPoint + "/logout";
            s.Message      = logoutMessage;
            s.SetupMessage = (msg) =>
            {
                logoutMessage.token = s.Context.Resolve <string>(UserTokenId);
                log?.Put(OutputLevel.Info, s.Name, "logging out" + user + ".");
            };
            s.ProcessResponse = (response) =>
            {
                if (response.IsSuccessStatusCode)
                {
                    s.Context.Remove(UserTokenId);
                }
                else
                {
                    LogError(log, s.Context, s.Name + " tried to log out, received error code." + " - " + response.ReasonPhrase);
                }
            };
            s.SendMethod = RestMethod.POST;
            return(s);
        }
예제 #3
0
 public void Close(bool bool_4)
 {
     this.bool_2 = true;
     if (this.udpClient_0 != null)
     {
         try
         {
             if (bool_4 && this.bool_0)
             {
                 LogoutMessage message = new LogoutMessage(this.string_0, this.string_1);
                 byte[]        dgram   = SerializeTool.Serialize(message);
                 this.udpClient_0.Send(dgram, dgram.Length, this.ipendPoint_0);
             }
             this.bool_0 = false;
             this.bool_1 = false;
             this.udpClient_0.Close();
             this.udpClient_0 = null;
             Thread.Sleep(0x3e8);
             this.thread_0 = null;
         }
         catch (Exception exception)
         {
             this.ilog_0.ErrorFormat("关闭连接异常:{0}", exception.ToString());
         }
     }
 }
예제 #4
0
        public static void LogOutUser(User user)
        {
            var api = new API();

            api.Logout(Startup.sessionCookie.Id);
            LogoutMessage.LoggedOut(user);
        }
예제 #5
0
        /// <summary>
        /// Executes the result.
        /// </summary>
        /// <param name="context">The HTTP context.</param>
        /// <returns></returns>
        public async Task ExecuteAsync(HttpContext context)
        {
            Init(context);

            var validatedRequest = _result.IsError ? null : _result.ValidatedRequest;

            string id = null;

            if (validatedRequest != null)
            {
                var logoutMessage = new LogoutMessage(validatedRequest);
                if (logoutMessage.ContainsPayload)
                {
                    var msg = new Message <LogoutMessage>(logoutMessage);
                    id = await _logoutMessageStore.WriteAsync(msg);
                }
            }

            var redirect = _options.UserInteraction.LogoutUrl;

            if (redirect.IsLocalUrl())
            {
                redirect = context.GetIdentityServerRelativeUrl(redirect);
            }

            if (id != null)
            {
                redirect = redirect.AddQueryString(_options.UserInteraction.LogoutIdParameter, id);
            }

            context.Response.Redirect(redirect);
        }
        public void Consume(LogoutMessage message)
        {
            var timestampString = message.Timestamp.ToString(Settings.TimeStampFormat);
            var logString       = $"{message.Username} logged out at {timestampString}";

            _messageView.Add(logString);
        }
        public async void Handle(LogoutMessage message)
        {
            var client = BuildRestClient();

            var response = await client.ExecuteTaskAsync(new RestRequest("/rest/auth/1/session", Method.DELETE));

            _configuration.JiraSessionId = "";
            _messageBus.Send(new LoggedOutMessage());
        }
예제 #8
0
        public void TestLogoutMessage()
        {
            var actual = new LogoutMessage {
                SuppressReply = SuppressReply.All
            };
            var expected = new ClientMessageSerializer().Deserialize <LogoutMessage>();

            Assert.IsTrue(expected.Match(actual));
        }
        public void BuildLoggedOutViewModelAsync_WhenSuccessfulLogout_ShowCorrectLogoutView()
        {
            //arrange
            const string logoutId    = "logoutId";
            const string iFrameUrl   = "iframeUrl";
            const string redirectUrl = "redirectUrl";

            var user = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.Name, "name"),
                new Claim(JwtClaimTypes.IdentityProvider, "client")
            }));

            var client = new Client
            {
                ClientId               = "clientId",
                ClientName             = "clientName",
                PostLogoutRedirectUris = new List <string> {
                    redirectUrl
                }
            };

            var logoutMessge = new LogoutMessage
            {
                ClientId   = client.ClientId,
                ClientName = client.ClientName,
                ClientIds  = new List <string>
                {
                    client.ClientId
                },
                SessionId             = "sessionId",
                SubjectId             = "subjectId",
                PostLogoutRedirectUri = redirectUrl
            };

            LogoutRequest logoutRequest = new LogoutRequest(iFrameUrl, logoutMessge);

            mockInteraction.Setup(x => x.GetLogoutContextAsync(logoutId))
            .ReturnsAsync(logoutRequest).Verifiable();

            mockAccessor.SetupGet(x => x.HttpContext.User).Returns(user).Verifiable();

            //act
            var result = CreateSut().BuildLoggedOutViewModelAsync(logoutId).Result;

            //assert
            Assert.True(result.AutomaticRedirectAfterSignOut);
            Assert.Equal(redirectUrl, result.PostLogoutRedirectUri);
            Assert.Equal(client.ClientName, result.ClientName);
            Assert.Equal(iFrameUrl, result.SignOutIframeUrl);
            Assert.Equal(logoutId, result.LogoutId);

            mockInteraction.Verify();
            mockAccessor.Verify();
        }
예제 #10
0
    /// <summary>
    /// Initializes a new instance of the <see cref="LogoutRequest"/> class.
    /// </summary>
    /// <param name="iframeUrl">The iframe URL.</param>
    /// <param name="message">The message.</param>
    public LogoutRequest(string iframeUrl, LogoutMessage message)
    {
        if (message != null)
        {
            ClientId              = message.ClientId;
            ClientName            = message.ClientName;
            PostLogoutRedirectUri = message.PostLogoutRedirectUri;
            SubjectId             = message.SubjectId;
            SessionId             = message.SessionId;
            ClientIds             = message.ClientIds;
            UiLocales             = message.UiLocales;
            Parameters            = message.Parameters.FromFullDictionary();
        }

        SignOutIFrameUrl = iframeUrl;
    }
예제 #11
0
        void HandleLogout(LogoutMessage msg)
        {
            Console.WriteLine("___HANDLE LOGOUT");
            if (_clients.ContainsKey(msg.ClientId))
            {
                //TODO - send the scene here too
                _clients.Remove(msg.ClientId);


                foreach (var scene in _loadedScenes)
                {
                    scene.Value.LogoutClient(msg.ClientId).Wait();
                }

                List <Guid> otorem = new List <Guid>();

                foreach (var oobj in _allClientObjects)
                {
                    oobj.Value.Item2.UnregisterClient(msg.ClientId).Wait();
                    if (oobj.Value.Item1 == msg.ClientId)
                    {
                        otorem.Add(oobj.Key);
                    }
                }

                foreach (var rid in otorem)
                {
                    _allClientObjects[rid].Item2.DestroyObject().Wait();
                    _allClientObjects.Remove(rid);
                }

                foreach (var client in _clients)
                {
                    client.Value.KillOwnedObjects(msg.ClientId);
                }

                _loggedInUsers.Remove(msg.UserId);
                _logger.Info($"Client - {msg.ClientId} is removed");
            }
            else
            {
                _logger.Warn($"Not exists {msg.ClientId} client");
            }
        }
        public async Task ExecuteAsync(HttpContext context)
        {
            _options            = _options ?? context.RequestServices.GetRequiredService <IdentityServerOptions>();
            _clock              = _clock ?? context.RequestServices.GetRequiredService <ISystemClock>();
            _logoutMessageStore = _logoutMessageStore ?? context.RequestServices.GetRequiredService <IMessageStore <LogoutMessage> >();

            var redirectUrl = _options.UserInteraction.LogoutUrl;

            if (!_result.IsError)
            {
                var validatedRequest = _result.ValidatedRequest;
                var logoutMessage    = new LogoutMessage(validatedRequest);
                var msg = new Message <LogoutMessage>(logoutMessage, _clock.UtcNow.UtcDateTime);
                var id  = await _logoutMessageStore.WriteAsync(msg);

                redirectUrl = redirectUrl.AddQueryString(_options.UserInteraction.LogoutIdParameter, id);
            }

            context.Response.RedirectToAbsoluteUrl(redirectUrl);
        }
예제 #13
0
        /// <summary>
        /// Executes the result.
        /// </summary>
        /// <param name="context">The HTTP context.</param>
        /// <returns></returns>
        public async Task ExecuteAsync(HttpContext context)
        {
            Init(context);

            var validatedRequest = _result.IsError ? null : _result.ValidatedRequest;

            string id        = null;
            string uilocales = null;

            if (validatedRequest != null)
            {
                var logoutMessage = new LogoutMessage(validatedRequest);
                if (logoutMessage.ContainsPayload)
                {
                    var msg = new Message <LogoutMessage>(logoutMessage);
                    id = await _logoutMessageStore.WriteAsync(msg);
                }

                uilocales = validatedRequest.Raw?.Get(OidcConstants.EndSessionRequest.UiLocales);
            }

            var redirect = _options.UserInteraction.LogoutUrl;

            if (redirect.IsLocalUrl())
            {
                redirect = context.GetIdentityServerRelativeUrl(redirect);
            }

            if (id != null)
            {
                redirect = redirect.AddQueryString(_options.UserInteraction.LogoutIdParameter, id);
            }

            // add uilocales to the query string if it is available
            if (uilocales.IsPresent() && uilocales.Length < _options.InputLengthRestrictions.UiLocale)
            {
                redirect = redirect.AddQueryString(OidcConstants.EndSessionRequest.UiLocales, uilocales);
            }

            context.Response.Redirect(redirect);
        }
예제 #14
0
        private void LogOutUser(User user)
        {
            Console.Out.WriteLine($">> {user.Name} has logged out.");

            _logedInUsers.Remove(user);

            // inform all other users
            var users      = _logedInUsers.Keys.ToList();
            var data       = new LogoutMessage(user);
            var newMessage = CreateMessage(data);

            foreach (var client in _clients)
            {
                SendMessage(client, newMessage);
            }

            if (_logedInUsers.Count == 1)
            {
                SendNobodyIsLoggedInMessage();
            }
        }
        internal static async Task <string> GetIdentityServerSignoutFrameCallbackUrlAsync(this HttpContext context, LogoutMessage logoutMessage = null)
        {
            var userSession = context.RequestServices.GetRequiredService <IUserSession>();
            var user        = await userSession.GetIdentityServerUserAsync();

            var currentSubId = user?.GetSubjectId();

            EndSession endSessionMsg = null;

            // if we have a logout message, then that take precedence over the current user
            if (logoutMessage?.ClientIds?.Any() == true)
            {
                var clientIds = logoutMessage?.ClientIds;

                // check if current user is same, since we migth have new clients (albeit unlikely)
                if (currentSubId == logoutMessage?.SubjectId)
                {
                    clientIds = clientIds.Union(await userSession.GetClientListAsync());
                    clientIds = clientIds.Distinct();
                }

                endSessionMsg = new EndSession
                {
                    SubjectId = logoutMessage.SubjectId,
                    SessionId = logoutMessage.SessionId,
                    ClientIds = clientIds
                };
            }
            else if (currentSubId != null)
            {
                // see if current user has any clients they need to signout of
                var clientIds = await userSession.GetClientListAsync();

                if (clientIds.Any())
                {
                    endSessionMsg = new EndSession
                    {
                        SubjectId = currentSubId,
                        SessionId = await userSession.GetCurrentSessionIdAsync(),
                        ClientIds = clientIds
                    };
                }
            }

            if (endSessionMsg != null)
            {
                var options = context.RequestServices.GetRequiredService <IdentityServerOptions>();
                var msg     = new Message <EndSession>(endSessionMsg, options.UtcNow);

                var endSessionMessageStore = context.RequestServices.GetRequiredService <IMessageStore <EndSession> >();
                var id = await endSessionMessageStore.WriteAsync(msg);

                var signoutIframeUrl = context.GetIdentityServerBaseUrl().EnsureTrailingSlash() + Constants.ProtocolRoutePaths.EndSessionCallback;
                signoutIframeUrl = signoutIframeUrl.AddQueryString(Constants.UIConstants.DefaultRoutePathParams.EndSessionCallback, id);

                return(signoutIframeUrl);
            }

            // no sessions, so nothing to cleanup
            return(null);
        }
예제 #16
0
 void OnLogoutMessage(LogoutMessage message)
 {
     OnUserOffline(message.Sender.ClientID);
 }
        public void Consume(LogoutMessage message)
        {
            var messageString = $"User {message.Username} logged out";

            _messagesView.Add(messageString);
        }
예제 #18
0
 private void Logout(LogoutMessage msg)
 {
     IsBusy = false;
     var settings = IsolatedStorageSettings.ApplicationSettings;
     settings.Remove("appUser");
     loginUser = new User();
     Password = "";
     Messenger.Default.Send(new SetUserMessage { User = null });
     Messenger.Default.Send(new NavigationMessage { Destination = "Login", OnStack = false, Source = this.GetType().ToString() });
 }
예제 #19
0
 public static void SendLogoutMessage()
 {
     LogoutMessage message = new LogoutMessage();
     Client.Instance.NetworkHelper.SendMessage(message);
 }
예제 #20
0
        public void LogoutMessageTest()
        {
            var logoutMessage = new LogoutMessage();

            this.AssertMessage(logoutMessage);
        }
예제 #21
0
        public new void Stop()
        {
            var message = new LogoutMessage();

            this.SendMessage(message);
        }
예제 #22
0
 private void OnLogoutReceived(LogoutMessage message)
 {
     Model.RemoveUserSession(message.ConnectionId);
 }
예제 #23
0
 private void OnLogout(LogoutMessage message)
 {
     Model.ConIdToUserName.Remove(message.ConnectionId);
     Model.SetChanges();
 }
예제 #24
0
 public void Handle(LogoutMessage message)
 {
     ActivateItem(_loginViewModel);
 }
예제 #25
0
 public virtual void OnLogout(object sender, LogoutMessage message)
 {
     ManagerState.Instance.ChangeState(EnumState.LOGIN);
 }
예제 #26
0
 public void OnLogoutHandler(LogoutMessage m)
 {
     IsViewVisible = true;
 }
예제 #27
0
        public void ConvertFixObjectToFixMessage_ReturnsCorrectString_ForLogoutMessage()
        {
            var messageObject = new LogoutMessage("Client", "Bank", 1);

            string result = new FixParser().ConvertFixObjectToFixMessage(messageObject);

            string expected = "8=FIXT1.1\u00019=28\u000135=5\u000149=Client\u000156=Bank\u000134=1\u000110=2\u0001";

            result.Should().Be(expected);
        }