`

spring security原理图及其解释(三)

 
阅读更多
What is spring_security_login and how did we get here?

You may have noticed that when you attempted to hit the home page of our JBCP Pets store, you were redirected to the URL http://localhost:8080/JBCPPets/ spring_security_login




The spring_security_login portion of the URL represents a default login page as named in the DefaultLoginPageGeneratingFilter class. We can use configuration attributes to adjust the name of this page to be something unique to our application.

Let's look at the HTML source of this form (stripping out table layout information) to figure out what the UsernamePasswordAuthenticationFilter is expecting:

<form name='f' action='/JBCPPets/j_spring_security_check' method='POST'>
    User:<input type='text' name='j_username' value=''>
    Password:<input type='password' name='j_password'/>
    <input name="submit" type="submit"/>
    <input name="reset" type="reset"/>
</form>

As our application is not utilizing the security component of our host servlet container, we could explicitly configure the UsernamePasswordAuthenticationFilter to expect form fields with different names. This particular configuration change is more complicated than you might expect; so for now, we'll trace back the lineage of UsernamePasswordAuthenticationFilter to see how it arrived in our configuration in the first place

The UsernamePasswordAuthenticationFilter is configured through the use of the <form-login> sub-element of the <http> configuration directive. As we mentioned earlier in this chapter, the auto-config attribute that we set will automatically add <form-login> capability to your application if you haven't explicitly included the directive. As you may guess, the j_spring_security_check URL doesn't map to anything physical in our application. This is a special URL that is watched for by the UsernamePasswordAuthenticationFilter to handle form-based login. In fact, there are several of these special URLs that cover specific global behavior in Spring Security. You'll find a table of these URLs in Appendix, Additional Reference Material.

Where do the user's credentials get validated?

In our simple three-step configuration file, we used an in-memory credential store to get up and running quickly:

<authentication-manager alias="authenticationManager">
        <authentication-provider>
                <user-service>
                        <user authorities="ROLE_USER" name="guest" password="guest"/>
                </user-service>
        </authentication-provider>
</authentication-manager>

We didn't wire this AuthenticationProvider to any explicit implementation, and we see once again that the security namespace handler performs a lot of rote configuration work on our behalf. Remember that the default implementation of the AuthenticationManager supports configuration of one or more AuthenticationProvider implementations. The <authentication-provider> declaration will by default instantiate an out of the box implementation known as o.s.s.authentication.dao.DaoAuthenticationProvider. The declaration of the <authentication-provider> element will also automatically wire this AuthenticationProvider to the configured (or, in our case, automatically configured) AuthenticationManager.

AuthenticationProvider虽然没有指定实现类,但是系统默认为我们指定了。而且默认的AuthenticationManager实现支持一个或者多个AuthenticationProvider。<authentication-provider>默认声明一个箱外的实现DaoAuthenticationProvider,用它来声明的会自动装配到AuthentiacationManager里面。

The DaoAuthenticationProvider is an AuthenticationProvider that provides a thin wrapper to implement the AuthenticationProvider interface and then delegates to an implementation of the o.s.s.core.userdetails. UserDetailsService interface. The UserDetailsService is responsible for returning an implementation of o.s.s.core.userdetails.UserDetails.

DaoAuthenticationProvider是一种AuthenticationProvider并且提供了一层AuthenticationProvider接口的简单实现,它代理UserDetailsService的实现。UserDetailsService 负责返回一个UserDetails的实现。

If you review the Javadoc for UserDetails, you'll notice that it looks strikingly similar to the Authentication interface we reviewed earlier. Don't get confused, although they have a lot of overlap in method names and capabilities, they have quite different purposes:

如果你重新看javadoc来查看UserDetails,你会发现它和接口Authentication非常相似。不要搞混了,虽然他们有很多重复的方法名和容器,但是他们有不同的目的:





Our declaration of the <user-service> subelement triggered a configuration of the o.s.s.core.userdetails.memory.InMemoryDaoImpl implementation of the UserDetailsService. As you'd anticipate, this implementation stores the users configured in the XML security configuration file in a memory-resident data store. The configuration of this service supports other attributes allowing accounts to be disabled or locked as well.

Let's visually review how the components of the DaoAuthenticationProvider interact to provide authentication support to the AuthenticationManager:


  • 大小: 37.2 KB
  • 大小: 38.6 KB
  • 大小: 42.8 KB
分享到:
评论

相关推荐

    springsecurity原理流程图.pdf

    Spring Security 是一个功能强大且高度可定制的身份验证和访问控制框架,它是安全领域中Spring生态系统的一部分。Spring Security旨在为Java应用程序提供一个全面的安全解决方案,尤其适用于企业级应用场景。它主要...

    SpringSecurity基本原理图

    对Security基本执行过程的分析和各个环节类执行的分析。

    SpringSecurity笔记,编程不良人笔记

    可能是使用Draw.io绘制的SpringSecurity架构图或流程图,帮助可视化理解SpringSecurity的工作原理。 总之,SpringSecurity为开发者提供了强大的安全工具,通过灵活的配置和丰富的扩展性,能够满足各种复杂的Web...

    springsecurity前端素材.zip

    在本“springsecurity前端素材”中,我们有两个主要的文件夹:templates和static,它们分别代表了前端展示层的不同方面。 **templates** 文件夹通常包含了应用的HTML模板文件,这些文件被用于构建用户界面。在...

    Spring security

    其实这些都不是问题,为了帮助学生理清思路把抽象的东西变的更加具体,我用Freemind 画了一幅Spring Security的一个整体概况图,从大的方向列出了配置一个Spring Security需要的一些东西,包括如何配置,配置文件中...

    基于SpringSecurity的图书借阅系统源代码

    《基于SpringSecurity的图书借阅系统源代码》是一款利用SpringSecurity框架实现的图书管理与借阅功能的应用系统。SpringSecurity是Java领域内广泛使用的安全框架,它为应用程序提供了全面的安全控制,包括认证、授权...

    SpringSecurity框架原理.png

    该图是作者在分析SpringSecurity框架源代码之后梳理出来的Spring Security框架得启动原理图,即SpringSecurity是如何获取过滤器参数配置并调用相应的过滤器的;

    Spring Security实现验证码登录功能

    知识点一:Spring Security验证码登录功能的实现原理 Spring Security的验证码登录功能是基于Java的图形验证码技术实现的。该技术生成一个随机的验证码图片,用户需要输入正确的验证码以完成登录。这样可以防止...

    springsecurity整合cas全程

    1. **开场简单介绍**:简要介绍 Spring Security 的核心组件及其工作原理。 2. **配置 CAS Filter**:Spring Security 需要配置 CAS Filter 来处理与 CASServer 的通信。主要步骤包括: - **引入 CAS Filter**:在...

    spring security 2 学习,是2 不是3

    - 通过阅读源码,我们可以深入理解Spring Security的工作原理,了解它是如何处理请求、认证和授权的,这对于定制和扩展框架非常有帮助。 8. **工具支持** - IDE插件:如Spring Tool Suite (STS) 可以提供对Spring...

    Spring Security整合Oauth2实现流程详解

    Spring Security 是一个强大的安全框架,它为Java应用程序提供了全面的安全管理解决方案。而OAuth2则是一种开放标准,用于授权第三方应用访问用户的数据。在前后端分离的架构中,OAuth2常常用于处理用户登录验证,...

    SpringBoot + SpringSecurity 短信验证码登录功能实现

    SpringBoot + SpringSecurity 短信验证码登录功能实现 本文主要介绍了 SpringBoot + SpringSecurity 短信验证码登录功能实现的详细过程,该功能可以使用户通过手机短信验证码登录系统,而不是传统的用户名密码登录...

    基于Acticiti7的Web工作流引擎,使用BPMN-JS绘制业务流程 集成SpringSecurity安全框架

    综上所述,这个项目结合了Acticiti7的工作流能力、BPMN-JS的流程建模可视化及SpringSecurity的安全保障,构建了一个功能齐全且易于维护的Web工作流管理系统。通过深入理解Acticiti7的工作原理、BPMN-JS的绘图机制...

    Spring Web Flow 2简化页面流的开发,结合Spring MVC更俊,Spirng Security 3添加安全机制

    理解Spring Web Flow 2的源码可以帮助开发者深入理解其工作原理,从而更好地设计和实现复杂的页面流程。源码中包含了各种核心组件,如FlowExecutor、StateMachine以及Action和Transition的实现。通过阅读源码,我们...

    Spring 揭秘 全面 深入了解Spring

    在事务管理方面,Spring提供了编程式和声明式两种事务管理方式,书中有详细的解释和示例,帮助读者理解何时及如何选择合适的方式。 安全是任何应用都需要考虑的问题,Spring Security提供了一套全面的安全解决方案...

    图书:Spring 安全3

    《Spring 安全3》是一本深入探讨Spring Security框架的专业图书,主要针对Java开发者和对安全领域感兴趣的IT人士。Spring Security是Spring生态系统中的一个核心组件,它为Java应用程序提供了全面的安全管理解决方案...

    JavaWeb开发之Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架

    本篇文章将详细讲解基于Spring、SpringMVC、MyBatis、SpringSecurity、EhCache和JCaptcha这六大组件构建的Web框架。 1. **Spring**: Spring作为整个框架的核心,提供了依赖注入(DI)和面向切面编程(AOP)等特性...

    学习Spring的图片截图

    Spring框架是中国乃至全球...结合图片截图,可以更直观地理解Spring的组件和工作原理,有助于快速掌握和应用Spring框架。同时,持续关注Spring的更新日志,可以确保我们的技能与时俱进,适应不断变化的软件开发环境。

    Spring技术内幕:深入解析Spring架构与设计原理(第2版)

    《Spring技术内幕:深入解析Spring架构与设计原理(第2版)》是一本专注于Spring框架的高级参考书籍,面向对Spring有深入了解需求的Java开发者。书中不仅介绍了Spring框架的基本概念和原理,更深入到Spring框架内部,...

Global site tag (gtag.js) - Google Analytics