2

我已经在我的应用程序中实现了 jasig-CAS,但现在我想了解更多。是否可以做我自己的登录页面,然后它会自动(在后台)在 CAS 中对用户进行身份验证。所以接下来的步骤是:

  1. 用户进入登录页面
  2. 用户输入他的凭据
  3. 如果身份验证成功,用户的凭据将被发送到 CAS,因此 CAS 在其系统中对用户进行身份验证并提供票证(用户不应看到任何 CAS 页面)
  4. 用户访问受保护的页面

谢谢。

4

5 回答 5

1

您可以使用 REST API。 CAS 休息

我将它用于登录,即 Drupal。由于您没有重定向,因此用户看不到任何 CAS 页面。

因此,步骤将是:

  1. 用户进入登录页面。
  2. 用户输入凭证。
  3. 您的应用程序通过 REST 将用户名和密码发布到 CAS。
  4. 您的应用程序在成功进行身份验证后会返回一个 Ticket Granting Ticket。

此时您可以将他登录到您的应用程序(他已经登录到 CAS)或验证您收到的票证然后登录他。

于 2012-11-28T00:44:26.490 回答
0

更新后的 CAS 文档有一个关于用户界面定制的页面:

https://apereo.github.io/cas/4.2.x/installation/User-Interface-Customization.html

请注意,自原始帖子和其他一些答案以来,CAS 站点和文档已经移动。

CAS 主页 - https://apereo.github.io/cas/4.2.x/index.html

Github 上的 CAS - https://github.com/apereo/cas

旧版 CAS Wiki - https://wiki.jasig.org/display/CAS/Home

于 2016-11-07T15:38:23.613 回答
0

不建议使用外部表单输入凭据,这会扩大攻击面。见https://apereo.github.io/cas/5.0.x/planning/Security-Guide.html

如果有人破坏了您的外部表单应用程序,攻击者就可以访问所有 SSO 连接的系统。

于 2017-03-22T13:11:43.390 回答
0
  1. 我认为您需要获得一份 CAS 官方客户端源代码(cas-client-core),并确保您可以编译它。

  2. 您需要更改客户端源代码中 org.jasig.cas.client.authentication.AuthenticationFilter 中的 doFilter() 函数代码,如下所示。

    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpServletResponse response = (HttpServletResponse) servletResponse;
    final HttpSession session = request.getSession(false);
    final Assertion assertion = session != null ? (Assertion) session.getAttribute(CONST_CAS_ASSERTION) : null;
    
    if(request.getServletPath().toLowerCase().equals("/caslogout.jsp"))
    {
        // Set the custom client login page when you logout from CAS server.
        request.setAttribute("casServerLogoutUrl",casServerLoginUrl.replace("login","logout"));
        request.setAttribute("customServerLoginUrl",customServerLoginUrl);
    
        //We must remove the attribute of CONST_CAS_ASSERTION manually
        if(session!=null)
            session.removeAttribute(CONST_CAS_ASSERTION);
    
        filterChain.doFilter(request, response);
        return;
    }
    
    if (assertion != null) {
        filterChain.doFilter(request, response);
        return;
    }
    
    // Although the custom login page must called caslogin, here you can change it.
    if(request.getServletPath().toLowerCase().equals("/caslogin.jsp"))
    {
        //Set the a default parameter to the caslogin
        request.setAttribute("defaultServerIndexUrl",defaultServerIndexUrl);
        request.setAttribute("casServerLoginUrl",casServerLoginUrl);
        filterChain.doFilter(request, response);
        return;
    }
    
    final String serviceUrl = constructServiceUrl(request, response);
    final String ticket = CommonUtils.safeGetParameter(request,getArtifactParameterName());
    final boolean wasGatewayed = this.gatewayStorage.hasGatewayedAlready(request, serviceUrl);
    
    if (CommonUtils.isNotBlank(ticket) || wasGatewayed) {
        filterChain.doFilter(request, response);
        return;
    }
    
    final String modifiedServiceUrl;
    
    log.debug("no ticket and no assertion found");
    if (this.gateway) {
        log.debug("setting gateway attribute in session");
        modifiedServiceUrl = this.gatewayStorage.storeGatewayInformation(request, serviceUrl);
    } else {
        modifiedServiceUrl = serviceUrl;
    }
    
    if (log.isDebugEnabled()) {
        log.debug("Constructed service url: " + modifiedServiceUrl);
    }
    
    final String urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl, getServiceParameterName(), modifiedServiceUrl, this.renew, this.gateway);
    
    if (log.isDebugEnabled()) {
        log.debug("redirecting to \"" + urlToRedirectTo + "\"");
    }
    
    // Add a custom server login url parameter to the CAS login url.
    response.sendRedirect(urlToRedirectTo+"&customLogin=custom&customLoginPage="+customServerLoginUrl);
    
  3. 将自己编译的 cas-client-core 添加到客户端 webapp 的依赖中。

  4. 将 caslogin.jsp 添加到您的客户端 webapp。

     <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 的过滤器中添加以下代码

<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 服务器 Web 应用程序中编辑 cas-server-webapp/WEB-INF/view/jsp/default/ui/casLoginView.jsp 中的代码。

<%
  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!

我还制作了一个关于如何使用客户端自定义登录屏幕而不是服务器登录屏幕登录 cas 的示例。您可以在https://github.com/yangminxing/cas-custom-login-page上下载它

于 2016-08-15T08:27:55.390 回答
0

如果您不需要 SSO,那么可以,正如 rexposadas 所说,使用 CAS REST。这是一个很好的 java 实现示例:http ://www.bmchild.com/2014/05/a-simple-cas-java-rest-client-example.html

但这不适用于 SSO,换句话说,您将无法在 appA 中登录,然后在 appB 中自动登录。这是因为 cas 登录页面创建了一个用于 SSO 的 TGT cookie。通过 REST,您不会创建该 cookie。

但同样,如果您不需要 SSO,那么 CAS REST 就可以了。

于 2016-11-07T15:23:03.003 回答