Spring Shiro 未在 SpringMVC Web 应用程序中验证登录屏幕

Spring Shiro 未在 SpringMVC Web 应用程序中验证登录屏幕

我正在尝试使用 Apache Shiro 框架 1.2.4 来满足我们的 Spring MVC Web 应用程序的安全要求。我已在下面的应用程序上下文、pom.xml 和 web.xml 中包含了配置详细信息。当用户单击登录屏幕上的提交按钮时,Shiro 不会对用户进行身份验证。您能告诉我解决此问题的任何解决方案吗?

应用程序上下文.xml

<bean id="dbdataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/Appweb" />
        </bean>

<bean id="jpaVendorAdapter"
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="true" />
    <property name="generateDdl" value="true" />
    <property name="database" value="POSTGRESQL" />
</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dbdataSource" />
    <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
    <!-- spring based scanning for entity classes -->
    <property name="packagesToScan" value="com.tracktrace.dao.jpa" />
</bean>

<bean id="jpaRealm" class="com.appweb.security.JpaShiroRealm"></bean>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager" depends-on="jpaRealm">
    <property name="realm" ref="jpaRealm" />
    <property name="sessionMode" value="native"/>
</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
    <property name="securityManager" ref="securityManager" />
    <property name="loginUrl" value="/login"/>
    <property name="successUrl" value="/"/>
    <property name="unauthorizedUrl" value="/login"/>       
    <property name="filterChainDefinitions"> 
    <value>
        /login = authc
        /login.jsp = authc 
        /** = authc 
     </value> 

    </property>
</bean>

Web.xml Appweb 应用程序

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>com.tracktrace.controller.common.SessionListener</listener-class>
</listener>
<listener>
    <listener-class>com.tracktrace.controller.common.ApplicationListener</listener-class>
</listener>
<listener>
    <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/appContext.xml</param-value>
</context-param>
<context-param>
    <param-name>shiroEnvironmentClass</param-name>
    <param-value>org.apache.shiro.web.env.DefaultWebEnvironment</param-value>
</context-param>
<servlet>
    <servlet-name>Appweb</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Appweb</servlet-name>
    <!-- <url-pattern>*.htm</url-pattern> -->
    <url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
        <param-name>targetFilterLifecycle</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

pom.xml 中的依赖项

<dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-core</artifactId>
        <version>${shiro.version}</version>
</dependency>
<dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-web</artifactId>
        <version>${shiro.version}</version>
</dependency>
<dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-aspectj</artifactId>
        <version>${shiro.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-spring</artifactId>
        <version>${shiro.version}</version>
    </dependency>

登录.jsp

<form action="">
user name:<input type="text" name="username" id="username"/><br/>
password: <input type="password" name="password" id="password"/><br/>

记住账号:

先感谢您。

相关内容