简体   繁体   English

Spring REST-JWT-JavaScript在安全页面之间导航

[英]Spring REST-JWT-JavaScript navigate between secure pages

I have a Java Spring REST back-end (@RestController) and using as security option Json Web Tokens(no session). 我有一个Java Spring REST后端(@RestController),并用作安全选项Json Web令牌(无会话)。 At the front-end I want to use JavaScript (jQuery to send requests to back-end), Html. 在前端,我想使用JavaScript(jQuery将请求发送到后端),HTML。 So after login I save a JWT in browser and send it back in header with every request I make to @RestController. 因此,登录后,我将JWT保存在浏览器中,并将其与我对@RestController的每个请求一起发送回标头中。

My question is: How to navigate between pages (that are accessible only for authenticated users) from js? 我的问题是:如何从js导航页面(只有经过身份验证的用户才能访问)? How @RestController will work in this case? @RestController在这种情况下将如何工作?

The @RestController handle the requests containing a path (the path of the request is not necessary to be the same with the path(URL) from front-end) @RestController处理包含路径的请求(请求的路径不必与前端的路径(URL)相同)

Solution (if you have a front-end server): When you try to reach a front-end URL you make a call to the server-side; 解决方案(如果您有前端服务器):当尝试访问前端URL时,您将调用服务器端; if the response status is 200 the page can be displayed(with the body of the response if you send information); 如果响应状态为200,则可以显示该页面(如果发送信息,则显示响应的正文); if the response is not you will stay on the home page, or you can redirect the user to login page... 如果没有响应,您将停留在主页上,或者可以将用户重定向到登录页面...

Also check this : http://www.studytrails.com/frameworks/spring/spring-security-method-level/ 还要检查以下内容: http : //www.studytrails.com/frameworks/spring/spring-security-method-level/

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

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