课程网站建设的背景网站开发软件英文版

张小明 2026/1/19 19:19:40
课程网站建设的背景,网站开发软件英文版,wordpress显示doc,网站如何修改后台密码授权简介前面我们了解的用户登录认证#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进行投诉反馈,一经查实,立即删除!

电商详情做的最好看的网站wordpress 官方文档

在当今数据驱动的时代,掌握高效的数据处理技能已成为数据分析师的核心竞争力。本文基于100个Pandas练习题项目,为你呈现一套完整的数据分析实战解决方案,帮助你在短时间内快速提升数据处理能力。 【免费下载链接】100-pandas-puzzles 100 dat…

张小明 2026/1/17 21:04:44 网站建设

网站新闻更新怎么设计产品开发的流程包括哪几个阶段

Linux 压缩、系统备份与软件安装全攻略 1. 压缩与备份基础 在 Linux 系统中,有多种压缩工具可供使用,每种工具都采用不同的压缩算法,从而产生不同的压缩比。以下是一些常见的压缩命令及其功能: | 命令 | 描述 | | — | — | | compress | 使用 Lempel - Ziv 压缩算法…

张小明 2026/1/17 21:04:45 网站建设

大型网站建设公司推荐十大现货交易平台排名

第一章:Open-AutoGLM新官网邀请码概述 Open-AutoGLM 是一个面向自动化代码生成与自然语言理解的开源大语言模型项目,其新官网上线后引入了邀请码机制,旨在控制初期用户增长节奏,保障系统稳定性并构建高质量开发者社区。邀请码不仅…

张小明 2026/1/17 21:04:45 网站建设

多人视频网站开发公司益阳市网站建设科技

在船舶设计与工程领域,专业软件往往价格昂贵,让许多设计师和爱好者望而却步。FREE!ship Plus in Lazarus作为一款完全免费的开源船舶设计工具,基于Lazarus/Free Pascal环境开发,为船舶设计师提供了强大的阻力分析、功率预测和流体…

张小明 2026/1/17 21:04:46 网站建设

吉林建设教育协会网站程序前端开发需要学什么软件

免费获取中小学智慧教育资源:knowledge-grab使用全攻略 【免费下载链接】knowledge-grab knowledge-grab 是一个基于 Tauri 和 Vue 3 构建的桌面应用程序,方便用户从 国家中小学智慧教育平台 (basic.smartedu.cn) 下载各类教育资源。 项目地址: https:…

张小明 2026/1/17 21:04:49 网站建设

门户网站推广渠道wordpress 栏目页

5分钟彻底解决PS3手柄电脑连接难题 【免费下载链接】BthPS3 Windows kernel-mode Bluetooth Profile & Filter Drivers for PS3 peripherals 项目地址: https://gitcode.com/gh_mirrors/bt/BthPS3 你是否曾经遇到过这样的困扰:手头闲置的PS3手柄无法在电…

张小明 2026/1/17 21:04:49 网站建设