`

Pathway from ACEGI to Spring Security 2.0(3)

阅读更多
  1. OK, so now we have setup the database based resources and now the next step is to get Spring Security to read the user details from the database. The examples that come with Spring Security 2.0 shows you how to keep a list of users and authorities in the configuration file like this:
    1. <authentication-provider>  
    2.     <user-service>  
    3.     <user name="rod" password="password" authorities="ROLE_SUPERVISOR, ROLE_USER" />  
    4.     <user name="dianne" password="password" authorities="ROLE_USER,ROLE_TELLER" />  
    5.     <user name="scott" password="password" authorities="ROLE_USER" />  
    6.     <user name="peter" password="password" authorities="ROLE_USER" />  
    7.     </user-service>  
    8. </authentication-provider>  
    You could replace these examples with this configuration so that you can read the user details straight from the database like this:
    1. <authentication-provider>  
    2.     <jdbc-user-service data-source-ref="dataSource" />  
    3. </authentication-provider>  
    While this is a very fast and easy way to configure database based security it does mean that you have to conform to a default databases schema. By default, the <jdbc-user-service> requires the following tables: user, authorities, groups, group_members and group_authorities.
    In my case this was not going to work as my security schema it not the same as what the <jdbc-user-service> requires, so I was forced to change the <authentication-provider>:
    1. <authentication-provider>  
    2.     <jdbc-user-service data-source-ref="dataSource"  
    3.     users-by-username-query="SELECT U.username, U.password, U.accountEnabled AS 'enabled' FROM User U where U.username=?"  
    4.     authorities-by-username-query="SELECT U.username, R.name as 'authority' FROM User U JOIN Authority A ON u.id = A.userId JOIN Role R ON R.id = A.roleId WHERE U.username=?"/>  
    5. </authentication-provider>  
    By adding the users-by-username-query and authorities-by-username-query properties you are able to override the default SQL statements with your own. As in ACEGI security you must make sure that the columns that your SQL statement returns is the same as what Spring Security expects. There is a another property group-authorities-by-username-query which I am not using and have therefore left it out of this example, but it works in exactly the same manner as the other two SQL statements.

    This feature of the <jdbc-user-service> has only been included in the past month or so and was not available in the pre-release versions of Spring Security. Luckily it has been added as it does make life a lot easier. You can read about this here and here.

    The dataSource bean instructs which database to connect to, it is not included in my configuration file as it's not specific to security. Here is an example of a dataSource bean for those who are not sure:
    1. <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
    2.     <property name="driverClassName" value="com.mysql.jdbc.Driver"/>  
    3.     <property name="url" value="jdbc:mysql://localhost/db_name?useUnicode=true&characterEncoding=utf-8"/>  
    4.     <property name="username" value="root"/>  
    5.     <property name="password" value="pwd"/>  
    6. </bean>  
  2. And that is all for the configuration of Spring Security. My last task was to change my current logon screen. In ACEGI you could create your own logon <form> by making sure that you POSTED the correctly named HTML input elements to the correct URL. While you can still do this in Spring Security 2.0, some of the names have changed.
    You can still call your username field j_username and your password field j_password as before.
    1. <input type="text" name="j_username" id="j_username"/>  
    2. <input type="password" name="j_password" id="j_password"/>  
    However you must set the action property of your <form> to point to j_spring_security_check and not j_acegi_security_check.
    1. <form method="post" id="loginForm" action="<c:url value='j_spring_security_check'/>"  
    There are a few places in our application where the user can logout, this is a link that redirects the logout request to the security framework so that it can be handled accordingly. This needs to be changed from j_acegi_logout to j_spring_security_logout.
    1. <a href='<c:url value="j_spring_security_logout"/>'>Logout</a>  

Conclusion

This short guide on how to configure Spring Security 2.0 with access to resources stored in a database does not come close to illustrating the host of new features that are available in Spring Security 2.0, however I think that it does show some of the most commonly used abilities of the framework and I hope that you will find it useful.

One of the benefits of Spring Security 2.0 over ACEGI is the ability to write more consice configuration files, this is clearly shown when I compare my old ACEGI configration (172 lines) file to my new one (42 lines).
Here is my complete securityContext.xml file:

  1. <?xml version="1.0" encoding=
分享到:
评论

相关推荐

    Spring Security 2 参考手册 中文版 (html格式)

    `z-pathway-acegi-spring-security.html`可能涉及Acegi安全系统的过渡信息,因为Spring Security最初是作为Acegi的后续项目发展起来的。这部分内容可能帮助那些从Acegi迁移到Spring Security的开发者理解两者之间的...

    Portable_Pathway_Builder_Tool 信号通路选件

    "Portable Pathway Builder Tool 2.0"版本在前一版本的基础上进行了优化升级,可能包括更丰富的图形库、增强的编辑功能、以及更好的兼容性。用户可以预设或自定义各种通路元素的形状、颜色和大小,以适应不同的展示...

    IPA-Ingenuity Pathway Analysis

    IPA(Ingenuity Pathway Analysis)是一款在生物信息学领域广泛应用的通路分析工具,它专为研究人员提供了一整套分析方案,以理解基因表达数据、蛋白质组学数据或其他分子交互数据背后的生物学意义。这款软件的强大...

    PyPI 官网下载 | pathway2cyjs-0.0.3-py3-none-any.whl

    from pathway2cyjs import Pathway2CyJS # 加载生物通路数据 pathway_data = ... # 创建转换器对象 converter = Pathway2CyJS() # 转换数据并获取JSON cyjs_json = converter.convert(pathway_data) # 将JSON...

    Microarray Analysis of the Secretory Pathway Genes Response to TuMV Infection in Brassica rapa

    利用基因芯片分析TuMV侵染对白菜分泌途径基因的影响,李彦肖,张昌伟,前人研究发现病毒的复制复合体(viral RNP complex)和病毒RNA通过分泌途径移动到胞间连丝。本研究通过拟南芥基因芯片鉴定病原物侵染引�

    Pathway_Builder

    软件名字叫做 pathway builder tool 官网是http: www proteinlounge com PathwayBuilder aspx(官网可以7天试用) 软件自带几乎所有分子生物学会用到的元素 如不同的细胞 细胞器 分子 老鼠模型 另外 这个软件自带...

    Notch1 signaling pathway

    通过对三种胰腺癌细胞系(BxPC-3、HPAC和PANC-1)进行实验,研究人员采用多种细胞生物学技术和分子生物学方法,如MTT细胞活力检测、流式细胞术、基因转染、实时RT-PCR和Western Blot等,探讨了Notch1下调后对胰腺癌...

    pathwaytool

    这款软件基于Pathway/Genome Database (PGDB) 数据库,提供了丰富的生物信息分析功能,包括基因功能注释、通路分析、基因集富集分析以及差异表达基因的可视化。 PathwayTool的核心功能: 1. **通路分析**:...

    Protein Networks and Pathway Analysis (Methods in Molecular Biology)

    《蛋白质网络与途径分析》(Protein Networks and Pathway Analysis)是分子生物学方法系列书籍中的一部,由尤里·尼科尔斯基(Yuri Nikolsky)和朱莉·布莱恩特(Julie Bryant)编辑,专注于蛋白质网络和生物途径的...

    Unsupervised Learning From Video to Detect Foreground Objects in

    3. Teacher-Student 模型 为了实现无监督学习检测单图像前景对象,我们提出了一个基于 Teacher-Student 模型的方法。该模型由两个部分组成:Teacher pathway 和 Student pathway。Teacher pathway 负责在视频数据中...

    Measurement of Mitochondrial Respiration in Isolated Protoplasts

    The AOX pathway is thought to act as a safety valve, preventing overreduction of the ETC and protecting cells from oxidative damage. 3. Mesophyll Protoplasts and Their Isolation Mesophyll ...

    A histone methylation-dependent DNA methylation pathway is uniquely impaired by deficiency in S-adenosylhomocysteine hydrolase

    A histone methylation-dependent DNA methylation pathway is uniquely impaired by deficiency in S-adenosylhomocysteine hydrolase

    dos下的pathway开发包

    3. **调试器**:为了帮助开发者定位和修复错误,Pathway提供了调试工具。这可能是一个基于命令行的调试器,允许设置断点、查看内存、单步执行代码等功能。 4. **其他工具**:除了核心组件外,Pathway开发包可能还...

    pathway系统设计

    3. **可视化工具**:设计直观的用户界面和交互式图表,帮助研究者快速理解和解释Pathway信息。这些工具应能够动态显示Pathway网络,突出关键节点和边,以及提供对特定通路的详细视图。 4. **算法优化**:开发高效的...

    工艺流程绘图软件

    在Portable_Pathway_Builder_Tool_2.0这个压缩包文件中,很可能包含的是这款工艺流程绘图软件的便携版本。便携版软件的一大优点是无需安装,可以直接运行,不会在用户的电脑上留下任何痕迹,方便在不同设备间切换...

    A Pathway Into Number Theory

    R. P. Burn的数论入门,非常好的一本数论指导书,影印版

    Introduction to Visual Computing: Core Concepts in Computer Vision, Graphics

    convolution, spectral analysis and feature detection) and corresponds to the low level retinal image processing that happens in the eye in the human visual system pathway. The next part of the book ...

Global site tag (gtag.js) - Google Analytics