挑战Acegi1.0,小试牛刀,一小例(参考springside的acegi的相关文档)

本文介绍了一个使用ACEGI安全框架的示例配置,包括web.xml和applicationContext-acegi-security.xml的详细设置。该配置实现了基于数据库的身份验证、权限管理及过滤器链等功能。

1。web.xml
acegi需要的配置代码:
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
   /WEB-INF/spring-config/applicationContext.xml,
   /WEB-INF/spring-config/applicationContext-acegi-security.xml(注:spring容器中acegi的配置文件)
  </param-value>
 </context-param>
 <context-param>
  <param-name>log4jConfigLocation</param-name>
  <param-value>/WEB-INF/classes/log4j.properties</param-value>
 </context-param>
 <context-param>
  <param-name>log4jRefreshInterval</param-name>
  <param-value>60000</param-value>
 </context-param>

 <filter>
  <filter-name>Acegi Filter Chain Proxy</filter-name>
  <filter-class>
   org.acegisecurity.util.FilterToBeanProxy
  </filter-class>
  <init-param>
   <param-name>targetClass</param-name>
   <param-value>
    org.acegisecurity.util.FilterChainProxy(注:acegi1.0全权代理)
   </param-value>
  </init-param>
 </filter>
 <filter-mapping>
  <filter-name>Acegi Filter Chain Proxy</filter-name>
  <url-pattern>*.do</url-pattern>(注:只对*.do,*.jsp的url过滤)
 </filter-mapping>
 <filter-mapping>
  <filter-name>Acegi Filter Chain Proxy</filter-name>
  <url-pattern>*.jsp</url-pattern>
 </filter-mapping>
 <listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>
 <listener>
  <listener-class>
   org.springframework.web.util.Log4jConfigListener
  </listener-class>
 </listener>
 <listener>
  <listener-class>
   org.acegisecurity.ui.session.HttpSessionEventPublisher
  </listener-class>
 </listener>
2。applicationContext-acegi-security.xml
spring容器中acegi的配置代码,去掉了匿名,cookie验证,参考acegi1.0提供的例子来做的修改:
<beans>

 <!-- ======================== FILTER CHAIN ======================= -->

 <!--  if you wish to use channel security, add "channelProcessingFilter," in front
  of "httpSessionContextIntegrationFilter" in the list below -->
<!--通过代理分别执行Filter-->
 <bean id="filterChainProxy"
  class="org.acegisecurity.util.FilterChainProxy">
  <property name="filterInvocationDefinitionSource">
   <value>
    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
    PATTERN_TYPE_APACHE_ANT
    /**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,securityContextHolderAwareRequestFilter,exceptionTranslationFilter,filterInvocationInterceptor
   </value>
  </property>
 </bean>

 <!-- ======================== AUTHENTICATION ======================= -->

 <!--验证管理器-->
<bean id="authenticationManager"
  class="org.acegisecurity.providers.ProviderManager">
  <property name="providers">
   <list>
    <ref local="daoAuthenticationProvider" />
   </list>
  </property>
 </bean>

 <!--采用数据库验证-->
<bean id="jdbcDaoImpl"
  class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
  <property name="dataSource">
   <ref bean="dataSource" />
  </property>
  <property name="usersByUsernameQuery">
   <value>
    SELECT ACCOUNT,PASSWORD,1 FROM SYSTEM_USER WHERE ACCOUNT=?
   </value>
  </property>
  <property name="authoritiesByUsernameQuery">
   <value>
    SELECT U.ACCOUNT,R.NAME FROM SYSTEM_USER U,SYSTEM_ROLE R
    WHERE R.ID=U.ROLEID AND U.ACCOUNT=?
   </value>
  </property>
 </bean>

 <bean id="passwordEncoder"
  class="org.acegisecurity.providers.encoding.Md5PasswordEncoder" />

 <bean id="daoAuthenticationProvider"
  class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
  <property name="userDetailsService">
   <ref local="jdbcDaoImpl" />
  </property>
  <property name="userCache">
   <ref local="userCache" />
  </property>
  <property name="passwordEncoder">
   <ref local="passwordEncoder" />
  </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>

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

 <bean id="httpSessionContextIntegrationFilter"
  class="org.acegisecurity.context.HttpSessionContextIntegrationFilter">
 </bean>

 <bean id="securityContextHolderAwareRequestFilter"
  class="org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter" />

 <!-- ===================== HTTP CHANNEL REQUIREMENTS ==================== -->

 <!-- You will need to uncomment the "Acegi Channel Processing Filter"
  <filter-mapping> in web.xml for the following beans to be used -->

 <bean id="channelProcessingFilter"
  class="org.acegisecurity.securechannel.ChannelProcessingFilter">
  <property name="channelDecisionManager">
   <ref local="channelDecisionManager" />
  </property>
  <property name="filterInvocationDefinitionSource">
   <value>
    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
    /A/login.jsp.*/Z=REQUIRES_SECURE_CHANNEL
    /A.*/Z=REQUIRES_INSECURE_CHANNEL
   </value>
  </property>
 </bean>

 <bean id="channelDecisionManager"
  class="org.acegisecurity.securechannel.ChannelDecisionManagerImpl">
  <property name="channelProcessors">
   <list>
    <ref local="secureChannelProcessor" />
    <ref local="insecureChannelProcessor" />
   </list>
  </property>
 </bean>

 <bean id="secureChannelProcessor"
  class="org.acegisecurity.securechannel.SecureChannelProcessor" />
 <bean id="insecureChannelProcessor"
  class="org.acegisecurity.securechannel.InsecureChannelProcessor" />

 <!-- ===================== HTTP REQUEST SECURITY ==================== -->

 <bean id="exceptionTranslationFilter"
  class="org.acegisecurity.ui.ExceptionTranslationFilter">
  <property name="authenticationEntryPoint">
   <ref local="authenticationProcessingFilterEntryPoint" />
  </property>
  <property name="accessDeniedHandler">
   <bean
    class="org.acegisecurity.ui.AccessDeniedHandlerImpl">
    <property name="errorPage" value="/login.jsp" />
   </bean>
  </property>
 </bean>

 <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>/acegi.bmp</value>
  </property>
  <property name="filterProcessesUrl">
   <value>/logon.do</value>
  </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="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 ROLE_* configuration settings -->
 <bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter" />
 <!-- Note the order that entries are placed against the objectDefinitionSource is critical.
  The FilterSecurityInterceptor will work from the top of the list down to the FIRST pattern that matches the request URL.
  Accordingly, you should place MOST SPECIFIC (ie a/b/c/d.*) expressions first, with LEAST SPECIFIC (ie a/.*) expressions last -->
 <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
    /index.jsp=ROLE_USER
    /acegi.jsp=ROLE_USER,ROLE_SUPER
   </value>
  </property>
 </bean>

