简体   繁体   English

如何从Java REST servlet向angular Client发送注销消息?

[英]How to Send a logout message from Java REST servlet to angular Client?

I have some doubts about how to send a message from a Java Rest Server, to an Angular Client. 我对如何从Java Rest服务器向Angular Client发送消息有所怀疑。 I have read about WebSockets, but Im not sure if it suits what im looking for. 我已阅读有关WebSockets的内容,但我不确定它是否适合我正在寻找的内容。

We use a token-based authentication , and when a client logouts, we choosed to simply remove token from client. 我们使用基于令牌的身份验证,当客户端注销时,我们选择从客户端删除令牌。 Until here everything is correct. 直到这里一切都是正确的。 Problem is that our system includes a functionality that allows admins to logoff online users. 问题是我们的系统包含一个允许管理员注销在线用户的功能。 As clients can't notice that they where logged off, they can't remove token. 由于客户端无法注意到它们已注销,因此无法删除令牌。 I'm looking for a way to send a message from server to an specific client, so It can logouts from ClientSide, and remove its token. 我正在寻找一种从服务器向特定客户端发送消息的方法,因此它可以从ClientSide注销,并删除其令牌。

Is WebSocket best way to do this? WebSocket是最好的方法吗?

Thanks in advance. 提前致谢。

Here is what I would do. 这就是我要做的。 When a user is logged off, which can actually also happen when the session expires, nothing will happen until the user performs an action. 当用户注销时,实际上也可以在会话到期时发生,在用户执行操作之前不会发生任何事情。 This action might require a backend call which can then return a 401 html code. 此操作可能需要后端调用,然后可以返回401 html代码。

When you really immediately want to redirect the user to a login page, you might indeed need web-sockets or if that is not an option, hit your backend with a certain interval to validate the session 当您真正想立即将用户重定向到登录页面时,您可能确实需要Web套接字,或者如果这不是一个选项,请以一定的时间间隔命中您的后端以验证会话

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM