首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有CAS登录屏幕的JASIG CAS登录

没有CAS登录屏幕的JASIG CAS登录
EN

Stack Overflow用户
提问于 2012-05-07 05:09:41
回答 5查看 10K关注 0票数 13

我们正在尝试为我们现有的基于web的应用程序使用CAS服务器进行SSO。我们的目标是

  • 跨各种应用程序(包括跨域)实现SSO。
  • 当不同的应用程序重定向到CAS Server登录页面时,要为不同的应用程序定制登录页面( UI术语)。
  • 能够在不访问CAS登录页面的情况下进行登录,原因是页面本身嵌入了“一个小的登录部分”,并且为了更好的可用性,用户不会被重定向到CAS登录页面。

我们完成了第一个和第二个目标。但与第三个有问题。

对于此功能,我们试图复制与第二个目标相同的操作,唯一不同的是从非CAS登录页面提交/发布数据(凭据、登录票等)。

  • 我们不能使用iframes在小部分显示CAS登录页面,这很容易受到浏览器兼容性问题的影响。
  • 我们不能使用ajax来使用CAS api来获取登录票和执行HTTP post (跨域问题)。
  • 我们所做的是:在非cas登录页面加载时,通过在服务器端执行HTTP post来检索login票证和执行id。当我们发布用户名/密码以及login票证和execId时,CAS服务器没有接受post数据,而是将用户重定向到CAS登录页面,但是返回浏览器并再次提交数据很好。在CAS和浏览器之间没有建立jsession,因此CAS拒绝任何post数据。我们可以使用CAS restAPI,但是它只是登录用户,而没有帮助完成SSO。

对我们如何处理这个问题有什么想法吗?

谢谢你,普赖克

EN

回答 5

Stack Overflow用户

发布于 2013-01-11 09:29:42

在CAS上有一个wiki页面,对此进行辩论:https://wiki.jasig.org/display/CAS/Using+CAS+without+the+Login+Screen (但它比米萨格·M提出的谷歌小组讨论更老)。

我的解决方案是"从外部链接或自定义外部窗体使用CAS“。

票数 1
EN

Stack Overflow用户

