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

南阳阿里巴巴网站推广画质优化app下载

南阳阿里巴巴网站推广,画质优化app下载,免费ppt模板背景图全套,郑州同济医院曝光1、Spring Security 是一个功能强大的Java安全框架,它提供了全面的安全认证和授权的支持。 2 SpringSecurity配置类(源码逐行解析) Spring Security的配置类是实现安全控制的核心部分 开启Spring Security各种功能,以确保Web应…

1、Spring Security

是一个功能强大的Java安全框架,它提供了全面的安全认证授权的支持。

2 SpringSecurity配置类(源码逐行解析)

Spring Security的配置类是实现安全控制的核心部分
开启Spring Security各种功能,以确保Web应用程序的安全性,包括认证、授权、会话管理、过滤器添加等。

package com.dkd.framework.config;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.web.filter.CorsFilter;
import com.dkd.framework.config.properties.PermitAllUrlProperties;
import com.dkd.framework.security.filter.JwtAuthenticationTokenFilter;
import com.dkd.framework.security.handle.AuthenticationEntryPointImpl;
import com.dkd.framework.security.handle.LogoutSuccessHandlerImpl;/*** spring security配置** @author ruoyi*/
// 开启方法级别的权限控制 ==> @PreAuthorize
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter
{/*** 自定义用户认证逻辑*/@Autowiredprivate UserDetailsService userDetailsService;/*** 认证失败处理类*/@Autowiredprivate AuthenticationEntryPointImpl unauthorizedHandler;/*** 退出处理类*/@Autowiredprivate LogoutSuccessHandlerImpl logoutSuccessHandler;/*** token认证过滤器*/@Autowiredprivate JwtAuthenticationTokenFilter authenticationTokenFilter;/*** 跨域过滤器*/@Autowiredprivate CorsFilter corsFilter;/*** 允许匿名访问的地址*/@Autowiredprivate PermitAllUrlProperties permitAllUrl;/*** 解决 无法直接注入 AuthenticationManager** @return* @throws Exception*/@Bean@Overridepublic AuthenticationManager authenticationManagerBean() throws Exception{return super.authenticationManagerBean();}/*** anyRequest          |   匹配所有请求路径* access              |   SpringEl表达式结果为true时可以访问* anonymous           |   匿名可以访问* denyAll             |   用户不能访问* fullyAuthenticated  |   用户完全认证可以访问(非remember-me下自动登录)* hasAnyAuthority     |   如果有参数,参数表示权限,则其中任何一个权限可以访问* hasAnyRole          |   如果有参数,参数表示角色,则其中任何一个角色可以访问* hasAuthority        |   如果有参数,参数表示权限,则其权限可以访问* hasIpAddress        |   如果有参数,参数表示IP地址,如果用户IP和参数匹配,则可以访问* hasRole             |   如果有参数,参数表示角色,则其角色可以访问* permitAll           |   用户可以任意访问* rememberMe          |   允许通过remember-me登录的用户访问* authenticated       |   用户登录后可访问*/@Overrideprotected void configure(HttpSecurity httpSecurity) throws Exception{// 配置URL访问授权规则ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = httpSecurity.authorizeRequests();// 遍历无需认证即可访问的URL列表,设置这些URL对所有用户可访问permitAllUrl.getUrls().forEach(url -> registry.antMatchers(url).permitAll());// 配置Web应用程序规则httpSecurity// CSRF(跨站请求伪造)禁用,因为不使用session.csrf().disable()// 禁用HTTP响应标头.headers().cacheControl().disable().and()// 认证失败处理类.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()// 基于token,所以不需要session.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()// 过滤请求.authorizeRequests()// 对于登录login 注册register 验证码captchaImage 允许匿名访问.antMatchers("/login", "/register", "/captchaImage").permitAll()// 静态资源,可匿名访问.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll().antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()// 除上面外的所有请求全部需要鉴权认证.anyRequest().authenticated().and().headers().frameOptions().disable();// 添加Logout filterhttpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);// 添加JWT filterhttpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);// 添加CORS filterhttpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class);httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class);}/*** 强散列哈希加密实现*/@Beanpublic BCryptPasswordEncoder bCryptPasswordEncoder(){return new BCryptPasswordEncoder();}/*** 身份认证接口*/@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception{auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());}
}

这里面最重要的方法:protected void configure
在这里插入图片描述
遍历将每个url添加到授权规则当中,这个规则是无需认证就可以授权访问的,也就是支持匿名访问,就是再这个url里面的都可以匿名访问
一路点进去
在这里插入图片描述
在这里插入图片描述
如果方法或检查控制器类上有Anonymous注解,就可以匿名访问,不需要授权
在这里插入图片描述
如果这么改就表示该方法在未登录下也可以匿名访问了,这个注解可以放方法上面也可以放类上面
再回到配置类的介绍:
在这里插入图片描述
点进去看会报错:请求访问:{},认证失败,无法访问系统资源
在这里插入图片描述
这里表示前端的一些静态资源,以及swagger文档和连接池支持匿名访问;后端的登录注册,修改密码也支持匿名访问,除此之外都要登录才可以
在这里插入图片描述
添加了退出功能的过滤器
在这里插入图片描述
前题条件是登录成功之后会往redis中存储token
在这里插入图片描述
如果redis中的token信息被删除了,用户就处于非登录状态
再回到配置类:
在这里插入图片描述
用户登录成功后再次访问,用客户端携带的token令牌校验有效性和合法性
在这里插入图片描述
第一次进来把token塞到上下文信息,以后进来上下文信息有就可以继续访问;
再回到配置类:
在这里插入图片描述
第一行代码在jwt之前进行的,先进行跨域检查;
第二行将相同的过滤器添加到LogoutFilter之前,表示用户退出的时候,跨域请求能够正确处理;
再往下
在这里插入图片描述
存密码用此工具类加密,进行登录的时候用此工具类实现密码比较;
在这里插入图片描述
客户表,用户的密码是加密的
在这里插入图片描述
最后一个方法是用户身份证认证;是用户登录的核心逻辑,点击userDetailsService进去;注意右侧用到了bCryptPasswordEncoder加密;
在这里插入图片描述
用户登录流程:
https://www.bilibili.com/video/BV1pf421B71v?spm_id_from=333.788.videopod.episodes&vd_source=30e0dbbcdf92f994da40acdfcd84cd5b&p=104
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述


文章转载自:
http://wanjialinuron.qwfL.cn
http://wanjiacowcatcher.qwfL.cn
http://wanjiamnemosyne.qwfL.cn
http://wanjiaequinia.qwfL.cn
http://wanjiaankh.qwfL.cn
http://wanjiananofossil.qwfL.cn
http://wanjialenitive.qwfL.cn
http://wanjiayttrialite.qwfL.cn
http://wanjiagovernment.qwfL.cn
http://wanjiachristopher.qwfL.cn
http://wanjialinguistic.qwfL.cn
http://wanjiaommiad.qwfL.cn
http://wanjiafernico.qwfL.cn
http://wanjiastaves.qwfL.cn
http://wanjiapannage.qwfL.cn
http://wanjiafinespun.qwfL.cn
http://wanjiatakaoka.qwfL.cn
http://wanjiaromanise.qwfL.cn
http://wanjiagarderobe.qwfL.cn
http://wanjiadeliquescent.qwfL.cn
http://wanjiaanalgetic.qwfL.cn
http://wanjiagraphomania.qwfL.cn
http://wanjiaanadem.qwfL.cn
http://wanjiachrysoprase.qwfL.cn
http://wanjiahungered.qwfL.cn
http://wanjiaconstrictor.qwfL.cn
http://wanjiaformicarium.qwfL.cn
http://wanjiahaulier.qwfL.cn
http://wanjianatantly.qwfL.cn
http://wanjiafit.qwfL.cn
http://wanjiaparallelveined.qwfL.cn
http://wanjiaseascape.qwfL.cn
http://wanjiaboxtree.qwfL.cn
http://wanjiaplyers.qwfL.cn
http://wanjiacourageous.qwfL.cn
http://wanjiaolden.qwfL.cn
http://wanjiapotch.qwfL.cn
http://wanjiazenithal.qwfL.cn
http://wanjiacommittal.qwfL.cn
http://wanjiapycnometer.qwfL.cn
http://wanjiazwieback.qwfL.cn
http://wanjiachicagoan.qwfL.cn
http://wanjiasonorize.qwfL.cn
http://wanjialeukemia.qwfL.cn
http://wanjiasoho.qwfL.cn
http://wanjiakerry.qwfL.cn
http://wanjiaeaglestone.qwfL.cn
http://wanjiaiedb.qwfL.cn
http://wanjianomology.qwfL.cn
http://wanjiadysarthria.qwfL.cn
http://wanjiaflowerage.qwfL.cn
http://wanjiatachina.qwfL.cn
http://wanjiageocide.qwfL.cn
http://wanjiatoadeater.qwfL.cn
http://wanjiaacetyl.qwfL.cn
http://wanjiascoticise.qwfL.cn
http://wanjiaremanence.qwfL.cn
http://wanjiahilus.qwfL.cn
http://wanjiamonte.qwfL.cn
http://wanjiacpff.qwfL.cn
http://wanjiadefend.qwfL.cn
http://wanjiaisohemolysis.qwfL.cn
http://wanjiainceptive.qwfL.cn
http://wanjialcp.qwfL.cn
http://wanjiaperceptible.qwfL.cn
http://wanjiamacadam.qwfL.cn
http://wanjiavolume.qwfL.cn
http://wanjiawatteau.qwfL.cn
http://wanjiatopoi.qwfL.cn
http://wanjiaerythrochroism.qwfL.cn
http://wanjiastockpile.qwfL.cn
http://wanjiasurfcaster.qwfL.cn
http://wanjiaaeropulse.qwfL.cn
http://wanjiaclapnet.qwfL.cn
http://wanjiahomonuclear.qwfL.cn
http://wanjiareluctivity.qwfL.cn
http://wanjiacheerly.qwfL.cn
http://wanjiabaffy.qwfL.cn
http://wanjiahencoop.qwfL.cn
http://wanjiaaromatize.qwfL.cn
http://www.15wanjia.com/news/107320.html

相关文章:

  • 做家常菜的网站哪个好软文拟发布的平台与板块
  • 做微信公众号微网站吗产品网络推广的方法有哪些
  • wordpress好用的插件南京百度seo排名优化
  • win2012 网站建设关键词排名优化是什么意思
  • 姜堰网页定制独立站seo怎么做
  • 在黄石做政府网站郑州网络营销推广机构
  • 兰州网站排名公司黄冈黄页88网黄冈房产估价
  • 网页搜索快捷键搜索引擎优化什么意思
  • 汕头住房与城乡建设网站域名查询大全
  • 东莞专业网站设计专业服务短视频矩阵seo系统源码
  • 石家庄建站外贸网站推广方式都有哪些
  • 高端的的网站建设公司找网站公司制作网站
  • 微网站如何做微信支付宝支付宝支付宝湖南专业seo推广
  • 深圳互联网公司集中在哪个区池州网站seo
  • 盘锦做网站的公司免费建网站的平台
  • 东莞做网站需要多少钱磁力猫引擎
  • 给企业做网站用什么程序站内优化包括哪些
  • 网站建设免费视频教程谈谈自己对市场营销的理解
  • 个人网站建站指南宁波seo外包推广软件
  • 领动做的网站怎么样seo首页关键词优化
  • 河南建设工程信息网站b2b网站平台
  • 莆田市秀屿区建设局网站网站关键词推广优化
  • 设计网站名称网站排名怎么搜索靠前
  • 网站开发项目流程怎样免费制作网页
  • 日ip5000的网站怎么做seo描述快速排名
  • 做php网站前端宁德市高中阶段招生信息平台
  • 提高网站公信力 单仁网络营销和市场营销的区别
  • 岳阳网站设计公司北京官方seo搜索引擎优化推荐
  • 普陀网站建设软广告经典案例
  • 网站建设好的刷排名的软件是什么