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

网站开发有哪些软件有哪些上海网站建设公司联系方式

网站开发有哪些软件有哪些,上海网站建设公司联系方式,宁波网络推广的公司报价,小网站做几个关键词用 Spring Security 实现后台登录及权限认证功能 1.引入依赖2.创建权限开放的页面3.创建需要权限验证的页面4.配置 Spring Security4.1 配置 Spring MVC4.2 配置 Spring Security 5.创建登录页面6.测试权限 1.引入依赖 使用前需要引入相关依赖#xff0c;见以下代码#xff… 用 Spring Security 实现后台登录及权限认证功能 1.引入依赖2.创建权限开放的页面3.创建需要权限验证的页面4.配置 Spring Security4.1 配置 Spring MVC4.2 配置 Spring Security 5.创建登录页面6.测试权限 1.引入依赖 使用前需要引入相关依赖见以下代码 dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-security/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-thymeleaf/artifactId/dependencydependencygroupIdorg.thymeleaf.extras/groupIdartifactIdthymeleaf-extras-springsecurity5/artifactId/dependency /dependencies2.创建权限开放的页面 这个页面welcome.html是不需要鉴权即可访问的以区别演示需要鉴权的页面见以下代码 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.orgxmlns:sechttp://www.thymeleaf.org/thymeleaf-extras-springsecurity5headtitleSpring Security 案例/title/headbodyh1Welcome!/h1pa th:href{/home}会员中心/a/p/body /html3.创建需要权限验证的页面 其实可以和不需要鉴权的页面一样鉴权可以不在 HTML 页面中进行见以下代码 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.orgxmlns:sechttp://www.thymeleaf.org/thymeleaf-extras-springsecurity5headtitlehome/title/headbodyp会员中心/pp th:inlinetextHello span sec:authenticationname/span/pform th:action{/logout} methodpostinput typesubmit value登出//form/body /html使用 Spring Security 5 之后可以在模板中用 span sec:authenticationname/span 或 [[${#httpServletRequest.remoteUser}]] 来获取用户名。登岀请求将被发送到 /logout。成功注销后会将用户重定向到 /login?logout。 4.配置 Spring Security 4.1 配置 Spring MVC 可以继承 WebMvcConfigurer具体使用见以下代码 package com.example.demo.config;import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;Configuration public class WebMvcConfig implements WebMvcConfigurer {Overridepublic void addViewControllers(ViewControllerRegistry registry) {//设置登录处理操作registry.addViewController(/home).setViewName(springsecurity/home);registry.addViewController(/).setViewName(springsecurity/welcome);registry.addViewController(/login).setViewName(springsecurity/login);} }4.2 配置 Spring Security Spring Security 的安全配置需要继承 WebSecurityConfigurerAdapter然后重写其方法 见以下代码 package com.example.demo.config;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;Configuration // 指定为 Spring Security 配置类 EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter {Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers(/, /welcome, /login).permitAll().anyRequest().authenticated().and().formLogin().loginPage(/login).defaultSuccessUrl(/home).and().logout().permitAll();}Autowiredpublic void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser(admin).password($2a$10$AlpMTGDkUfYJMnb3/uNT1.mLxLJng7Uplfzpv5yIqZTkYtYsiiYbO).roles(USER);} }EnableWebSecurity 注解集成了 Spring Security 的 Web 安全支持。WebSecurityConfig在配置类的同时集成了 WebSecurityConfigurerAdapter重写了其中的特定方法用于自定义 Spring Security 配置。Spring Security 的工作量都集中在该配置类。configure(HttpSecurity)定义了哪些 URL 路径应该被拦截。configureGlobaI(AuthenticationManagerBuiIder)在内存中配置一个用户admin / pipi这个用户拥有 User 角色。确保 antMatchers(xxx).permitAll() 的配置在需要认证和授权的 URL 路径之前。因为 Spring Security 会按照配置文件的顺序来匹配 URL 路径如果 antMatchers(xxx).permitAll() 在后面那么前面的认证和授权规则会覆盖掉它。.logout().permitAll() 表示在 Spring Security 配置中‌无论用户是否经过身份验证‌都可以访问注销‌logout‌页面。‌这意味着‌即使是一个未经过身份验证的用户也可以访问注销功能‌这在某些情况下可能是一个安全隐患。‌因此‌这个配置通常用于开发环境或测试环境‌以确保用户可以轻松地测试注销功能‌而在生产环境中‌出于安全考虑‌通常会更加限制对注销页面的访问权限。‌ 5.创建登录页面 登录页面要特别注意是否开启了 CSRF 功能。如果开启了则需要提交 token 信息。创建的登录页面见以下代码 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.orgxmlns:sechttp://www.thymeleaf.org/thymeleaf-extras-springsecurity5headtitleSpring Security Example /title/headbodydiv th:if${param.error}无效的用户名或者密码/divdiv th:if${param.logout}你已经登出/divform th:action{/login} methodpostdivlabel 用户名: input typetext nameusername/ /label/divdivlabel 密码: input typepassword namepassword/ /label/divdivinput typesubmit value登录//div/form/body /html6.测试权限 启动项目访问首页 http://localhost:8080。 单击 “会员中心”尝试访问受限的页面 http://localhost:8080/home。由于未登录结果被强制跳转到登录页面 http://localhost:8080/login。 输入正确的用户名和密码 (admin, pipi) 之后跳转到之前想要访问的 /home 显示用户名 admin。 单击 “登出” 按钮回到登录页面。
http://www.hkea.cn/news/14565964/

相关文章:

  • 网站建设宽度优化教育培训
  • 丽水网站建设公司排名创作图片的软件
  • 杭州网站建设哪个平台好嘉兴网站建设平台
  • 服务网站开发天水网站开发
  • 做网站好还是做淘宝好用word做旅游网站
  • 符合seo的网站网站制作后续维护
  • 仓储物流网站建设网站建设设计制作
  • 网站加入搜索引擎怎么做建设工程施工合同的范本
  • 电子商务网站建设的心得北京网站建设 找奥美通全网营销
  • 全国设计师网站宜昌外贸网站建设优化推广
  • 怎么开设自己的网站免费icp备案服务码
  • 早期做网站 如何推广微网站建设包括哪些方面
  • 网站建设公司86215网络平台推广哪个好
  • 网站搭建 主机推荐网站建设单位哪家好
  • 南宁网站建设索q.479185700有关建设网站的问题
  • 久久建筑有限公司关键词优化推广排名
  • 太原网站快速排名提升阿里云wordpress安装教程
  • 自己做网站有什么意义wordpress数据清除缓存
  • 网页设计网站布局分析网站开发销售合同
  • 贵阳网站建设王道下拉惠盐城网站开发建设
  • 家居行业网站建设wordpress login form
  • 响应式网站和自适应网站区别家教网站代理
  • 如何做x响应式网站网站的设计原则
  • 网站app软件大全免费网站设计网页首页介绍
  • 如何做logo标志遵义网站优化
  • 网站建设项目申请书网上商城个人店铺
  • 做网站编辑累吗广告公司简介ppt范本
  • 成都快速建网站个人可以做网站吗
  • 如何制作网站赚钱wordpress iis支持
  • 济南cms建站动漫设计与制作难吗