acegi建立三个表

如果我一个用户不输入用户名或者用户名是错的


像这中情况就是登陆失败,你可以通过配置是页面转向失败页面。


建立三个表。


表一:用户信息表 CREATE TABLE `userinfo` (
`USER_ID` INTEGER(11) NOT NULL AUTO_INCREMENT,
`USERNAME` VARCHAR(10) NOT NULL,
`PASSWORD` VARCHAR(30) DEFAULT NULL,
`ENABLED` TINYINT(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`USER_ID`),
UNIQUE KEY `USER_ID` (`USER_ID`),
UNIQUE KEY `USERNAME` (`USERNAME`)
);
INSERT INTO `userinfo` (`USER_ID`, `USERNAME`, `PASSWORD`, `ENABLED`) VALUES
(1,'root','root',1)
表二:权限表 CREATE TABLE `authorities` (
`AUTH_ID` INTEGER(11) NOT NULL DEFAULT '0',
`AUTHORITY` VARCHAR(255) NOT NULL,
`AUTH_TYPE` VARCHAR(32) NOT NULL,
`PROTECTED_RES` VARCHAR(64) NOT NULL,
`DISPLAY` VARCHAR(64) NOT NULL,
`NOTE` VARCHAR(64) DEFAULT NULL,
PRIMARY KEY (`AUTH_ID`),
UNIQUE KEY `AUTH_ID` (`AUTH_ID`)
);

COMMIT;

INSERT INTO `authorities` (`AUTH_ID`, `AUTHORITY`, `AUTH_TYPE`, `PROTECTED_RES`, `DISPLAY`, `NOTE`) VALUES
(0,'AUTH_USER','USER','USER','一般用户权限',NULL);

表三:用户权限关联表 CREATE TABLE `user_auth` (
`USER_ID` INTEGER(11) NOT NULL DEFAULT '0',
`AUTH_ID` INTEGER(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`USER_ID`, `AUTH_ID`)
);
INSERT INTO `user_auth` (`USER_ID`, `AUTH_ID`) VALUES
(1,0)
然后进行如下配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- ======================== FILTER CHAIN ======================= -->
<!-- if you wish to use channel security, add "channelProcessingFilter," in front
of "httpSessionContextIntegrationFilter" in the list below -->
<bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy">
<property name="filterInvocationDefinitionSource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor
</value>
</property>
</bean>

<bean id="httpSessionContextIntegrationFilter" class="org.acegisecurity.context.HttpSessionContextIntegrationFilter">
<property name="context"><value>org.acegisecurity.context.security.SecureContextImpl</value></property>
</bean>

<!-- ======================== AUTHENTICATION ======================= -->
<bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">
<property name="providers">
<list>
<ref local="daoAuthenticationProvider"/>
<ref local="anonymousAuthenticationProvider"/>
</list>
</property>
</bean>

<bean id="jdbcDaoImpl" class="org.acegisecurity.providers.dao.jdbc.JdbcDaoImpl">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="usersByUsernameQuery">
<value>SELECT USERNAME, PASSWORD,ENABLED FROM USERINFO WHERE USERNAME=?</value>
</property>
<property name="authoritiesByUsernameQuery">
<value>
SELECT username,authority FROM `userinfo` u, `authorities` a,`user_auth` ua
WHERE u.user_id=ua.user_id
and a.auth_id=ua.auth_id
and u.username = ?
</value>
</property>
</bean>

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/>

<bean id="userCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager"> <ref local="cacheManager"/> </property>
<property name="cacheName"> <value>userCache</value> </property>
</bean>

<bean id="userCache" class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache">
<property name="cache"><ref local="userCacheBackend"/></property>
</bean>

<bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
<property name="authenticationDao"><ref local="jdbcDaoImpl"/></property>
<property name="userCache"><ref local="userCache"/></property>
</bean>

<!-- Automatically receives AuthenticationEvent messages from DaoAuthenticationProvider -->
<bean id="loggerListener" class="org.acegisecurity.event.authentication.LoggerListener"/>

<bean id="anonymousProcessingFilter" class="org.acegisecurity.providers.anonymous.AnonymousProcessingFilter">
<property name="key"><value>foobar</value></property>
<property name="userAttribute"><value>anonymousUser,AUTH_ANONYMOUS</value></property>
</bean>

<bean id="anonymousAuthenticationProvider" class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider">
<property name="key"><value>foobar</value></property>
</bean>

<!-- ===================== HTTP REQUEST SECURITY ==================== -->
<bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="authenticationFailureUrl"><value>/login.jsp?login_error=1</value></property>
<property name="defaultTargetUrl"><value>/index.jsp</value></property>
<property name="filterProcessesUrl"><value>/j_acegi_security_check</value></property>
</bean>

<bean id="securityEnforcementFilter" class="org.acegisecurity.intercept.web.SecurityEnforcementFilter">
<property name="filterSecurityInterceptor"><ref local="filterInvocationInterceptor"/></property>
<property name="authenticationEntryPoint"><ref local="authenticationProcessingFilterEntryPoint"/></property>
</bean>

<bean id="authenticationProcessingFilterEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
<property name="loginFormUrl"><value>/login.jsp</value></property>
<property name="forceHttps"><value>false</value></property>
</bean>

<bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="accessDecisionManager"><ref local="httpRequestAccessDecisionManager"/></property>
<property name="objectDefinitionSource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/login.jsp*=AUTH_ANONYMOUS,AUTH_USER
/**=AUTH_USER
</value>
</property>
</bean>

<bean id="httpRequestAccessDecisionManager" class="org.acegisecurity.vote.AffirmativeBased">
<property name="allowIfAllAbstainDecisions"><value>false</value></property>
<property name="decisionVoters">
<list>
<ref bean="roleVoter"/>
</list>
</property>
</bean>
<!-- An access decision voter that reads AUTH_* configuration settings -->
<bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter">
<!-- set that this voter can only used for AUTH_ started roles! -->
<property name="rolePrefix"><value>AUTH_</value></property>
</bean>
</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值