我最近看到Mike Wienser的SpringOne2GX谈论了Application Security Pitfalls 。 如果您在Servlet容器上使用Spring的堆栈,这将非常有用,值得一看。

它使我想起了我曾经面临的一个严重的Spring Security Misconfiguration。 在Spring的指导项目Securing a Web Application上进行解释。 该项目使用Spring Boot,Spring Integration和Spring MVC。

项目使用以下视图:

@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {@Overridepublic void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/home").setViewName("home");registry.addViewController("/").setViewName("home");registry.addViewController("/hello").setViewName("hello");registry.addViewController("/login").setViewName("login");}}

应公开访问“ / home”,“ /”和“ / login” URL,而“ / hello”仅应由经过身份验证的用户访问。 这是《指南》中的原始Spring Security配置:

@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers("/", "/home").permitAll().anyRequest().authenticated();http.formLogin().loginPage("/login").permitAll().and().logout().permitAll();}@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");}
}

就像所有Spring指南一样,很好并且具有解释性。 第一种“配置”方法将“ /”和“家庭”注册为公共,并指定其他所有内容均应进行身份验证。 它还注册登录URL。 第二种“配置”方法指定角色“ USER”的身份验证方法。 当然,您不想在生产中像这样使用它!

现在,我将略微修改此代码。

@Overrideprotected void configure(HttpSecurity http) throws Exception {//!!! Don't use this example !!!http.authorizeRequests()              .antMatchers("/hello").hasRole("USER");//... same as above ...}

一切都是公共和私有端点,必须列出。 您可以看到我修改后的代码具有与原始代码相同的行为。 实际上,它节省了一行代码。

但是,这有一个严重的问题。 如果我需要引入新的专用端点怎么办? 假设我不知道它需要在Spring Security配置中注册的事实。 我的新端点将是公共的。 这样的配置错误确实很难发现,并且可能导致URL暴露。

因此得出的结论是: 默认情况下,始终对所有端点进行身份验证。

翻译自: https://www.javacodegeeks.com/2014/06/spring-security-misconfiguration.html

Spring Security配置错误相关推荐

  1. Spring Boot——Spring Session Redis整合Spring Security时错误【RedisConnectionFactory is required】解决方案

    问题描述 异常栈栈底 Caused by: java.lang.IllegalStateException: RedisConnectionFactory is requiredat org.spri ...

  2. 从零开始java安全权限框架篇(一):spring security配置登录登出的配置

    目录 一:安全权限框架的选取 二:功能 三:登录登出 四:代码注释 1.将登陆交由Spring security完成 2.前台明文密码加密,与数据库比对 3.关键配置 4.自定义用户异常 5.ajax ...

  3. Spring Security 配置 Remember Me

    1.概述 本教程将展示如何使用 Spring Security 在 Web 应用程序中启用和配置 Remember Me.之前已经讨论过设置安全和简单表单登录的 MVC 应用程序. 该机制将能够跨多个 ...

  4. Spring Security配置全局 AuthenticationManager

    Topical Guide | Spring Security Architecture 默认的全局 AuthenticationManager @Configuration public class ...

  5. Spring Boot——配置Spring Security配置类DEMO

    源代码 package club.zstuca.myzstu.filter;import club.zstuca.myzstu.entity.Resource; import club.zstuca. ...

  6. Spring Security 配置白名单访问后,仍然报错403

    按照框架上配置, .antMatchers("/test/abc").anonymous() 增加 自己路径白名单的配置,结果访问仍然出现403 forbidden 原因在于 没有 ...

  7. spring security配置详解

    1.<intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY"/> ...

  8. 史上最简单的Spring Security教程(二十八):CA登录与默认用户名密码登录共存详细实现及配置

    ​在前面的文章中,我们自定义了一些CA登录相关的类,如 CertificateAuthorityAuthenticationToken.CertificateAuthorityAuthenticati ...

  9. 【Spring Boot】Spring Boot 2.x + Spring Security OAuth2 2.3.3 出现 bad client credentials 错误的踩坑记录

    环境: spring boot 2.0.4.RELEASE spring security oauth 2.3.3.RELEASE OAuth2的配置 @Configuration @EnableAu ...

最新文章

  1. 如何优雅地退出python程序
  2. 使用快速傅里叶变换计算大整数乘法-代码
  3. JS判断是否选中的是表格内当前选中的那一行
  4. db2 mysql sql server_下文给大家介绍mysql数据库介绍,具体详情如下所示:MySQL数据库:Oracle、DB2、SQL Server、MySQL、access、mang...
  5. mysql数据库时间突然是12小时制_为什么存入mysql数据库中的timestamp,晚了13或14个小时...
  6. 【机器学习-西瓜书】三、逻辑回归(LR);线性判别分析(LDA)
  7. 2018 OpenInfra Days China 大咖来袭——开源,我们是认真的
  8. py2exe打包python_Python打包-py2exe使用
  9. numpy.zeros(np.zeros)
  10. 1.2 Illustrator多文档的几种排列方式
  11. 宽带连接自动断开是怎么回事?
  12. 给机器人罗宾写一封英语回信_人教版5年级英语unit1知识
  13. 产品读书《极简工作法则》
  14. 专科计算机专业软件工程,软件工程专业专科学校都有哪些?
  15. 《菊与刀》读后感作文5000字
  16. C++ #ifdef 和 #endif
  17. 【Javaweb】【答卷】萌狼蓝天大二上学期期末Javaweb考试复习卷(一)
  18. (三)爬取新房销售信息——位置坐标转换+地图标点可视化篇
  19. 防刷新网站访问量计数器
  20. ls-dyna基础教程

热门文章

  1. linux中usb设备名,Linux 中识别 USB 设备名字的 4 种方法
  2. HDU2049(错列排序)
  3. snmp与java集成_轻松地与Java完全集成
  4. 多个定时器相互干扰的问题_相互问题
  5. jsf教程_JSF范围教程– JSF / CDI会话范围
  6. javafx 项目_JavaFX,Jigsaw项目和JEP 253
  7. JMetro版本11.5.10和8.5.10发布
  8. file.getpath_Java中File的getPath(),getCanonicalPath()和getAbsolutePath()之间的区别...
  9. 使用Angular,Ionic 4和Spring Boot构建移动应用
  10. mockito模拟依赖注入_使用Mockito模拟自动装配的字段