别人的都是最佳实践,因为我目前的设置没有按照参考文档推荐,还是采用DelegatingFilterProxy,所以我只能说简明实践。先贴我的applicationContext-security.xml

<?xml version="1.0" encoding="UTF-8"?>  

<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/<a href="http://lib.csdn.net/base/javaee" class='replace_word' title="Java EE知识库" target='_blank' style='color:#df3434; font-weight:bold;'>spring</a>-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd">
<global-method-security secured-annotations="enabled">
</global-method-security>
<http auto-config="true"> <!-- intercept-url pattern="/**" filters="none" /-->
<intercept-url pattern="/login.jsp*" filters="none"/>
<intercept-url pattern="/common/pages/**" access="IS_AUTHENTICATED_REMEMBERED" />
<intercept-url pattern="/common/**" filters="none" />
<intercept-url pattern="/secure/extreme/**" access="ROLE_SUPERVISOR"/>
<intercept-url pattern="/secure/**" access="IS_AUTHENTICATED_REMEMBERED" />
<intercept-url pattern="/**" access="IS_AUTHENTICATED_REMEMBERED" /> <form-login login-page='/login.jsp' authentication-failure-url="/login.jsp?login_error=1" default-target-url='/index.jsp' /> </http>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
group-authorities-by-username-query="select U.username,G.group_name,GA.authority as 'authority' from users U join group_members GM on U.username=GM.username join groups G on GM.group_id=G.id join group_authorities GA on G.id=GA.group_id where U.username=?"
/> <password-encoder hash="plaintext"/>
</authentication-provider>
</beans:beans>

对上面的配置说明一下,form-login的authentication-failure-url和default-target-url属性设置基本就可以免去使用ExceptionTranslationFilter的麻烦,authentication-provider使用上面这个配置方式是最方便可用的,至于因为我的数据库建立在sql Server上,所以添加了group-authorities-by-username-query属性,password-encoder我个人建议采用参考文档上推荐的以username做salt的sha编码,我这儿使用plaintext,是因为我这个项目目前还在开发测试阶段,用户管理这个模块还没有完全建立,所以为了测试的方便,用了plaintext的编码。那个dataSource,我是按照API文档推荐,建立了一个容器JNDI,然后在spring里用JndiObjectFactoryBean代理了一下。

用户管理的设施代码采用以JdbcUserDetailsManager为主,jdbcTemplate为辅的方式,其中前者不要建立在springContext下面,否则会导致多userDetailService冲突。

下面说一下spring Security国际化(i18N)的配置处理,先贴代码:

<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/ssm"/>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver"/>

注意了:我上面的bean定义不在applicationContext-security.xml里面,而是在一个以beans作为默认命名空间的applicationContext-beans.xml里面,我说一下上面这个配置做的时候出现的问题,其中的basename的value,我刚开始采用开发指南上说的"org/springframework/security/messages",可是始终找不到jar包里面的messages文件,后来,我看了一个老外的同问题贴,他采用上面这种方式,把messages文件放在了/WEB-INF/下面,反正这种配置方式下,messages文件终于可以找到,i18N可以正常运行了,至于那个messages文件,还是从jar包里面解压出来的东西。

Spring Security简明实践及相关国际化处理的更多相关文章

  1. Spring Security 学习+实践

    Spring Security是Spring为解决应用安全所提供的一个全面的安全性解决方案.基于Spring AOP和Servlet过滤器,启动时在Spring上下文中注入了一组安全应用的Bean,并 ...

  2. Spring Security教程(5)---- 国际化配置及UserCache

    这一章是为了给后面的讲解打基础的,主要介绍下国际化的配置及UserCache的配置及使用 国际化配置 <!-- 定义上下文返回的消息的国际化 --> <bean id="m ...

  3. Spring Security 入门(1-9)国际化的使用

  4. Spring Security Auth/Acl 实践指南

    目录 导语 Web Api Authentication/Authorization 示例接口 添加 Maven 依赖 实现接口 访问接口 认证/鉴权 配置认证/鉴权 添加 Maven 依赖 创建数据 ...

  5. Spring Security 入门详解(转)

    1.Spring Security介绍 Spring Security是基于spring的应用程序提供声明式安全保护的安全性框架,它提供了完整的安全性解决方案,能够在web请求级别和方法调用级别 处理 ...

  6. Spring Security 与 OAuth2 介绍

    个人 OAuth2 全部文章 Spring Security 与 OAuth2(介绍):https://www.jianshu.com/p/68f22f9a00ee Spring Security 与 ...

  7. Spring Security 入门详解

    序:本文主要参考 spring实战 对里面的知识做一个梳理 1.Spring Security介绍 Spring Security是基于spring的应用程序提供声明式安全保护的安全性框架,它提供了完 ...

  8. Spring Security 与 OAuth2(介绍)

    https://www.jianshu.com/p/68f22f9a00ee Spring Security 与 OAuth2(介绍) 林塬 2018.01.23 11:14* 字数 3097 阅读 ...

  9. oauth2 Spring Security

    oauth2四种授权方式小结 http://www.ruanyifeng.com/blog/2019/04/oauth-grant-types.html 密码模式(resource owner pas ...

随机推荐

  1. IE浏览器打印的页眉页脚设置解决方法

    首先说明问题: 默认情况下,通过IE的打印对话框,打印出来的内容都有页眉和页脚的. 查看ie的页面设置发现如右图中,页眉页脚 下面先说明&w&bPage&p of &P ...

  2. Android解析中国天气接口JSon数据,应用于天气查询!

    android解析Json数据是比较常见的一种操作.也是客户端和服务器进行数据交互的桥梁.下面就来看一看在android中解析JSon数据的方法吧. 首先要想获得Json数据,就必须访问相关的网络接口 ...

  3. VC++读取图像RGB值

    代码: #include <iostream> #include <fstream> #include <string> #include <windows. ...

  4. 海量数据挖掘MMDS week4: 推荐系统之数据降维Dimensionality Reduction

    http://blog.csdn.net/pipisorry/article/details/49231919 海量数据挖掘Mining Massive Datasets(MMDs) -Jure Le ...

  5. Leetcode_13_Roman to Integer

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41486885 通过本文你可能学到的知识如下: (1)理解本 ...

  6. (NO.00001)iOS游戏SpeedBoy Lite成形记(三)

    在Xcode中建立新类Player,继承自CCSprite.因为我们之后需要方便的更换玩家的大头贴,所以需要能够以不同的大头贴参数初始化Player对象. 不过别急,想想我们还需要在Player对象初 ...

  7. How To Get Log, Trace Files In OA Framework Pages And Concurrent Request Programs

    Goal   Solution   References APPLIES TO: Oracle Supplier Lifecycle Management - Version 12.1.2 and l ...

  8. hadoop namenode格式化问题汇总

    hadoop namenode格式化问题汇总 (持续更新) 0 Hadoop集群环境 3台rhel6.4,2个namenode+2个zkfc, 3个journalnode+zookeeper-serv ...

  9. 【Android 应用开发】Android - TabHost 选项卡功能用法详解

    TabHost效果图 : 源码下载地址 : http://download.csdn.net/detail/han1202012/6845105        . 作者 :万境绝尘  转载请注明出处  ...

  10. getJSONObject与optJSONObject的区别,结合源码分析

    *json解析常见问题: getJSONObject与optJSONObject的区别,下面结合源码和案例来分析当我们使用这两周方法来解析数据时,哪种比较好. 源码分析: //使用getJSONObj ...