</beans>
3。数据库
自己随便定义的非常简单的两个表SYSTEM_USER和SYSTEM_ROLE
例子嘛,我不希望数据库搞得太复杂了,能说明问题就行
SYSTEM_USER表字段:id,account,password,roleid
SYSTEM_ROLE表字段:id,name(两条记录name=ROLE_USER,name=ROLE_SUPER)
====================================================================
上面的applicationContext-acegi-security.xml文件里面的配置有看不懂的地方可以留言,我再补充解释

1)普通用户端(全平台) 音乐播放核心体验: 个性化首页:基于 “听歌历史 + 收藏偏好” 展示 “推荐歌单(每日 30 首)、新歌速递、相似曲风推荐”,支持按 “场景(通勤 / 学习 / 运动)” 切换推荐维度。 播放页功能:支持 “无损音质切换、倍速播放(0.5x-2.0x)、定时关闭、歌词逐句滚动”,提供 “沉浸式全屏模式”(隐藏冗余控件,突出歌词与专辑封面)。 多端同步:自动同步 “播放进度、收藏列表、歌单” 至所有登录设备(如手机暂停后,电脑端打开可继续播放)。 音乐发现与管理: 智能搜索:支持 “歌曲名 / 歌手 / 歌词片段” 搜索,提供 “模糊匹配(如输入‘晴天’联想‘周杰伦 - 晴天’)、热门搜索词推荐”,结果按 “热度 / 匹配度” 排序。 歌单管理:创建 “公开 / 私有 / 加密” 歌单,支持 “批量添加歌曲、拖拽排序、一键分享到社交平台”,系统自动生成 “歌单封面(基于歌曲风格配色)”。 音乐分类浏览:按 “曲风(流行 / 摇滚 / 古典)、语言(国语 / 英语 / 日语)、年代(80 后经典 / 2023 新歌)” 分层浏览,每个分类页展示 “TOP50 榜单”。 社交互动功能: 动态广场:查看 “关注的用户 / 音乐人发布的动态(如‘分享新歌感受’)、好友正在听的歌曲”,支持 “点赞 / 评论 / 转发”,可直接点击动态中的歌曲播放。 听歌排行:个人页展示 “本周听歌 TOP10、累计听歌时长”,平台定期生成 “全球 / 好友榜”(如 “好友中你本周听歌时长排名第 3”)。 音乐圈:加入 “特定曲风圈子(如‘古典音乐爱好者’)”,参与 “话题讨论(如‘你心中最经典的钢琴曲’)、线上歌单共创”。 (2)音乐人端(创作者中心) 作品管理: 音乐上传:支持 “无损音频(FLAC/WAV)+ 歌词文件(LRC)+ 专辑封面” 上传,填写 “歌曲信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值