简体   繁体   English

Tomcat Realm身份验证-登录后

[英]Tomcat Realm Authentication - After login

I am using Tomcat 8 with a DataSourceRealm and FORM authentication for logging into my webapp. 我正在使用具有DataSourceRealm和FORM身份验证的Tomcat 8登录到我的Web应用程序。 The authentication piece is working correctly but I would like to execute code immediately after a successful login. 身份验证部分工作正常,但我想在成功登录后立即执行代码。 I cannot seem to find where to put this code since nearly all the authentication is handled by tomcat. 由于几乎所有的身份验证都是由tomcat处理的,因此我似乎找不到放置此代码的位置。

Here is my html: 这是我的html:

<form method="POST" action="j_security_check">
    <table>
        <tr>
            <td colspan="2">Login Blah blah blah</td>
        </tr>
        <tr>
            <td>Name:</td>
            <td><input type="text" name="j_username" /></td>
        </tr>
        <tr>
            <td>Password:</td>
            <td><input type="password" name="j_password"/ ></td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" value="Go" /></td>
        </tr>
    </table>
</form>

and web.xml relevant info: 和web.xml相关的信息:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Protected pages</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>*</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/jsp/Login.jsp</form-login-page>
        <form-error-page>/jsp/Login.jsp?action=error</form-error-page>
    </form-login-config>
</login-config>

and my context.xml 和我的context.xml

<Realm className="org.apache.catalina.realm.DataSourceRealm"
    digest="MD5"
    allRolesMode="authOnly"
    <!-- sensitive info removed -->  />

Some examples of post login code I would like to execute are checking if password is expired, updating last login time, etc, etc... 我要执行的登录后代码示例包括检查密码是否已过期,更新上次登录时间等,等等。

I don't think it can be done with DataSourceRealm . 我认为DataSourceRealm不能做到这一点。 Which means you'll either have to write your own Realm implementation, or forget about using Tomcat to handle the logins and write your own login code. 这意味着您要么必须编写自己的Realm实现,要么忘记使用Tomcat来处理登录并编写自己的登录代码。 I would do the latter, but that's a matter of preference. 我会选择后者,但这是优先事项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM