成华网站制作修改网页数据的修改器

张小明 2025/12/31 21:53:20
成华网站制作,修改网页数据的修改器,长沙网络推广代理,半夜一分快三app推荐直播下载授权简介前面我们了解的用户登录认证#xff0c;不管是用户密码还是图像验证码都是为了让系统知道你是谁#xff0c;你可以在这个系统中做什么事情#xff0c;这个情况就是叫做授权。其实也就是你是否能够控制访问某个url路径。我们在应用系统中#xff0c;如果想要控制用户…授权简介前面我们了解的用户登录认证不管是用户密码还是图像验证码都是为了让系统知道你是谁你可以在这个系统中做什么事情这个情况就是叫做授权。其实也就是你是否能够控制访问某个url路径。我们在应用系统中如果想要控制用户权限需要2部分数据系统配置信息数据写着系统里面哪些url每个url需要哪些权限才可以被访问另一份数据就是用户权限信息请求用户拥有权限系统用户发送一个请求系统配置信息和用户权限进行对比如果对比成功则允许被访问。SpringSecurity授权内置权限表达式表达式说明permitAll指定任何人都允许访问。denyAll指定任何人都不允许访问。anonymous指定匿名用户允许访问。rememberMe指定已记住的用户允许访问。authenticated指定任何经过身份验证的用户都允许访问不包含 anonymous。fullyAuthenticated指定经过身份验证的用户允许访问不包含 anonymous 和 rememberMe。hasRole(role)指定需要特定的角色的用户允许访问会自动在角色前面插入ROLE_。hasAnyRole(role1,role2)指定需要任意一个角色的用户允许访问会自动在角色前面插入ROLE_。hasAuthority(authority)指定需要特定的权限的用户允许访问。hasAnyAuthority(authority1,authority2)指定需要任意一个权限的用户允许访问。hasIpAddress(ip)指定需要特定的 IP 地址可以访问。url安全表达式自定义权限不足类Component public class MyAccessHandler implements AccessDeniedHandler { Override public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException { httpServletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN); httpServletResponse.setContentType(text/html;charsetUTF-8); httpServletResponse.getWriter().write(权限不足); } }设置url访问权限// 权限控制, 只有ADMIN角色的用户才能访问/user/** http.authorizeRequests().antMatchers(/user/**).hasRole(ADMIN); // 权限控制, 只有ADMIN或者PRODUCT角色的用户才能访问/product/**, 并且只能从127.0.0.1访问 http.authorizeRequests().antMatchers(/product/**).access(hasRole(ADMIN,PRODUCT)and hasIpAddress(127.0.0.1)); // 拒绝访问处理 http.exceptionHandling().accessDeniedHandler(accessDeniedHandler);设置用户对于的角色权限// 先声明一个权限集合, 因为构造方法里面不能传入null CollectionGrantedAuthority authorities new ArrayList(); if (admin.equalsIgnoreCase(user.getUsername())) { authorities.add(new SimpleGrantedAuthority(ROLE_ADMIN)); } else { authorities.add(new SimpleGrantedAuthority(ROLE_PRODUCT)); }在web安全表达式中引用自定义Bean授权自定义授权类/** * 自定义授权类 */ Component public class MyAuthorizationService { /** * 检查用户是否有对应的访问权限 * * param authentication 登录用户 * param request 请求对象 * return */ public boolean check(Authentication authentication, HttpServletRequest request) { User user (User) authentication.getPrincipal(); // 获取用户所有权限 CollectionGrantedAuthority authorities user.getAuthorities(); // 获取用户名 String username user.getUsername(); // 如果用户名为admin,则不需要认证 if (username.equalsIgnoreCase(admin)) { return true; } else { // 循环用户的权限, 判断是否有ROLE_ADMIN权限, 有返回true for (GrantedAuthority authority : authorities) { String role authority.getAuthority(); if (ROLE_ADMIN.equals(role)) { return true; } } } return false; } }配置类//使用自定义Bean授权 http.authorizeRequests().antMatchers(/user/**). access(myAuthorizationService.check(authentication,request));携带路径变量/** * 检查用户是否有对应的访问权限 * * param authentication 登录用户 * param request 请求对象 * param id 参数ID * return */ public boolean check(Authentication authentication, HttpServletRequest request, Integer id) { if (id 10) { return false; } return true; }//使用自定义Bean授权,并携带路径参数 http.authorizeRequests().antMatchers(/user/delete/{id}). access(myAuthorizationService.check(authentication,request,#id));Method安全表达式针对方法级别的访问控制比较复杂spring security提供了4种注解分别是PreAuthorizePostAuthorizePreFilterPostFilter开启方法级别的注解配置Configuration EnableGlobalMethodSecurity(prePostEnabled true) public class SecurityConfiguration extends WebSecurityConfigurerAdapter在方法上使用注解RequestMapping(/findAll) PreAuthorize(hasRole(ADMIN))//需要ADMIN权限 public String findAll(Model model) { ListUser userList userService.list(); model.addAttribute(userList, userList); return user_list; } /** * 用户修改页面跳转 * * return */ RequestMapping(/update/{id}) PreAuthorize(#id10)//针对参数权限限定 id10可以访问 public String update(PathVariable Integer id, Model model) { User user userService.getById(id); model.addAttribute(user, user); return user_update; }RBAC权限模型简介用户系统接口及访问的操作者权限能够访问某接口或者做某操作的授权资格角色具有一类相同操作权限的总称RBAC的演化进程用户与权限直接关联用户与角色关联基于RBAC设计权限表结构一个用户有一个或者多个角色一个用户包含多个用户一个角色有多种权限一个权限属于多个角色、1. 动态查询用户对应的权限Mapper 层import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.tapou.domain.Permission; import org.apache.ibatis.annotations.Select; import java.util.List; public interface PermissionMapper extends BaseMapperPermission { /** * 根据用户ID查询权限 * param id 用户ID * return 用户对应的权限列表 */ Select(SELECT p.* FROM permission p,t_role_permission rp,t_role r,t_user_role ur,t_user u WHERE u.id #{id} AND ur.user_id u.id AND ur.role_id r.id AND rp.role_id r.id AND rp.permission_id p.id) ListPermission findByUserId(Integer id); }2. 给用户授权权限装配// 先声明一个权限集合避免空指针 CollectionGrantedAuthority authorities new ArrayList(); // 调用service查询用户的权限列表 ListPermission permissions permissionService.findByUserId(user.getId()); for (Permission permission : permissions) { // 将权限添加到认证对象中 authorities.add(new SimpleGrantedAuthority(permission.getPermissionTag())); }3. 设置请求访问权限全局权限拦截// 查询数据库中所有权限列表 ListPermission permissions permissionService.list(); for (Permission permission : permissions) { // 为指定请求路径配置“需拥有对应权限才能访问” http.authorizeRequests() .antMatchers(permission.getPermissionUrl()) // 请求路径 .hasAuthority(permission.getPermissionTag()); // 所需权限 }基于页面端标签的权限控制首先需要引入配置文件!--添加thymeleaf为SpringSecurity提供的标签 依赖 -- dependency groupIdorg.thymeleaf.extras/groupId artifactIdthymeleaf-extras-springsecurity5/artifactId version3.0.4.RELEASE/version /dependency在html中申请使用!DOCTYPE html html xmlns:thhttp://www.thymeleaf.org xmlns:sechttp://www.thymeleaf.org/extras/spring-security常用 SpringSecurity 标签属性介绍标签属性说明sec:authorizeisAuthenticated()判断用户是否已登录认证引号内参数固定为isAuthenticated()。sec:authenticationname获取当前用户的用户名引号内参数固定为name。sec:authorizehasRole(role)判断当前用户是否拥有指定角色引号内参数为角色名称。sec:authorizehasAuthority(权限名)判断当前用户是否拥有指定权限引号内参数为权限名称。SpringSecurity标签的使用示例div classleftnav div classleftnav-title !-- 判断用户是否已认证登录 -- div sec:authorizeisAuthenticated() !-- 获取当前用户名 -- span sec:authenticationname/span img srcimages/y.jpg classradius-circle rotate-hover height50 alt /div /div !-- 判断用户是否拥有“user:findAll”权限 -- div sec:authorizehasAuthority(user:findAll) dl dtspan classicon-user/span系统管理/dt dd styledisplay:block ul !-- 有权限则显示“用户管理”链接 -- lia href/user/findAll targetrightspan classicon-caret-right/span用户管理/a/li lia hrefjavascript:void(0) onclicktoCors() targetright span classicon-caret-right/span跨域测试/a /li /ul /dd /dl /div !-- 判断用户是否拥有“product:findAll”权限 -- div sec:authorizehasAuthority(product:findAll) dl dtspan classicon-pencil-square-o/span数据管理/dt dd ul !-- 有权限则显示“商品管理”链接 -- lia href/product/findAll targetrightspan classicon-caret-right/span商品管理/a/li /ul /dd /dl /div /div
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

北京建站管理系统开发用html制作个人网站源代码

Linly-Talker在抑郁症筛查中的初步对话测试 在精神健康问题日益凸显的今天,一个沉默而普遍的现实是:许多有抑郁倾向的人从未走进心理咨询室。不是因为他们不需要帮助,而是因为羞耻感、资源稀缺或对“面对面倾诉”的恐惧,让他们选择…

张小明 2025/12/27 4:49:18 网站建设

建德营销型网站建设临海建设局网站

MetaRTC终极入门指南:5分钟快速上手跨平台WebRTC开发 【免费下载链接】metaRTC A cross-platform webRTC SDK 项目地址: https://gitcode.com/gh_mirrors/me/metaRTC 想要快速掌握跨平台WebRTC开发技术吗?MetaRTC作为一款功能强大的开源WebRTC SD…

张小明 2025/12/27 4:49:19 网站建设

欧美设计网站桐乡做网站

GG3M相关内容目录(中英对照版) 第1章:鸽姆智库概述(GG3M Overview) 第2章:全球痛点(Global Pain Points) 第3章:GG3M 的使命:构建智慧文明的未来&#xff…

张小明 2025/12/30 0:07:33 网站建设

个人网站备案说明怎样做地方门户网站

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容: 创建一个基于paraphrase-multilingual-minilm-l12-v2模型的文本改写工具,支持多种语言的输入和输出。用户可以输入一段文本,选择目标语言,系统自…

张小明 2025/12/27 0:14:14 网站建设

一个门户网站多少钱网站开发怎样

C 允许在同一作用域中的某个函数和运算符指定多个定义,分别称为函数重载和运算符重载。 重载声明是指一个与之前已经在该作用域内声明过的函数或方法具有相同名称的声明,但是它们的参数列表和定义(实现)不相同。 当您调用一个重…

张小明 2025/12/27 0:14:12 网站建设

用vs做网站后台开发可以吗外国广告公司网站

SpringAI与LangChain4j都是Java生态中用于构建智能应用的框架,前者侧重与Spring生态集成,方便企业级应用智能化改造;后者强调多模型适配与灵活的工作流构建,适用于创新型AI产品开发等场景。以下是具体介绍: SpringAI智…

张小明 2025/12/27 0:14:10 网站建设