附录 B. 常见问题解答

Spring Security

附录 B. 常见问题解答

附录 B. 常见问题解答

B.1.

Q: 如何获得源代码

A: 在SpringSecurity的发布包中的dist目录下,包含很多“.jar”文件,名称中包含“sources”的文件中就是源文件了,比如:可以在spring-security-core-2.0.4-sources.jar中找到core模块的所有文件。

B.2.

Q: 为何登录时出现There is no Action mapped for namespace / and action name j_spring_security_check.

A: 这是因为登陆所发送的请求先被struts2的过滤器拦截了,为了试登陆请求可以被Spring Security正常处理,需要在web.xml中将Spring Security的过滤器放在struts2之前。

B.3.

Q: 用户登陆之后没有进入设置的default-target-url页面。

A: Spring Security登陆成功后的策略是,先判断用户登录前是否尝试访问过受保护的页面,如果有,则跳转到用户登录前访问的受保护页面,否则跳转到default-target-url。如果希望登陆后一直跳转到default-target-url,可以使用always-use-default-target="true"。

B.4.

Q: 如何实现国际化。

A: 在xml中添加如下配置:

<beans:bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <beans:property name="basename" value="org/springframework/security/messages" />
</beans:bean>
            

B.5.

Q: 如何监听Spring Security的事件日志。

A: 在xml中添加如下配置:

<beans:bean class="org.springframework.security.event.authentication.LoggerListener"/>

<beans:bean class="org.springframework.security.event.authorization.LoggerListener"/>
            

B.6.

Q: 如何启用group。

A: 设置enableGroups="true"才能在JdbcDaoImpl中启用group,默认是禁用的,而namespace中没有支持这个参数,所以想用group时,只好自己配置了。