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

无锡专业网站建设免费的室内设计网站

无锡专业网站建设,免费的室内设计网站,seo站长工具平台,厦门市建设管理协会网站首页1、Spring Security 是一个功能强大的Java安全框架#xff0c;它提供了全面的安全认证和授权的支持。 2 SpringSecurity配置类#xff08;源码逐行解析#xff09; Spring Security的配置类是实现安全控制的核心部分 开启Spring Security各种功能#xff0c;以确保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*/BeanOverridepublic 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访问授权规则ExpressionUrlAuthorizationConfigurerHttpSecurity.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_from333.788.videopod.episodesvd_source30e0dbbcdf92f994da40acdfcd84cd5bp104
http://www.w-s-a.com/news/250980/

相关文章:

  • 门户网站简介做网站一天能接多少单
  • 论坛类网站建设遵义网站制作外包
  • vps服务器购买网站小视频做网站怎么赚钱
  • 网站用图片wordpress同步发布
  • 织梦图片自适应网站源码网页美工的设计要点
  • 渝快办官方网站wordpress产品图片怎么改
  • 高端网站特色深圳建网站哪
  • 宝塔搭建网站软文小故事200字
  • 公司网站设计免费虚拟主机网站源码
  • 怎样做好网站用户体验申请网站空间
  • 网站建设优化公司招聘福州网站建设思企
  • 设计网站会员wordpress rss聚合
  • 网站建设过程中的收获html5官方网站开发流程
  • 网站建设-信科网络h5美食制作网站模板下载
  • 聊城九洲建设有限公司网站师大暨大网站建设
  • 烟台网站建设学校潍坊市建设监理协会网站
  • 大良营销网站建设资讯建设厅网站总经济师是干什么的
  • 网站优化推广软件网站制作公司dedecms
  • 在哪一个网站做社保申报百度小程序开发平台
  • 东莞网站建设_东莞网页设计网站色调代号
  • 濮阳住房和城乡建设部网站给别人做ppt的网站
  • 电子商务网站建设规划心得广告投放媒体
  • 淘宝店铺购买价格宝应百度seo
  • 同一虚拟主机 2个网站如果网站设计时
  • 网站维护的协议做网站 需要 域名 空间
  • 高安建站公司济宁哪里做网站最便宜
  • 南宁建站免费模板简单的html网页设计
  • 吉林省建设 安全 网站沐风seo
  • 自己做捕鱼网站能不能挣钱软件开发公司需要什么硬件设备
  • 大连设计网站公司3小说网站开发