有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

AngularJS Java EE REST安全性

我在JavaEE7后端使用AngularJS和RESTAPI。 该项目部署在Wildfly应用服务器上,我对重新分级安全性有一些疑问:

  1. 为了加密/解密数据,我使用CryptoJS在服务器端(Java)进行加密和解密,但显然我们必须以明文形式发送密码短语,密码和salt只是加密的。 我的问题是为什么密码短语是明文?它应该是秘密的,然后再加密不是吗

  2. 对于RESTAPI,Java EE 7 HTTP安全头(基本身份验证)使用的标准是什么?Json访问令牌?它到底是如何工作的,在cookie上存储用户会话/令牌的位置?我只是想知道如何用角形的

  3. 也许我可以使用基于表单的身份验证和请求的经典JAAS。服务器端的login()将进行身份验证,然后我的EJB将受到@Role的保护

  4. 在AngularJS中保护页面的方法是什么?目前我正在使用网络。xml和URL模式,也许有更好的方法

我已经找到了很多这样的例子:

AngularJs and Jboss and JAAS(全方位安全)

how to integrate angularjs and java jaas based authentication?

一些用户提到:

* index.html page should contain token inside html to avoid CSRF
* token shouldn't be stored in a cookie storage
* Each request should be signed with header param
* Server should validate every request by passed header
* If cookie usage is a must you should validate referer in order to prevent CSRF

但是没有具体的例子说明如何实现这一点,特别是CSRF


共 (1) 个答案

  1. # 1 楼答案

    To Encrypt/decrypt data I am using CryptoJS to encrypt and decrypt on server side ( Java ) but apparently we have to send the passphrase in clear, the cipher and salt are only encrypted. My question is why the passphrase is clear text ? it should be secret and then encrypted as well no ?

    一旦您发送密钥(密码短语?)在清除-加密是无用的

    要实现合理的客户机-服务器安全性,请使用HTTPS。简单、有效且更安全。一般来说,在web应用程序端加密是个坏主意,因为用户或“中间人”可以检索或修改密钥和数据

    不同的情况是端到端安全,当客户端加密、发布加密数据并按原样存储/处理它们时,加密密钥仅对用户可用。如果情况并非如此,并且服务需要进一步操作所需的数据,那么HTTPS就是最好的选择

    For the REST API, what is the standard to use for Java EE 7, HTTP security header (basic-auth) ? Json Access token ? and how it really works, where to store user session/token, on a cookie ? I just want to know how to do it with Angular.

    实际上你列出了你的选择。这是你的决定。每种选择都有其利弊。基本上-如果您谈论的是(REST)服务,那么使用什么技术并不重要

    对于直接从浏览器调用的REST服务,我将省略基本身份验证(否则用户将获得弹出的身份验证窗口)

    您可以使用JWT令牌(由应用程序机密签名,只需添加一些过期日期),但是您不能“注销”用户,只需等待令牌过期。优点是,令牌是“自给自足”的,您无需担心会话管理。客户端在授权HTTP头中发送JWT令牌,您只需对其进行解码、验证,然后就可以从令牌中获得身份

    另一个选项是会话令牌(cookie或作为授权头发送),您需要在其中管理会话(存储令牌,注销时清除令牌,…)。使用app server会话cookies会使您的服务无法被其他应用程序使用(仍然是一个问题-您是否希望/需要第三方重用这些服务),但您实现了内置授权(JAAS、角色等)

    Maybe I can use the classic JAAS with form-based authentication and then having request.login() on server side to be authenticated then my EJB will be all protected by @Role.

    实际上,这是一种验证和授权用户并发出令牌(jwt、cookie、其他…)的方法

    What is the way to protect pages in AngularJS ? For the moment I am using the web.xml and putting the URL patterns, maybe there is a better way ?

    默认的web授权应该是ok

    仍然-保持简单。根据我的经验,静态资源(web页面、图像、脚本、css)应该是静态的,如果它们是公开的,那就无关紧要了。重要的是执行(操作、数据等)作为服务公开,这是您进行适当身份验证和授权的地方

    玩得开心