当前位置: 首页 > news >正文

做暖暖小视频老司机网站成人短期培训能学什么

做暖暖小视频老司机网站,成人短期培训能学什么,wordpress任意文件删除漏洞,互联网挣钱新方法SpringSecurity6从入门到实战之SpringSecurity6自定义认证规则 Spring Security 中默认所有的 http 请求都需要先认证通过后,才能访问。那么, 如何指定不需要认证就可以直接访问的资源呢?比如 用户的登录页面和注册页面,都是不需要…

SpringSecurity6从入门到实战之SpringSecurity6自定义认证规则

Spring Security 中默认所有的 http 请求都需要先认证通过后,才能访问。那么, 如何指定不需要认证就可以直接访问的资源呢?比如 用户的登录页面和注册页面,都是不需要认证就必须能被直接访问的。这就需要设置自定义的URL认证规则

SpringSecurity5.x自定义认证与6.x

# 在 SpringSecurity5.x中( 了解,已被废弃 )// 自定义配置类 继承 WebSecurityConfigurerAdapter 类覆盖 configure() 方法@Configurationpublic class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeHttpRequests().mvcMatchers("/hello").permitAll().anyRequest().authenticated().and().formLogin();}}
# 在 SpringSecurity6.x 中// 自定义配置类 使用注解 @EnableWebSecurity 配置 SpringSecurity

开发示例

创建一个新的controller

/test

package com.example.controller;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HelloController {@RequestMapping("/hello")public String hello() {System.out.println("/hello");return "hello...";}@RequestMapping("/test")public String test() {System.out.println("/test");return "test...";}
}

方便与/hello对比进行测试

根据SpringSecurity6.x自定义认证规则配置

新建MyWeSecurityConfig自定义配置类

package com.example.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;@Configuration
@EnableWebSecurity
public class MyWeSecurityConfig {@Beanpublic SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {//放行hello和testhttp.authorizeHttpRequests().requestMatchers("/hello", "test").permitAll()//所有请求都需要进行认证.anyRequest().authenticated()//进行表单登录验证.and().formLogin();return http.build();}
}

测试

image.png

image.png

结论

最终可以发现我们可以自定义认证规则,让例如注册等不需要认证的请求直接放行,让其他请求进行认证操作后再进行放行
http://www.wangmingla.cn/news/114283.html

相关文章:

  • 盱眙住房和城乡建设局网站线上广告宣传方式有哪些
  • 百度收录好的网站seo专员招聘
  • 17网站一起做网店怎么拿货最火的网络销售平台
  • 怎么做网站站长微信广告投放推广平台多少费用
  • 网站建设优化服务代写
  • 百度验证网站所有权qq群推广平台
  • 陵水县建设局网站关于网络推广的方法
  • wordpress找不到分类页面网站关键词优化报价
  • 郑州东区做网站电话网站备案
  • 那些市区做网站群网站内容优化关键词布局
  • 999网站免费百度合伙人答题兼职赚钱
  • wordpress网站管理员插件关键词调词平台
  • 第一次做网站没头绪友链大全
  • 中国建造师官网查询应用关键词优化
  • 中型电商网站维护费用谷歌商店官网下载
  • 企业网站建设可行性分析表短视频搜索seo
  • 细分网站营销型网站建设论文
  • 做网站还赚钱么优化服务平台
  • 响应式网站建设的好处天津seo代理商
  • 衡阳做网站推广网站的公司
  • 网站维护的工作内容怎么做网站关键词优化
  • 做自媒体的网站百度搜索推广是什么
  • 专业杭州网站建设青岛seo计费
  • 深圳建网站多少钱一年业务推广平台
  • 极速网站建设定制网络广告有哪些形式
  • 汕头公司做网站南京做网站的公司
  • 网站在哪里建立百度开放平台登录
  • 手机版网站制作模板aso优化师主要是干嘛的
  • 个人主页网站设计论文seo案例分析方案
  • 网站建设服务领域网络推广计划书