【发布时间】:2016-06-25 20:25:35
【问题描述】:
我正在为我的 Web 应用程序使用 JdbcRealm 和基于 FORM 的身份验证,它是使用 JSF 创建的。我创建了一个用于用户管理的网页。问题是当用户更改密码时,jdbcRealm 不会立即反映更改并重定向到错误页面。
我正在使用具有以下配置的 Jetty 插件进行开发:
web.xml
<login-config>
<auth-method>FORM</auth-method>
<realm-name>RealmName</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/access-denied.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>secured</web-resource-name>
<description/>
<url-pattern>/views/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>USER</role-name>
<role-name>ADMINISTRATOR</role-name>
</auth-constraint>
</security-constraint>
pom.xml
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.RC1</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/ROOT</contextPath>
</webApp>
<dumpOnStart>true</dumpOnStart>
<loginServices>
<loginService implementation="org.eclipse.jetty.security.JDBCLoginService">
<name>RealmName</name>
<config>${project.basedir}/src/main/resources/realm.properties</config>
</loginService>
</loginServices>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
</dependencies>
</plugin>
realm.properties
jdbcdriver = com.mysql.jdbc.Driver
url = urlOfMyDatabase
username = myUser
password = myPassword
usertable = table
usertablekey = id_user
usertableuserfield = username
usertablepasswordfield = password
roletable = role
roletablekey = id_role
roletablerolefield = name
userroletable = user
userroletableuserkey = id_user
userroletablerolekey = role_id
cachetime = 300
我猜是因为缓存时间的原因,但是当我执行用户修改时,如何维护缓存并刷新呢?
以下配置是针对我的开发环境的,对于生产环境,我使用的是具有以下配置的 Tomcat:
<Realm className="org.apache.catalina.realm.JDBCRealm" driverName="com.mysql.jdbc.Driver" localDataSource="true" connectionURL="urlOfMyDatabase" connectionName="myUser" connectionPassword="myPassword" userTable="user_view" userNameCol="username" userCredCol="password" userRoleTable="user_view" roleNameCol="role"/>
我希望你能帮助我:)
【问题讨论】:
-
如何检测到这种情况?如果用户更改了他的密码,他必须已经登录。
-
如果用户更改密码,注销并尝试验证它会被重定向到错误页面