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

PM665

我有一个使用表单身份验证的基于JSF的Web应用程序。安全域在jbossconfig中设置我也有一个JAX-RS包含REST-API应用程序,我希望只有在第一个App中通过身份验证的用户才能访问其某些方法。
我看了一下jasig,CAS但就我的目的而言似乎有点沉重,我想有一个更简单的解决方案,也许你们会帮我找到它。提前致谢。

马里奥

您需要的可以通过Oauth解决

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

尽管这看起来很复杂,但是对您来说,查看Stormpath还是很有用的为此,我们有一个非常简单的解决方案。请查看使用Stormpath进行API身份验证

概括来说,您的解决方案如下所示:

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

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

  3. 然后,您的后端将尝试根据Stormpath后端对用户进行身份验证,并返回access 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);
    }
    

请在这里查看更多信息

希望对您有所帮助!

免责声明,我是Stormpath的活跃贡献者。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用多个应用程序处理 django 身份验证

使用Windows身份验证和Web应用程序的IIS与Web应用程序

具有身份验证的MVC应用程序内的Web API基本身份验证

使用不同AuthenticationProviders多个WebSecurityConfigurerAdapter(用于API和LDAP的web应用程序基本身份验证)

移动应用程序:永久登录(使用两种身份验证方法)

多个Django应用程序,共享身份验证

多个 .NET 应用程序共享身份验证

在Web应用程序中对用户进行身份验证时,对用户进行身份验证以使用Azure功能

使用 ElasticSearch 为 Web 应用程序放置身份验证/会话管理的哪一层

Web应用程序和请求身份验证

Azure Web应用程序网关身份验证

移动应用程序Web API身份验证

Hyperledger Composer Web应用程序用户身份验证

Microsoft 身份验证库 SPA 与 Web 应用程序

Tomcat身份验证和特定的Web应用程序身份验证

使用 Xero 的 Java SDK 来支持多个私有应用程序的身份验证?

使用BASIC身份验证集中保护所有tomcat Web应用程序

使用WildFly自定义Web应用程序身份验证

使用python作为CGI Web应用程序进行相互身份验证?

使用Nginx和Tomcat Web应用程序进行TLS客户端身份验证

如何对Android应用程序使用的Web API服务实施身份验证?

如何使用node.js对外部Web应用程序的用户进行身份验证?

使用AWS Cognito和AD FS作为Web应用程序的身份验证

如何正确使用Express-gateway进行Web应用程序的身份验证?

用户通过Google Web应用程序进行身份验证后,获取并使用访问令牌

使用Moodle对Web应用程序的用户进行身份验证

使用Web应用程序的Apache服务器会话身份验证

无法使用 Onelogin 和 Azure Web 应用程序获得 OpenID 身份验证

Web 应用程序、Web API 和移动应用程序之间的身份验证