- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个基于 JSF 的 Web 应用程序,它使用表单例份验证。安全域在jboss
配置中设置。我还有一个包含 REST-API 的 JAX-RS 应用程序,我希望它的一些方法只能由在第一个应用程序中经过身份验证的用户访问。
我看了一下 jasig CAS
但它对于我的目的来说似乎有点重,我想有一个更简单的解决方案,也许你们会帮助我找到它。提前致谢。
最佳答案
您需要的可以通过 Oauth 解决.
您的后端 (REST-API) 将需要对您的 API 操作进行身份验证访问。反过来,您的前端(基于 JSF 的 Web 应用程序)在与后端通信时需要发出经过身份验证的请求。这是通过发送访问 token
来实现的。
虽然这看起来很复杂,但查看 Stormpath 对您非常有用。 。我们对此有一个非常简单的解决方案。请查看Using Stormpath for API Authentication 。
作为摘要,您的解决方案将如下所示:
在您的前端,当用户按下登录按钮时,您的前端将通过其 REST API 将凭据安全地发送到您的后端。
2.1。顺便说一句,Stormpath 极大地增强了这里的所有可能性。您可以通过其 IDSite 将登录/注册功能完全委托(delegate)给 Stormpath,而不是拥有自己的登录页面。 ,或者您也可以委托(delegate)给我们的Servlet Plugin 。 Stormpath还支持Google、Facebook、LinkedIn和Github登录。
然后,您的后端将尝试根据 Stormpath 后端对用户进行身份验证,并返回一个访问 token
:
/** This code will throw an Exception if the authentication fails */
public void postOAuthToken(HttpServletRequest request, HttpServletResponse response) {
Application application = client.getResource(applicationRestUrl, Application.class);
//Getting the authentication result
AccessTokenResult result = (AccessTokenResult) application.authenticateApiRequest(request);
//Here you can get all the user data stored in Stormpath
Account account = accessTokenResult.getAccount();
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("application/json");
//Output the json of the Access Token
response.getWriter().print(token.toJson());
response.getWriter().flush();
}
然后,对于每个经过身份验证的请求,您的后端都会执行以下操作:
public void getEquipment(HttpServletRequest request, HttpServletResponse response) {
Application application = client.getResource(applicationRestUrl, Application.class);
OauthAuthenticationResult result = (OauthAuthenticationResult) application.authenticateOauthRequest(request).execute();
System.out.println(result.getApiKey());
System.out.println(result.getAccount());
//Return what you need to return in the response
handleEquipmentRequest(response);
}
请看一下here了解更多信息
希望有帮助!
免责声明,我是一名活跃的 Stormpath 贡献者。
关于java - 对耳内的多个 Web 应用程序使用一种身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29181255/
我想通过耳机播放音乐文件, 我现在正在做的是: 在 viewDidLoad 方法中:::: [[AVAudioSession sharedInstance] setCategory:AVAudioSe
我正在寻找一个 opencv 函数(在 python 中)检测人脸上的左耳 - 下巴 - 右耳(看起来像抛物线)线。有没有什么 haarcascade 在做这项工作?我已经知道正面或眼睛 haarca
我是一名优秀的程序员,十分优秀!