如何从Java层与WebSSO集成

时间:2016-10-22 07:15:06

标签: java angularjs rest

请原谅我一个冗长的问题。我正在将REST服务与我们的WebSSO设置集成。这项任务似乎很复杂;因此寻求建议。虽然我提供了添加更多细节的细节,但我要求您将此视为如何与Java层中的WebSSO设置集成的一般问题。这样你就不会被我必须使用的特定技术所劝阻。

设置

我们在AngularJS中构建了一个应用程序。使用此应用程序,可以将文件上传到Filenet。我们的Filenet平台提供REST API(我们围绕Filenet本机API的内部REST包装器)。 Filenet启用了WebSSO - 我们需要使用它。由于我无法控制的原因,我无法直接从AngularJS直接调用Filenet REST。相反,我需要创建自己的REST接口(WebLogic上的Java Jersey) - 让我们将此接口称为façadeREST。 AngularJS代码调用façadeREST,而façadeREST实现依次调用Filenet REST。当我使用应用程序帐户(或系统帐户或匿名帐户)时,一切都很顺利。但是,我需要提高标准并实施WebSSO(我们不能使用应用程序帐户或基本身份验证)。注意:

  • 我们使用RSA ClearTrust for WebSSO。
  • 我们使用NTLM(我相信 - 但我不完全确定)作为WebSSO令牌。因此,登录到我们的Windows机器后,我们无需在登录任何Web应用程序(即启用WebSSO)时输入用户名/密码。
  • AngularJS代码和façadeREST实现驻留在同一个Weblogic服务器上。此服务器上启用了WebSOO。
  • 我使用Jersey来实现façadeREST。从façaderest,我使用Apache HTTP Client调用Filenet REST。
  • 我们的Filenet驻留在不同的服务器上 - IBM WebSphere。此服务器上已启用WebSSO。

伪代码

以下是我设想它将如何运作以及随后的查询。

1)  The AngularJS makes a call to façade REST
2)  Façade REST makes a call to Filenet REST
    2.2) Filenet REST, upon finding that the WebSSO cookie is absent, redirects the caller to WebSSO login page (this is evident in the code that I have developed so far).
    2.2) From façade, do I need to redirect the browser to this login page? I haven’t tried this yet. If I redirected the browser to login page, how would the browser then know that, after seamless and successful login, it should get back to my façade REST?

重复上述第2.2点:

  • 我是否需要将浏览器重定向到此登录页面?
  • 如果我将浏览器重定向到登录页面,那么浏览器如何知道,在无缝成功登录后,它应该回到我的外观REST?
  • 我可能面临哪些其他挑战?
  • 我的思维过程是否准确?
  • 我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

虽然看似复杂,但解决方案却相对简单直接。这就是我必须要做的事情:

  • 在FilenetFaçade中,阅读由我们的基础WebSSO产品生成的CTSESSION cookie,并将其传递给Filenet REST。
  • 在FilenetFaçade中,在对Filenet REST进行Apache HTTPClient调用时,将重定向策略设置为LaxRedirectStrategy(),以便Apache HTTPClient将处理任何重定向。

以下是代码(删除了不相关的部分):

@POST
@Path("/upload")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response upload(@CookieParam("CTSESSION") Cookie ctSessionCookie) {

    // Get the CTSESSION cookie value
    String ctSession = ctSessionCookie.getValue();

    // Initialize Apache HTTPClient and pass the obtained cookie as a header
    HttpPost request = new HttpPost("FileNet.REST.URL");
    request.addHeader("Cookie", "CTSESSION=" + ctSession);
    CloseableHttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
    CloseableHttpResponse result = client.execute(request);

    // Obtain the result, construct Jersey Response, and send it out to the original caller
    Response.ok(result.toString()).build();
}