`
anson_xu
  • 浏览: 506013 次
  • 性别: Icon_minigender_1
  • 来自: 惠州
社区版块
存档分类

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>



分享到:
评论

相关推荐

    acegi 例子 近企业中项目中使用的项目架构 支持数据库

    在这个例子中,我们可以找到三个核心的数据库表:用户表、用户角色表和权限角色表。用户表存储用户的详细信息,用户角色表连接用户和他们的角色,而权限角色表则定义了角色所拥有的权限。 用户表可能包含字段如`...

    spring-Acgei的一个小例子之三

    Acegi相關類別之間的依賴關係,可以藉由IoC容器來協助建立,在這邊您可以使用 Spring 的IoC容器功能,您可以在下載的Acegi檔案中,找到acegi-security-sample-tutorial.war,將之使用解壓縮軟體解 開,可以在WEB-INF...

    权限管理 struts2 hiberante3.5 spring3.0 annotation

    Struts2、Hibernate3.5和Spring3.0是Java Web开发中的三个核心框架,它们在权限管理中扮演着重要角色。这篇详细说明将深入探讨这三个框架如何协同工作,以及如何利用注解(Annotation)来简化配置。 Struts2是一个...

    spring+hibernater+struts权限管理

    在IT行业中,尤其是在Web应用程序开发领域,Spring、Hibernate和Struts是三个非常重要的框架,它们分别专注于不同层面的问题。Spring作为一个全面的轻量级框架,提供了依赖注入(DI)、面向切面编程(AOP)以及丰富...

    关于shiro的介绍

    Shrio 架构有三个核心概念: * Subject(主体) * SecurityManager * Realms(领域) 知识点四:RBAC 权限设计模型 RBAC 权限设计模型基于角色的权限访问控制(Role-Based Access Control),作为传统访问控制...

    spring-security3.2.5

    pring Security 的前身是 Acegi Security ,是 Spring 项目组中用来提供安全认证服务的框架。 Spring Security 为基于J2EE企业应用软件提供了全面安全服务。特别是使用领先的J2EE解决方案-Spring框架开发的企业软件...

    spring security3.2.0

    Spring Security 的前身是 Acegi Security ,是 Spring 项目组中用来提供安全认证服务的框架。 Spring Security 为基于J2EE企业应用软件提供了全面安全服务。特别是使用领先的J2EE解决方案-Spring框架开发的企业...

    SSH集成Spring+hibernate+security 用户管理

    SSH集成是Java开发中一种常见的技术栈组合,主要包括Spring、Hibernate和Struts(或Spring MVC)这三个框架。在这个项目中,SSH被用来构建一个用户管理系统,实现了用户的基本操作以及权限控制功能。以下是对这些...

    spring in action英文版

    第三部分 Spring在Web层的应用  第8章 建立Web层  8.1 开始Spring MVC之旅  8.1.1 请求生命中的一天  8.1.2 配置DispatcherServlet  8.1.3 Spring MVC概述  8.2 将请求映射到控制器  8.2.1 将...

    基于SSH框架的电影票订票系统

    SSH框架是Java Web开发中的一个经典组合,包括Struts、Spring和Hibernate三个开源框架。Struts提供了MVC(Model-View-Controller)设计模式的实现,负责处理用户请求并更新视图;Spring作为一个全面的轻量级应用框架...

    spring framework reference htmlsingle(单机英文版reference)

    Spring JDBC模块简化了数据库操作,而ORM模块则帮助开发者在Java对象和数据库表之间建立映射。 五、MVC框架 Spring MVC是Spring提供的一个用于构建Web应用程序的模块。它提供了模型-视图-控制器架构,使得开发者...

Global site tag (gtag.js) - Google Analytics