2012-04-05 76 views
2

我正在尝试做一些从远程网页远程登录到我们的门户。 来自远方网页的用户具有登录/密码字段,他将在我们的门户网站中提交处理认证。如果一切正常,他将被记录。如果失败,他将被重定向到具有匹配的验证错误(即“无效登录/密码”)的门户的标准登录页面。用Spring安全进程远程认证

我试图通过一个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 

} 

该servlet部分:

/** 
* @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; 

} 

提前感谢您的关注!

回答

1

这看起来像是单一登录场景。

所以。

如果用户已经登录到您信任的应用程序,那么您的门户上不需要登录表单。

这样做的一些标准方法是CASOpen ID,Spring Security支持这两种方法。

第三种方法是在成功登录到远程站点并使用弹簧过滤器查找该cookie时,在用户浏览器上设置一个cookie。通常用于此的过滤器是AbstractPreAuthenticatedProcessingFilter(实际上它是子类)。

我还会指出你的春季安全文档的Pre-Authentication scenarios部分。

+0

其实,它不是一个单一的标志。这只是另一个用户可以登录的地方。这并不意味着他也会登录远程网站。这是一个标准的认证,但有一个远程点。无论如何,我会看看你的链接。感谢 – Marvin 2012-04-05 10:03:38

+0

他必须登录两次?如果是的话,为什么呢? – Simeon 2012-04-05 10:47:11

+0

不,他可以从标准登录页面登录,保存在我们的web应用程序中,或者从一个修改器的网页登录。在这种情况下,合作伙伴将包括我首先包含的一段代码,这段代码将导致用户被重定向到我们的webapp,直接连接到私有部分(如果连接成功),或者直接连接到标准登录页面(从我们的Web应用程序) – Marvin 2012-04-05 12:13:42