自定义WSO2 IS登录错误消息

时间:2017-07-20 19:58:42

标签: authentication saml-2.0 wso2is

我正在使用WSO2 5.2。我创建了一个自定义的UserStoreManager,它扩展了JDBCUserStoreManager并且是只读的。以下是user-mgt.xml的片段。

    <UserStoreManager class="org.arbfile.wso2.user.ReadOnlyJDBCUserStoreManager">
        <Property name="TenantManager">org.wso2.carbon.user.core.tenant.JDBCTenantManager</Property>
        <Property name="ReadOnly">true</Property>
        <Property name="ReadGroups">false</Property>
        <Property name="WriteGroups">false</Property>
        ........
    </UserStoreManager>

在用户身份验证方面,我在自定义类的doAuthenticate()方法中进行用户/密码验证。我还做了IP过滤和用户帐户锁定等其他检查。当这些其他项失败时,我可以抛出UserStoreException。我遇到的问题是根据某些故障情况设置相应的错误消息。我找到了以下链接https://docs.wso2.com/display/IS500/Customizing+Authentication+Error+Messages,但信息太模糊了。我需要知道如何设置一个新的&#34;自定义错误消息,因此身份验证端点可以将其传递给login.jsp,在其中呈现它。现在,无论发生什么错误,我都会收到完全相同的错误消息。

编辑:为了清晰起见,添加了html表单代码:

<form action="../commonauth" method="post" id="loginForm">

<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 form-group">
    <input id="username" name="username" type="text" class="form-control" tabindex="0" placeholder="Username">
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 form-group">
    <input id="password" name="password" type="password" class="form-control" placeholder="Password" autocomplete="off">
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 form-group">
    <input type="hidden" name="sessionDataKey" value='e04168f9-95c7-4b87-93af-60e1ecdc6273'/>
</div>

<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 form-group">
    <div class="form-actions">
        <button class="wr-btn green-ltgr col-xs-12 col-md-12 col-lg-12 uppercase font-extra-large" type="submit">Login</button>
    </div>
</div>
</form>

我正在使用SAML,这是在WSO2服务器上基于表单登录的表单。表单操作是&#34; ../ commonauth&#34;。使用用户名和密码的表单提交似乎是针对不同的Web应用程序(而不是authenticationendpoint Web应用程序)。上面的代码来自basicauth.jsp。

2 个答案:

答案 0 :(得分:0)

几个月前,我有完全相同的要求,但找不到合适的解决方案。每次向登录页面发送相同的错误代码时,我都会发现 BasicAutheticator 。作为一种解决方法,我改变了我的流程并决定自定义登录应用程序而不是自定义WSO2错误代码。我知道这是一种错误的做法,但它解决了我的问题。以下是我的新架构的工作原理。

  1. 我创建了一个包含所有预认证检查逻辑的库,让我们将其命名为validation.jar

  2. 然后我将此库作为maven依赖项添加到 authenticationendpoint 的登录应用程序。

  3. 在登录应用程序中创建一个新的servlet,让它命名为PreValidation.java

  4. 修改了basicAuth.jsp,而不是将表单提交到/ samlsso,将表单提交给 PreValidation servlet。

  5. 在PreValidation servlet中,在validation.jar的帮助下,执行除身份验证之外的所有验证(应该是WSO2的任务)。

  6. 如果任何验证失败,请将相应的错误代码传回login.jsp并在屏幕上显示该消息。

  7. 如果所有验证都已完成,请将请求提交给WSO2并让流程继续。

  8. 希望这会对你有所帮助。

答案 1 :(得分:0)

application-authentication.xml启用错误代码后,您可以编辑以下JSP以显示错误消息。

  • 登录失败BasicAuth: - [IS_HOME] \ repository \ deployment \ server \ webapps \ authenticationendpoint \ basicauth.jsp
  • 剩余尝试结束: - [IS_HOME] \ repository \ deployment \ server \ webapps \ authenticationendpoint \ retry.jsp

请查看Get请求中的网址。它包含相关的错误代码。希望这有助于某人。