Spring Security 指定登陸入口
spring security除通過form-login的熟悉指定登陸還可以通過entry-point-ref 指定登陸入口。具體配置如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"> <!-- entry-point-ref指定登錄入口 --> <security:http entry-point-ref="authEntryPoint"> <security:logout delete-cookies="JSESSIONID" /> <security:intercept-url pattern="/login*.jsp*" access="IS_AUTHENTICATED_ANONYMOUSLY" /> <security:intercept-url pattern="/**" access="ROLE_USER" /> <!-- 添加自己定義的AuthenticationFilter到FilterChain的FORM_LOGIN_FILTER位置 --> <security:custom-filter ref="authenticationFilter" position="FORM_LOGIN_FILTER"/> </security:http> <!-- AuthenticationEntryPoint,引導用戶進行登錄 --> <bean id="authEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> <property name="loginFormUrl" value="/login.jsp"> </property> </bean> <!-- 認證過濾器 --> <bean id="authenticationFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> <property name="authenticationManager" ref="authenticationManager" /> <property name="usernameParameter" value="username"/> <property name="passwordParameter" value="password"/> <property name="filterProcessesUrl" value="/login.do" /> </bean> <security:authentication-manager alias="authenticationManager"> <security:authentication-provider user-service-ref="userDetailsService"> <security:password-encoder hash="md5"></security:password-encoder> </security:authentication-provider> </security:authentication-manager> <bean id="userDetailsService" class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl"> <property name="dataSource" ref="dataSource"></property> </bean> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/security"></property> <property name="user" value="root"></property> <property name="password" value="root"></property> <property name="acquireIncrement" value="5"></property> <!-- 當連接池中的連接用完時,C3P0一次性創建新連接的數目2 --> <property name="initialPoolSize" value="10"></property> <!-- 初始化時創建的連接數,必須在minPoolSize和maxPoolSize之間 --> <property name="minPoolSize" value="5"></property> <property name="maxPoolSize" value="20"></property> <!-- 最大空閑時間,超過空閑時間的連接將被丟棄 [需要注意:mysql默認的連接時長為8小時(28800)【可在my.ini中添加 wait_timeout=30(單位秒)設置連接超時】,這里設置c3p0的超時必須<28800] --> <property name="maxIdleTime" value="300"></property> <property name="idleConnectionTestPeriod" value="60"></property> <!-- 每60秒檢查連接池中的空閑連接 --> <property name="maxStatements" value="20"></property> <!-- jdbc的標準參數 用以控制數據源內加載的PreparedStatement數量,但由于預緩存的Statement屬 于單個Connection而不是整個連接 --> </bean> </beans>
浙公網安備 33010602011771號