我正在使用带有DataSourceRealm和FORM身份验证的Tomcat 8来登录我的webapp。身份验证部分正常工作,但我想在成功登录后立即执行代码。我似乎无法找到放置此代码的位置,因为几乎所有的身份验证都是由tomcat处理的。
这是我的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>
和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>
和我的context.xml
<Realm className="org.apache.catalina.realm.DataSourceRealm"
digest="MD5"
allRolesMode="authOnly"
<!-- sensitive info removed --> />
我想要执行的登录后代码的一些例子是检查密码是否过期,更新上次登录时间等等......
答案 0 :(得分:1)
我不认为可以使用DataSourceRealm
完成。这意味着您要么必须编写自己的Realm
实现,要么忘记使用Tomcat来处理登录并编写自己的登录代码。我会做后者,但这是一个偏好的问题。