2

アプリケーションにjasig-CASを実装しましたが、もっと知りたいです。自分のログインページを作成して、CASでユーザーを自動的に(バックグラウンドで)認証することは可能ですか?したがって、次の手順は次のとおりです。

  1. ユーザーがログインページに移動します
  2. ユーザーが自分の資格情報を入力します
  3. 認証が成功すると、ユーザーのクレデンシャルがCASに送信されるため、CASはシステム内のユーザーを認証し、チケットを提供します(ユーザーにはCASページは表示されません)。
  4. ユーザーが保護されたページにアクセスする

ありがとう。

4

5 に答える 5

1

REST API を使用できます。 キャスレスト

これをログイン、つまり 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
  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 をクライアント Web アプリケーションの依存関係に追加します。

  4. caslogin.jsp をクライアント Web アプリケーションに追加します。

     <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

外部フォームを使用して資格情報を入力することはお勧めできず、攻撃対象領域が広がります。https://apereo.github.io/cas/5.0.x/planning/Security-Guide.htmlを参照してください。

外部フォーム アプリケーションが侵害された場合、攻撃者はすべての SSO 接続システムにアクセスできます。

于 2017-03-22T13:11:43.390 に答える