本文介绍了休息后端,Angular.js前端很多问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

欧凯,让时间来建立使用JBoss,RestEasy的作为后端的web应用,我想去像Angular.js一些MVC的前端框架。

Okey, so time to build an webapplication using Jboss, restEasy as backend and i wanted to go for some MVC front-end framework like Angular.js.

从来没有这样做之前,所以这里是一个亿的问题:

Never done this before so here is a million questions:

我应该使用安全角色在java或有我自己的安全认证,并宣布我自己的角色?

Should i be using security roles in java or have my own security authentication and declare my own roles?

J_security_check是奇怪的,它只是提示您登录,如果您尝试访问被禁止的资源。然后,它重新路由到登录页面。我如何使用这跟角?在我看来,这可能是一个非常混乱改道游戏。

J_security_check is wierd, it only prompts you to log in if you try to access a forbidden resource. Then it reroutes you to the login page. How can i use this with Angular? seems to me this can be a very messy rerouting-game.

消息摘要几乎没有任何解释,但似乎是要走的路,但我不知道如何使用它。

Message Digest is hardly any explanation, but seems to be the way to go, but i have no idea how to use it.

可有人请尽量向我解释验证过程应该如何工作,运行RestEasy的和角度时的步骤。以及如何沟通应该在使用过程中后端的前端之间。

如果我在后端设置角色如何角知道什么样的角色有,并显示出什么看法?我一定要在一个cookie每个请求和存储发送的角色?或者是会话ID anough后端跟踪?

If i set up roles in the back-end how does angular know what roles there are and what views to show? do i have to send roles in each request and store in a cookie? or is the sessionID anough for back-end to keep track?

一切都在我的脑海只是凌乱的。

everything is just messy in my head.

不过这是我认为大气压:

but this is what i think atm:


  1. 冲浪到http:/www.mydomain.com /

  2. 欢迎页面是检查一个cookie,如果没有,创建具有某种客信息的cookie,然后担任了角单页的应用程序的servlet。角读取cookie,并给你的登录页面。

  3. 登录通过SSL调用restservice和后端摘要和用户进行身份验证。在这里,我不知道我应该做的,我应该返回一个cookie的新角色?或不?我应该存储在贝克端登录的用户在一个sessionBean并作出restcall时,经常检查会话bean?我应该保护我背后的Java安全角色restservice?或上述所有?

即时通讯在这里的黑暗,请大家帮忙。

im in the dark here, please help.

推荐答案

既然你在你的后端使用REST风格的服务,我想它会更好,而不是使用一个Cookie令牌认证。

Since you are using a RESTfull service in your back-end, I think it would be better to use a token authentication instead of a cookie.

通过一个cookie,它不会是无状态的,其余的是无状态的。
你可以在这里找到很多选择

With a cookie, it wouldn't be stateless and REST have to be stateless.you can find many options here.

有关角色管理,用户通过验证后,您还可以从后端(与标头中的令牌)的服务将得到的角色。在角可以使用的服务,在localStorage的或在sessionStorage的存储。之后,你不必发送在每个请求(仅令牌用于具有要认证的请求)的角色。

For the roles management, after the user is authenticated, you can call a service from the back-end (with the token in the header) to get the roles. In angular you can store them using a service, in a localStorage or in a sessionStorage. After that you don't have to send the roles in each request (only the token for the requests that have to be authenticated).

的步骤将是:


  1. 冲浪到http:/www.mydomain.com /

  2. 如果用户通过身份验证,即令牌是在服务上,一个的localStorage或sessionStorage的,那么你会显示欢迎页面

  3. 如果用户未通过身份验证(无令牌),则显示登录页面。他本人进行身份验证,角接收令牌,拨打电话来获取角色,然后继续欢迎页面就像在步骤2中。

在后端,您通过验证令牌,如果它在请求的头部进行管理。如果它是无效或完全不存在,您发回一个状态code 401未授权。然后,前端会知道它具有显示登录页面。

In your back-end, you manage this by verifying the token if it's in the request's header. If it's invalid or totally absent, you send back a status code 401 Unauthorized. The front-end will then know that it has to display the login page.

这篇关于休息后端,Angular.js前端很多问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!