发布于 2016-08-15 08:17:57

  1. 您必须获得CAS官方客户端源代码( cas- client -core,https://github.com/apereo/java-cas-client )的副本,并确保可以编译它。
  2. 您需要在客户端源代码中更改org.jasig.cas.client.authentication.AuthenticationFilter上的doFilter()函数代码,如下所示。 最终HttpServletRequest请求= (HttpServletRequest) servletRequest;最终HttpServletResponse响应= (HttpServletResponse) servletResponse;最终HttpSession会话= request.getSession(false);最终断言= session != null?(断言) if(request.getServletPath().toLowerCase().equals("/caslogout.jsp")) (断言) session.getAttribute(CONST_CAS_ASSERTION):null;当您从CAS服务器注销时,设置自定义客户端登录页。request.setAttribute("casServerLogoutUrl",casServerLoginUrl.replace(“登录”,“注销”));request.setAttribute("customServerLoginUrl",customServerLoginUrl);//我们必须手动删除CONST_CAS_ASSERTION的属性if (会话!=空) session.removeAttribute(CONST_CAS_ASSERTION);filterChain.doFilter(请求,响应);返回;}if(断言=空){filterChain.doFilter(请求,响应);返回;} //尽管自定义登录页面必须调用caslogin,但您可以在这里更改它。if(request.getServletPath().toLowerCase().equals("/caslogin.jsp")) {//将默认参数设置为级联request.setAttribute("defaultServerIndexUrl",defaultServerIndexUrl);request.setAttribute("casServerLoginUrl",casServerLoginUrl);filterChain.doFilter(请求、响应);返回;} final =constructServiceUrl(请求、响应);if (CommonUtils.isNotBlank(票证)而论){filterChain.doFilter(请求、响应);返回;} final String modifiedServiceUrl;log.debug(“无票证和未找到断言”);if (this.gateway) {log.debug(“设置会话中的网关属性”);modifiedServiceUrl = modifiedServiceUrl serviceUrl;}filterChain.doFilter{modifiedServiceUrl=serviceUrl;} if (log.isDebugEnabled()) {log.debug(“构造服务url:”+ modifiedServiceUrl);}最终字符串urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl,getServiceParameterName()、modifiedServiceUrl、this.renew、this.gateway);if (log.isDebugEnabled()) {log.debug(“重定向到”+ urlToRedirectTo +“\”);} //将自定义服务器登录url参数添加到CAS登录url。response.sendRedirect(urlToRedirectTo+"&customLogin=custom&customLoginPage="+customServerLoginUrl);
  3. 将您自己编译的cas客户端核心添加到客户端webapp应用程序的依赖中。
  4. 将caslogin.jsp添加到客户端webapp应用程序中。

代码语言:javascript
复制
     <form method="GET" action="<%=request.getAttribute("casServerLoginUrl")%>">
    <p>Username : <input type="text" name="username" /></p>
    <p>Password : <input type="password" name="password" /></p>
    <p><input type="submit" value="Login" /></p>
    <input type="hidden" name="auto" value="true" />
    <input type="hidden" name="service" value="<%=request.getParameter("service")==null?request.getAttribute("defaultServerIndexUrl"):request.getParameter("service")%>" />

  1. 在客户端webapp中编辑web.xml。在CASFilter的过滤器中添加下面的代码

代码语言:javascript
复制
<init-param>
    <param-name>defaultServerIndexUrl</param-name>
    <param-value>http://clientip:port/webappname/index.jsp</param-value>
</init-param>
<init-param>
    <param-name>customServerLoginUrl</param-name>
    <param-value>http://clientip:port/webappname/caslogin.jsp</param-value>
</init-param>

  1. 在cas-server-webapp/WEB-INF/view/jsp/default/ui/casLoginView.jsp服务器web应用程序中编辑代码。

代码语言:javascript
复制
<%
  String auto=request.getParameter("auto");
  String customLogin=request.getParameter("customLogin");

  if(auto!=null&&auto.equals("true"))
  {
    %>
    <html>
    <head>
      <script language="javascript">
        function doAutoLogin()
        {
          document.forms[0].submit();
        }
      </script>
    </head>
    <body onload="doAutoLogin()">
    <form id="credentials" method="POST" action="<%=request.getContextPath()%>/login?service=<%=request.getParameter("service")%>">
      <input type="hidden" name="lt" value="${loginTicket}" />
      <input type="hidden" name="execution" value="${flowExecutionKey}" />
      <input type="hidden" name="_eventId" value="submit" />
      <input type="hidden" name="username" value="<%=request.getParameter("username")%>" />
      <input type="hidden" name="password" value="<%=request.getParameter("password")%>" />
      <input type="hidden" name="login_form" value="<%=request.getParameter("login_form")%>" />
      <input type="hidden" name="rememberMe" value="true" />
      <input type="submit" value="Submit" style="visibility: hidden" />
    </form>
    </body>
    </html>

    <%
}
else if(customLogin!=null&&customLogin.equals("custom"))
{  
  response.sendRedirect(request.getParameter("customLoginPage")+"?service="+request.getParameter("service"));
%>
<%
}
else
{%>
<!-- The Orgin Source Code of casLoginView.jsp!!!!!!!!!!!!!!!!!!!!!!!!! -->
<%}%>

  1. 确保您可以使用caslogin.jsp登录cas。
  2. 将您自己登录页面的内容放到caslogin.jsp中。
  3. 现在您可以使用自己的caslogin.jsp登录cas了。

我还制作了一个示例,说明如何使用客户端自定义登录屏幕登录cas,而不是使用服务器登录srceen。你可以下载到

https://github.com/yangminxing/cas-custom-login-page

票数 1
EN

Stack Overflow用户

发布于 2015-02-10 14:16:03

我知道很晚了,但如果有人在找答案,我就是这样解决的。这是我在casLoginView.jsp中输入的代码

代码语言:javascript
复制
<head>
    <script language="javascript">
        function doAutoLogin() {
            document.forms[0].submit();
        }
    </script>
</head>
<body onload="doAutoLogin();">
    <form id="credentials" method="POST" action="<%= request.getContextPath() %>/login?service=<%= request.getParameter("service") %>">
        <input type="hidden" name="lt" value="${loginTicket}" />
        <input type="hidden" name="execution" value="${flowExecutionKey}" />
        <input type="hidden" name="_eventId" value="submit" />
        <input type="hidden" name="serviceLogin" value="<%= request.getParameter("serviceLogin") %>"/>
        <input type="hidden" name="username" value="<%= request.getParameter("username") %>" />
        <input type="hidden" name="password" value="<%= request.getParameter("password") %>" />
        <% 
        if ("true".equals(request.getParameter("rememberMe"))) {%>
            <input type="hidden" name="rememberMe" id="rememberMe" value="true"/>
        <% } %>

        <input type="submit" value="Submit" style="visibility: hidden;" />
    </form>
    <% } else {
        response.sendRedirect(request.getParameter("redirectURL"));
       }
    %>
</body>

在你的网络应用程序中,只需向你的CAS服务器发送一份请愿书。

希望它能帮上忙

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10476949

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档