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

做视频的素材什么网站好网站推广方案的构成

做视频的素材什么网站好,网站推广方案的构成,张家港百度网站制作,南京好的网站设计一、前言 Spring Security 和 Apache Shiro 都是安全框架,为Java应用程序提供身份认证和授权。 二者区别 Spring Security:重量级安全框架Apache Shiro:轻量级安全框架 关于shiro的权限认证与授权可参考小编的另外一篇文章 : …

一、前言

Spring SecurityApache Shiro 都是安全框架,为Java应用程序提供身份认证和授权。

二者区别
  1. Spring Security:量级安全框架
  2. Apache Shiro:量级安全框架

关于shiro的权限认证与授权可参考小编的另外一篇文章 : SpringBoot集成Shiro 实现动态加载权限

https://blog.csdn.net/qq_38225558/article/details/101616759

二、SpringBoot集成Spring Security入门体验

基本环境 : springboot 2.1.8
1、引入Spring Security依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>
2、新建一个controller测试访问
@RestController
public class IndexController {@GetMapping("/index")public String index() {return "Hello World ~";}
}
3、运行项目访问 http://127.0.0.1:8080/index

温馨小提示:在不进行任何配置的情况下,Spring Security 给出的默认用户名为user 密码则是项目在启动运行时随机生成的一串字符串,会打印在控制台,如下图:在这里插入图片描述当我们访问index首页的时候,系统会默认跳转到login页面进行登录认证

在这里插入图片描述认证成功之后才会跳转到我们的index页面在这里插入图片描述

三、Spring Security用户密码配置

除了上面Spring Security在不进行任何配置下默认给出的用户user 密码随项目启动生成随机字符串,我们还可以通过以下方式配置

1、springboot配置文件中配置
spring:security:user:name: admin  # 用户名password: 123456  # 密码
2、java代码在内存中配置

新建Security 核心配置类继承WebSecurityConfigurerAdapter

@Configuration
@EnableWebSecurity // 启用Spring Security的Web安全支持
public class SecurityConfig extends WebSecurityConfigurerAdapter {/*** 将用户设置在内存中* @param auth* @throws Exception*/@Autowiredpublic void config(AuthenticationManagerBuilder auth) throws Exception {// 在内存中配置用户,配置多个用户调用`and()`方法auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()) // 指定加密方式.withUser("admin").password(passwordEncoder().encode("123456")).roles("ADMIN").and().withUser("test").password(passwordEncoder().encode("123456")).roles("USER");}@Beanpublic PasswordEncoder passwordEncoder() {// BCryptPasswordEncoder:Spring Security 提供的加密工具,可快速实现加密加盐return new BCryptPasswordEncoder();}}
3、从数据库中获取用户账号、密码信息

这种方式也就是我们项目中通常使用的方式,这个留到后面的文章再说

四、Spring Security 登录处理 与 忽略拦截

相关代码都有注释相信很容易理解

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {/*** 登录处理* @param http* @throws Exception*/@Overrideprotected void configure(HttpSecurity http) throws Exception {// 开启登录配置http.authorizeRequests()// 标识访问 `/index` 这个接口,需要具备`ADMIN`角色.antMatchers("/index").hasRole("ADMIN")// 允许匿名的url - 可理解为放行接口 - 多个接口使用,分割.antMatchers("/", "/home").permitAll()// 其余所有请求都需要认证.anyRequest().authenticated().and()// 设置登录认证页面.formLogin().loginPage("/login")// 登录成功后的处理接口 - 方式①.loginProcessingUrl("/home")// 自定义登陆用户名和密码属性名,默认为 username和password.usernameParameter("username").passwordParameter("password")// 登录成功后的处理器  - 方式②
//                .successHandler((req, resp, authentication) -> {
//                    resp.setContentType("application/json;charset=utf-8");
//                    PrintWriter out = resp.getWriter();
//                    out.write("登录成功...");
//                    out.flush();
//                })// 配置登录失败的回调.failureHandler((req, resp, exception) -> {resp.setContentType("application/json;charset=utf-8");PrintWriter out = resp.getWriter();out.write("登录失败...");out.flush();}).permitAll()//和表单登录相关的接口统统都直接通过.and().logout().logoutUrl("/logout")// 配置注销成功的回调.logoutSuccessHandler((req, resp, authentication) -> {resp.setContentType("application/json;charset=utf-8");PrintWriter out = resp.getWriter();out.write("注销成功...");out.flush();}).permitAll().and().httpBasic().and()// 关闭CSRF跨域.csrf().disable();}/*** 忽略拦截* @param web* @throws Exception*/@Overridepublic void configure(WebSecurity web) throws Exception {// 设置拦截忽略url - 会直接过滤该url - 将不会经过Spring Security过滤器链web.ignoring().antMatchers("/getUserInfo");// 设置拦截忽略文件夹,可以对静态资源放行web.ignoring().antMatchers("/css/**", "/js/**");}}

五、总结

  1. 项目引入Spring Security依赖
  2. 自定义Security核心配置类继承WebSecurityConfigurerAdapter
  3. 账号密码配置
  4. 登录处理
  5. 忽略拦截
案例demo源码

gitee.com/zhengqingya…

http://www.yayakq.cn/news/310246/

相关文章:

  • 建设银行网站打不开别的网站可以用吗中小企业网站建设维护内容
  • 成都网站开发费用抖音代运营套餐价格表
  • 无锡优化网站公司一手项目对接app平台
  • 网页和网站设计h5 和手机网站
  • 手机论坛网站源码做网站的开发心得
  • 网站建设v南开区网站建设公司
  • 精诚时代 网站谁做的php网站开发前景
  • wordpress建站事项跨境电商网络营销是什么
  • 网站做代理还可以刷水吗有哪个网站可以做兼职
  • 的建站公司域名解析网站
  • 绍兴 网站建设 电话学网页制作有什么用
  • 电子商务网站与普通网站的区别多语言网站怎么做
  • 做网站客源东莞网站建设规范
  • 织梦网站logo微信腾讯会议
  • 淘宝客必须做网站吗电商网站建设的目的跟意义
  • asp.net个人网站空间基于响应式设计的网站建设
  • 一流的镇江网站优化公司网站建设注意点
  • 饶平网站建设网站访问速度慢的原因
  • 没有域名 有公网ip 建网站可以简洁网站首页模板
  • 南京环力建设有限公司网站自己做平台网站
  • 邢台中北世纪城网站兼职代理网页浏览
  • 网站域名申请步骤为企业做出贡献的句子
  • 星座 网站 建设网站建设项目管理论文
  • 文山州建设局网站电商网站商品排序分类怎么做
  • 网站搭建服务器需要多少钱百度怎么推广广告
  • 做网站一个月赚多少建站平台功能结构图
  • 四川大学规划建设处官方网站网站开发使用软件环境
  • 做网站内容图片多大微商城app官方下载
  • 大庆市网站建设公司wordpress 换空间 换域名
  • 青岛网站制作需要多少钱电商网站的活动怎么做