0

通过使用 Spring 安全性,当我让我的应用程序网页打开一段时间后,身份验证将丢失,用户必须再次登录,因此当我单击应用程序中的按钮或链接以完成我的工作时,会出现此异常:

Etat HTTP 500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: org.springframework.beans.NotReadablePropertyException: Invalid property 'principal.username' of bean class [org.springframework.security.authentication.AnonymousAuthenticationToken]: Bean property 'principal.username' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

所以我想隐藏这个并显示一个漂亮的页面,说用户必须登录,因为用户可能不理解 tomcat 的消息,他可能会害怕!有什么建议么 ?

/* 编辑 */

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/security"
        xmlns:beans="http://www.springframework.org/schema/beans" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.0.xsd">

        <http auto-config="true">
            <intercept-url pattern="/" access="ROLE_ADMIN,ROLE_USER" />
            <intercept-url pattern="/index*" access="ROLE_ADMIN,ROLE_USER" />
            <intercept-url pattern="/mise_a_jour*" access="ROLE_ADMIN,ROLE_USER" />
            <intercept-url pattern="/recherche*" access="ROLE_ADMIN,ROLE_USER" />
            <intercept-url pattern="/pages/*" filters="none" />
            <intercept-url pattern="/css/*" filters="none" />
            <intercept-url pattern="/js/*" filters="none" />
            <intercept-url pattern="/images/*" filters="none" />
            <form-login login-page="/login" authentication-failure-url="/failLogin" />
            <logout logout-success-url="/logoff" />
            <access-denied-handler error-page="/403" />

        </http>



   <beans:bean id="concurrencyFilter"
          class="org.springframework.security.web.session.ConcurrentSessionFilter">
        <beans:property name="sessionRegistry" ref="sessionRegistry" />
        <beans:property  name="expiredUrl" value="/session-expired"  />
      </beans:bean>

        <authentication-manager>
            <authentication-provider>
                <password-encoder hash="sha" />
                <jdbc-user-service data-source-ref="dataSource"
                    users-by-username-query="select login,password, enable from utilisateurs where login=?"
                    authorities-by-username-query="select u.login, r.role from utilisateurs u, roles r where u.id = r.id and u.login =?  " />
            </authentication-provider>
        </authentication-manager>


    </beans:beans>

堆栈跟踪:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionRegistry' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
    ... 25 more
4

1 回答 1

0

您可以设置一个名为 expired-url 的配置,如下所示

<beans:bean id="concurrencyFilter"
      class="org.springframework.security.web.session.ConcurrentSessionFilter">
    <beans:property name="sessionRegistry" ref="sessionRegistry" />
    <beans:property **name="expiredUrl" value="/session-expired.htm"** />
  </beans:bean>

更多信息在这里http://static.springsource.org/spring-security/site/docs/3.0.x/reference/session-mgmt.html

于 2013-05-21T17:34:07.303 回答