AngularJs and Jboss and JAAS

女生的网名这么多〃 提交于 2019-12-06 13:33:04

You can use Servlet/Java EE security for your REST endpoint, which I guess is what you're using for Angular.

However the FORM authentication method is probably ill suited for this, as it's more intended for actual user to app interaction, not code to API. Java EE also has a CUSTOM option. Take a look at this http://arjan-tijms.omnifaces.org/2014/11/header-based-stateless-token.html for the general idea.

You'd probably want to act just on the HTTP return codes. Have the Java EE authentication module return a 403* when the user is not authenticated, then in your Angular code display a native login page/dialog based on that. The login dialog could call a login endpoint where a username/password are exchanged for a token that you then use in the following REST calls.

Make sure that you access all the protected endpoints using HTTPS, but at least the login service. Additionally you probably want to expire the token after some time.

*) a 403 is good start point, but there's something to say for always returning a 404 so attackers can't start guessing which protected URLs exist. To check if authentication succeeded (not if the URL exists or is protected) you can echo the authenticated user's ID or name back in a header.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!