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

个人网站怎么做推广seo软件优化工具软件

个人网站怎么做推广,seo软件优化工具软件,郑州怎么做外贸公司网站,艺术字体在线生成器可复制项目代码 gson/spring-security-demo 简介 Spring Security 是 Spring 家族中的一个安全管理框架。相比与另外一个安全框架Shiro,它提供了更丰富的功能,社区资源也比Shiro丰富。 一般来说中大型的项目都是使用SpringSecurity来做安全框架。小项目有Shiro的比较多,因为相比…

项目代码

gson/spring-security-demo


简介

Spring Security 是 Spring 家族中的一个安全管理框架。相比与另外一个安全框架Shiro,它提供了更丰富的功能,社区资源也比Shiro丰富。

一般来说中大型的项目都是使用SpringSecurity来做安全框架。小项目有Shiro的比较多,因为相比与SpringSecurity,Shiro的上手更加的简单。

一般Web应用的需要进行认证授权

认证:验证当前访问系统的是不是本系统的用户,并且要确认具体是哪个用户

授权:经过认证后判断当前用户是否有权限进行某个操作

而认证和授权也是SpringSecurity作为安全框架的核心功能。


搭建基础项目

1、我们先搭建一个简单的SpringBoot工程,并添加相关依赖

 <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.0</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency></dependencies>

2、创建启动类

@SpringBootApplication
public class SecurityApplication {public static void main(String[] args) {SpringApplication.run(SecurityApplication.class,args);}
}

3、创建Controller

@RestController
@RequestMapping("/book")
public class BookController {@GetMapping("/list")public String list() {return "book-list";}}

4、创建配置文件application.yml

server:port: 8000

然后启动项目,输入地址进行访问测试


引入SpringSecurity

在SpringBoot项目中使用SpringSecurity我们只需要引入依赖即可实现入门案例。

       <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency>

引入依赖后我们在尝试去访问之前的接口就会自动跳转到一个SpringSecurity的默认登陆页面,默认用户名是user,密码会输出在控制台。

必须登陆之后才能对接口进行访问。


认证

登陆校验流程

SpringSecurity完整流程

SpringSecurity的原理其实就是一个过滤器链,内部包含了提供各种功能的过滤器。这里我们可以看看入门案例中的过滤器。

图中只展示了核心过滤器,其它的非核心过滤器并没有在图中展示。

UsernamePasswordAuthenticationFilter:负责处理我们在登陆页面填写了用户名密码后的登陆请求。入门案例的认证工作主要有它负责。

ExceptionTranslationFilter:处理过滤器链中抛出的任何AccessDeniedException和AuthenticationException 。

FilterSecurityInterceptor:负责权限校验的过滤器。

我们可以通过Debug查看当前系统中SpringSecurity过滤器链中有哪些过滤器及它们的顺序。

认证流程详解

概念速查:

  • Authentication接口: 它的实现类,表示当前访问系统的用户,封装了用户相关信息。
  • AuthenticationManager接口:定义了认证Authentication的方法
  • UserDetailsService接口:加载用户特定数据的核心接口。里面定义了一个根据用户名查询用户信息的方法。
  • UserDetails接口:提供核心用户信息。通过UserDetailsService根据用户名获取处理的用户信息要封装成UserDetails对象返回。然后将这些信息封装到Authentication对象中。

登录过程分析

登录

①自定义登录接口

  • 调用ProviderManager的方法进行认证 如果认证通过生成jwt,
  • 把用户信息存入redis中

②自定义UserDetailsService

  • 在这个实现类中去查询数据库

校验:

①定义Jwt认证过滤器

  • 获取token
  • 解析token获取其中的userid
  • 从redis中获取用户信息
  • 存入SecurityContextHolder

代码准备工作

1、添加依赖

        <!--redis依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><!--fastjson依赖--><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.33</version></dependency><!--jwt依赖--><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt</artifactId><version>0.9.0</version></dependency><!-- 引入MybatisPuls和mysql驱动的依赖--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.3</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><!-- 单元测试的依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency>

2、添加Redis相关配置

/*** Redis使用FastJson序列化** @author sg*/
public class FastJsonRedisSerializer<T> implements RedisSerializer<T>
{public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");private Class<T> clazz;static{ParserConfig.getGlobalInstance().setAutoTypeSupport(true);}public FastJsonRedisSerializer(Class<T> clazz){super();this.clazz = clazz;}@Overridepublic byte[] serialize(T t) throws SerializationException{if (t == null){return new byte[0];}return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);}@Overridepublic T deserialize(byte[] bytes) throws SerializationException{if (bytes == null || bytes.length <= 0){return null;}String str
http://www.tj-hxxt.cn/news/80500.html

相关文章:

  • 漳州北京网站建设公司哪家好王通seo赚钱培训
  • 网页游戏单机游戏搜索引擎优化seo是什么
  • 网站设计O2O平台优化seo排名赚挂机赚钱软件下载
  • 网站后缀有什么区别为什么不能去外包公司
  • asp.net网站开发pdf网站统计哪个好用
  • 网站建设中模版常用的网络推广方法有
  • 外贸网站建设哪家有名网站点击量 哪里查询
  • 赤峰做网站哪家好关键词优化公司排名
  • 怎么做网站里插入背景音乐seo广告
  • 阜阳专业网站建设搜索引擎网站排名优化方案
  • 制作视频软件哪个好seo服务如何收费
  • wordpress 文字排版西安排名seo公司
  • 用php做网站用什么软件百度指数官网查询入口
  • 深圳做网站 汉狮网络淘宝代运营
  • 一级a做爰片免费观网站看无码短视频关键词seo优化
  • 企业做网站分一般为哪几种类型淘宝关键词排名优化技巧
  • 大连网站推广排名seo课程
  • 在网上找做设计是什么网站电商运营
  • 北京好的设计公司上海seo服务外包公司
  • 广州网站维护十大最靠谱it培训机构
  • 大连网站建设特色百度链接提交入口
  • 金融网站开发方案用网站模板建站
  • 中国站长网站域名交易平台
  • 定制网站建设服务外贸海外推广
  • 天津平台网站建设报价外包公司为什么没人去
  • 河北专业网站建设公司推荐怎么做百度网页
  • 平邑的网站都是谁做的廊坊关键词排名优化
  • 婚庆公司怎么开店个人网站seo
  • wordpress 文章关联seo 360
  • 网站制作评价标准常州百度推广代理