gpt4 book ai didi

java - 对耳内的多个 Web 应用程序使用一种身份验证

转载 作者:行者123 更新时间:2023-11-30 03:30:25 25 4
gpt4 key购买 nike

我有一个基于 JSF 的 Web 应用程序,它使用表单例份验证。安全域在jboss配置中设置。我还有一个包含 REST-API 的 JAX-RS 应用程序,我希望它的一些方法只能由在第一个应用程序中经过身份验证的用户访问。
我看了一下 jasig CAS 但它对于我的目的来说似乎有点重,我想有一个更简单的解决方案,也许你们会帮助我找到它。提前致谢。

最佳答案

您需要的可以通过 Oauth 解决.

您的后端 (REST-API) 将需要对您的 API 操作进行身份验证访问。反过来,您的前端(基于 JSF 的 Web 应用程序)在与后端通信时需要发出经过身份验证的请求。这是通过发送访问 token 来实现的。

虽然这看起来很复杂,但查看 Stormpath 对您非常有用。 。我们对此有一个非常简单的解决方案。请查看Using Stormpath for API Authentication

作为摘要,您的解决方案将如下所示:

  1. 您将使用Stormpath Java SDK轻松委派您的所有用户管理需求。
  2. 在您的前端,当用户按下登录按钮时,您的前端将通过其 REST API 将凭据安全地发送到您的后端。

    2.1。顺便说一句,Stormpath 极大地增强了这里的所有可能性。您可以通过其 IDSite 将登录/注册功能完全委托(delegate)给 Stormpath,而不是拥有自己的登录页面。 ,或者您也可以委托(delegate)给我们的Servlet Plugin 。 Stormpath还支持Google、Facebook、LinkedIn和Github登录。

  3. 然后,您的后端将尝试根据 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();
    }
  4. 然后,对于每个经过身份验证的请求,您的后端都会执行以下操作:

    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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com