【问题标题】:Calling RESTful services using CAS Proxy and Spring Security使用 CAS Proxy 和 Spring Security 调用 RESTful 服务
【发布时间】:2012-05-19 04:11:46
【问题描述】:

我目前使用带有 CAS 的 Spring Security 作为身份验证机制来保护 Web 应用程序以及我的 RESTful 服务 API(在单独的服务器上)。我想在 AJAX 中从我的 Web 应用程序调用 RESTful 服务。我已成功设置从 Web 应用程序到服务的 CAS 代理。在我的 AJAX/JQuery 代码中使用 PGT 调用服务以检索服务数据的最佳方式是什么?

现在我可以使用以下测试 servlet 成功读取服务数据,但想知道使用 AJAX 的方法是什么。

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
String targetUrl = "https://example.com/services/helloworld";

final CasAuthenticationToken token = (CasAuthenticationToken) req
    .getUserPrincipal();
final String proxyTicket = token.getAssertion().getPrincipal()
    .getProxyTicketFor(targetUrl);

// Make a remote call using the proxy ticket
final String serviceUrl = targetUrl + "?ticket="
    + URLEncoder.encode(proxyTicket, "UTF-8");
String proxyResponse = CommonUtils.getResponseFromServer(serviceUrl);

resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentType("text/plain");
PrintWriter writer = resp.getWriter();
writer.println(proxyResponse);
writer.flush();
}

【问题讨论】:

    标签: ajax spring-security cas


    【解决方案1】:

    我最终认输并转向 OAuth 2 解决方案。

    【讨论】:

      猜你喜欢
      • 2014-03-22
      • 2011-07-19
      • 2016-10-01
      • 2012-12-02
      • 2017-04-05
      • 2013-10-18
      • 2012-05-06
      • 2012-11-06
      • 2014-07-31
      相关资源
      最近更新 更多