簡體   English   中英

使用 Spring security 進行遠程認證

[英]Process remote authentification with Spring security

我正在嘗試從遠程網頁到我們的門戶進行一些遠程登錄。 來自遠程網頁的用戶有登錄/密碼字段,他將提交這些字段以在我們的門戶中進行身份驗證。 如果一切正常,他將被登錄。如果失敗,他將被重定向到門戶的標准登錄頁面,並出現匹配的驗證錯誤(即“無效登錄/密碼”)。

我試圖通過一個 servlet 來完成,希望表單的安全字段將通過請求傳輸,直到它們到達門戶的登錄頁面。

不幸的是,他們看起來好像沒有達到目標,因為我總是收到“無效密碼/登錄”錯誤。

由於我對 Spring 真的沒有經驗,所以我真的不確定如何實現它。 我可能會考慮通過 BASE 64 編碼數據傳遞信息,但我不知道如何將這些信息傳遞給 Spring,也不確定這是一種安全的方式。

所以,如果你們有任何想法,我會很高興地閱讀它!

這是遠程表單代碼:

<form id="connexion">
    <input id="j_username" name="j_username" type="text" value="Email" class="field"/>
    <input id="j_password" name="j_password" type="password" value="Mot de passe" class="field"/>
    <input type="button" class="btn" value="OK" onClick="javascript:register()"/>
</form>


function register(){

  urlSite=http://localhost:8080/monApp/DistantLogingServlet
this.document.location=urlSite

}

小服務程序部分:

 /**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 * @param request 
 * @param response 
 * @throws IOException 
 * @throws ServletException 
 */
 protected final void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {

    final ExternalContext context = FacesUtils.getFacesContext( request, response, servletContext).getExternalContext();

    final RequestDispatcher dispatcher = request.getRequestDispatcher("/j_spring_security_check");

    dispatcher.forward(request, (ServletResponse) context.getResponse());

    FacesContext.getCurrentInstance().responseComplete();
}

門戶網站的標准登錄頁面 (jsp):

<h:inputSecret
  id="j_password"
  type="text"
  name="j_password"
  value="#{user.password}"/>

<h:selectBooleanCheckbox
  id="_spring_security_remember_me"
  name="_spring_security_remember_me"
  value="#{user.rememberme}"
  class="float-left" /> 

<h:commandButton
  action="#{user.doLogin}"/>

和 java 認證部分:

public final String doLogin() throws IOException, ServletException {

    final ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

    final HttpServletRequest request = ((HttpServletRequest) context.getRequest());

    final RequestDispatcher dispatcher = request.getRequestDispatcher("/j_spring_security_check");

    dispatcher.forward(request, (ServletResponse) context.getResponse());

    FacesContext.getCurrentInstance().responseComplete();

    // It's OK to return null here because Faces is just going to exit.
    return null;

}

提前感謝您的關注!

這看起來像是單點登錄場景。

所以。

如果用戶已經登錄到您信任的應用程序,則您的門戶上不需要登錄表單。

執行此操作的一些標准方法是CASOpen ID ,Spring Security 支持這兩種方法。

第三種方法是在用戶成功登錄到遠程站點時在用戶的瀏覽器上設置一個 cookie,並使用 spring 過濾器查找該 cookie。 通常用於此的過濾器是AbstractPreAuthenticatedProcessingFilter (它實際上是子類)。

我還會向您指出 Spring 安全文檔的預身份驗證場景部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM