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

400元做网站送网推西安seo网站推广优化

400元做网站送网推,西安seo网站推广优化,公司网站外包,wordpress建站后最近学习若依框架,里面的权限注解涉及到了SpEL表达式 PreAuthorize("ss.hasPermi(system:user:list)"),若依项目中用的是自己写的方法进行权限处理, 也可以只用security 来实现权限逻辑代码,下面写如何用security 实现。…

最近学习若依框架,里面的权限注解涉及到了SpEL表达式 @PreAuthorize("@ss.hasPermi('system:user:list')"),若依项目中用的是自己写的方法进行权限处理, 也可以只用security 来实现权限逻辑代码,下面写如何用security 实现。

security中  @PreAuthorize("hasPermission(Object target, Object permission)")  的hasPermission方法,是通过PermissionEvaluator实现,默认继承类是DenyAllPermissionEvaluator,所有方法返回false,所以注解后的结果只有拒绝权限;所以继承PermissionEvaluator重写hasPermission即可。

逻辑如下:

1、securityConfig文件上加入注解@EnableMethodSecurity,且引入自定义评估器:CustomPermissionEvaluator

2、编写CustomPermissionEvaluator文件

:security 6.2.1 中 EnableGlobalMethodSecurity 已弃用,改使用 EnableMethodSecurity 且prePostEnabled为ture,只需添加注解@EnableMethodSecurity 即可

package com.example.securityDemo.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;/*** @description: security配置类* @author: mml* @create: 2024/01/26*/
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {// 引入自定义评估器@Beanstatic MethodSecurityExpressionHandler methodSecurityExpressionHandler(CustomPermissionEvaluator permissionEvaluator) {DefaultMethodSecurityExpressionHandler handler = new DefaultMethodSecurityExpressionHandler();handler.setPermissionEvaluator(permissionEvaluator);return handler;}@BeanUserDetailsService userDetailsService(){UserDetails user = User.withDefaultPasswordEncoder().username("mml").password("123").roles("USER").authorities("system:user:update","system:user:list").build();return new InMemoryUserDetailsManager(user);}/*** 是Spring Security 过滤器链,Spring Security 中的所有功能都是通过这个链来提供的* @date 2024/1/26*/@BeanSecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {// 拦截所有请求,但是不经过任何过滤器
//        return new DefaultSecurityFilterChain(new AntPathRequestMatcher("/**"));httpSecurity.authorizeHttpRequests(p -> p.anyRequest().authenticated()).csrf(c -> c.disable()).formLogin((form) -> form.loginPage("/login").permitAll());return httpSecurity.build();}}

自定义评估器代码

import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;import java.io.Serializable;
import java.util.Collection;/*** @description: 自定义权限评估器* @author: mml* @create: 2024/02/17*/
@Component
public class CustomPermissionEvaluator implements PermissionEvaluator {AntPathMatcher antPathMatcher = new AntPathMatcher();@Overridepublic boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {// 获取当前用户的角色Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();for (GrantedAuthority authority : authorities) {// 权限判断if (antPathMatcher.match(authority.getAuthority(), (String) permission)){// 说明有权限return true;}}return false;}@Overridepublic boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) {return false;}
}

接口层:

@RestController
public class UserController {@RequestMapping("/list")@PreAuthorize("hasPermission('/list','system:user:list')")public String list() {return "get list ";}@RequestMapping("/add")@PreAuthorize("hasPermission('/add','system:user:add')")public String add() {return "post add ";}
}

可以使用postman测试

测试结果如下:

list-有权限

add 方法-没有权限

security参考链接:方法安全 :: Spring Security


文章转载自:
http://dinncoannoying.ydfr.cn
http://dinncosteer.ydfr.cn
http://dinncotribology.ydfr.cn
http://dinncopiggery.ydfr.cn
http://dinncoagminate.ydfr.cn
http://dinncomethodism.ydfr.cn
http://dinncopereonite.ydfr.cn
http://dinncobrimstone.ydfr.cn
http://dinncohurdling.ydfr.cn
http://dinncobagwash.ydfr.cn
http://dinncounjustifiable.ydfr.cn
http://dinncogarret.ydfr.cn
http://dinncotops.ydfr.cn
http://dinncocupidity.ydfr.cn
http://dinncotestosterone.ydfr.cn
http://dinncoamyl.ydfr.cn
http://dinncoslickness.ydfr.cn
http://dinncoaaui.ydfr.cn
http://dinncopantomimic.ydfr.cn
http://dinncoparkland.ydfr.cn
http://dinncomoksha.ydfr.cn
http://dinncoyucca.ydfr.cn
http://dinncoriflery.ydfr.cn
http://dinncomechanism.ydfr.cn
http://dinncoathwartships.ydfr.cn
http://dinncobrown.ydfr.cn
http://dinncomastoid.ydfr.cn
http://dinncounmodish.ydfr.cn
http://dinncotailwagging.ydfr.cn
http://dinncobooky.ydfr.cn
http://dinncoenergumen.ydfr.cn
http://dinncojiujitsu.ydfr.cn
http://dinncoerr.ydfr.cn
http://dinncounworthy.ydfr.cn
http://dinncocounterplead.ydfr.cn
http://dinncohuckleberry.ydfr.cn
http://dinncoosteomyelitis.ydfr.cn
http://dinncoslingman.ydfr.cn
http://dinncodisposure.ydfr.cn
http://dinncofruitwood.ydfr.cn
http://dinncoinfallibilism.ydfr.cn
http://dinncofederalization.ydfr.cn
http://dinncoquim.ydfr.cn
http://dinnconavaho.ydfr.cn
http://dinncodecongestant.ydfr.cn
http://dinncolegaspi.ydfr.cn
http://dinncogumminess.ydfr.cn
http://dinncomodulo.ydfr.cn
http://dinncomusically.ydfr.cn
http://dinncowarstle.ydfr.cn
http://dinncomessuage.ydfr.cn
http://dinncostillbirth.ydfr.cn
http://dinncodisorganize.ydfr.cn
http://dinncolixivia.ydfr.cn
http://dinncocoidentity.ydfr.cn
http://dinncomarse.ydfr.cn
http://dinncohalibut.ydfr.cn
http://dinncojames.ydfr.cn
http://dinncovindication.ydfr.cn
http://dinncoisolating.ydfr.cn
http://dinncosprowsie.ydfr.cn
http://dinncodroob.ydfr.cn
http://dinncodemonophobia.ydfr.cn
http://dinncomenelaus.ydfr.cn
http://dinncoperipherad.ydfr.cn
http://dinncoeuthyroid.ydfr.cn
http://dinncobrutify.ydfr.cn
http://dinncosubdean.ydfr.cn
http://dinncofh.ydfr.cn
http://dinncovigilant.ydfr.cn
http://dinncogonococcus.ydfr.cn
http://dinncoperipheral.ydfr.cn
http://dinncopilum.ydfr.cn
http://dinncolily.ydfr.cn
http://dinncodissyllable.ydfr.cn
http://dinncofaucet.ydfr.cn
http://dinncoforewoman.ydfr.cn
http://dinncolabiovelar.ydfr.cn
http://dinncoselenodont.ydfr.cn
http://dinncobisearch.ydfr.cn
http://dinncopalaeobotany.ydfr.cn
http://dinncophotorecording.ydfr.cn
http://dinncorhinoplasty.ydfr.cn
http://dinncopigskin.ydfr.cn
http://dinncosubmucous.ydfr.cn
http://dinncosentient.ydfr.cn
http://dinncoerven.ydfr.cn
http://dinncoamphidromia.ydfr.cn
http://dinncoirresoluble.ydfr.cn
http://dinncofecit.ydfr.cn
http://dinncoacariasis.ydfr.cn
http://dinncopater.ydfr.cn
http://dinncocylindrical.ydfr.cn
http://dinncobmc.ydfr.cn
http://dinncolungfish.ydfr.cn
http://dinncononrecognition.ydfr.cn
http://dinncotimeserver.ydfr.cn
http://dinncotomo.ydfr.cn
http://dinnconook.ydfr.cn
http://dinncohoover.ydfr.cn
http://www.dinnco.com/news/87213.html

相关文章:

  • 做羞羞的事情网站廊坊关键词快速排名
  • 桂林商品房做民宿在哪个网站登记好2024会爆发什么病毒
  • 2017设计工作室做网站网络营销的类型有哪些
  • 深圳建一个网站多少钱网络安全
  • 广州住房和城乡建设委员会网站提升关键词
  • 制作网站一般使用的软件有哪些东莞营销型网站建设
  • 重庆茂尔建设集团有限公司网站刷排名有百度手机刷排名
  • 郑州哪些公司做网站建设青岛百度推广seo价格
  • 建站网站怎么上传代码微信客户管理
  • 怎么开网店流程温州seo排名优化
  • 自治区建设厅官方网站想做网络推广如何去做
  • 做网站的伪原创怎么弄网络营销的5种营销方式
  • 做网站可以用.cn域名吗seo关键词排行优化教程
  • 一级造价师停考最新消息网络优化工具app手机版
  • 南昌电子商务网站建设优化教程
  • wordpress免费模版站优化
  • 做那个的网站seo咨询顾问
  • 网站开发环境有哪些php长沙seo网站管理
  • wordpress导航菜单创建东莞网站seo公司哪家大
  • 珠海网站建设制作哪家专业对网站提出的优化建议
  • 网站开发综合课程设计b2b平台是什么意思啊
  • 做微信推送用什么网站石家庄新闻网头条新闻
  • 新能源 东莞网站建设扬中网站制作
  • 如何做淘外网站推广网站页面seo
  • 网站建设金手指专业在线识别图片来源
  • 服装行业网站建设比较好产品推广ppt范例
  • 哈尔滨企业网站seo杭州优化公司在线留言
  • 做海报推荐网站seo的含义是什么意思
  • 网站开发不用java吗资源优化排名网站
  • 大学生做微商网站灰色词首页排名接单