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

海南响应式网站建设制作贵阳百度快照优化排名

海南响应式网站建设制作,贵阳百度快照优化排名,东莞网络公司,哪个网站做中高端衣服Spring Boot与安全视频 Spring Security, shiro等安全框架。主要功能是”认证“和”授权“#xff0c;或者说是访问控制。 认证#xff08;Authentication#xff09;是建立在一个声明主体的过程#xff08;一个主体一般指用户#xff0c;设备或一些可以在你的应用程序中…Spring Boot与安全视频 Spring Security, shiro等安全框架。主要功能是”认证“和”授权“或者说是访问控制。 认证Authentication是建立在一个声明主体的过程一个主体一般指用户设备或一些可以在你的应用程序中执行动作的其他系统。 授权Authorization指确定一个主体是否允许在你的应用程序执行一个动作的过程。 为了抵达需要授权的店 主体的身份已经有认证过程建立。 这里我们使用Spring Security练习。 1. pom.xml 创建springboot应用导入spring-boot-starter-security等相关依赖。 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion1.5.12.RELEASE/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom.crysw.security/groupIdartifactIdspringboot05-security/artifactIdversion0.0.1-SNAPSHOT/versionnamespringboot05-security/namedescriptionspringboot05-security/descriptionpropertiesjava.version1.8/java.version!--指定thymeleaf相关依赖的版本--thymeleaf.version3.0.9.RELEASE/thymeleaf.versionthymeleaf-layout-dialect.version2.3.0/thymeleaf-layout-dialect.versionthymeleaf-extras-springsecurity4.version3.0.2.RELEASE/thymeleaf-extras-springsecurity4.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-security/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-thymeleaf/artifactId/dependency!--可以在html中引用thymeleaf来获取授权和认证的相关信息--dependencygroupIdorg.thymeleaf.extras/groupIdartifactIdthymeleaf-extras-springsecurity4/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build/project2. html页面 准备静态资源(html测试页面) 2.1 welcome.html /请求转发到首页welcome.html !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.orgxmlns:sechttp://www.thymeleaf.org/thymeleaf-extras-springsecurity4 headmeta http-equivContent-Type contenttext/html charsetUTF-8titleTitle/title /head body h1 th:aligncenter欢迎光临武林秘籍管理系统/h1!--没有认证-- div sec:authorize!isAuthenticated()!--/login的get请求是security默认跳转登录页面的处理--!--h2 aligncenter游客您好如果想查看武林秘籍,a th:href{/login}请登录/a/h2--!--/userlogin的get请求是自定义跳转自己登录认证页面的处理--h2 th:aligncenter游客您好如果想查看武林秘籍,a th:href{/userlogin}请登录/a/h2 /div!--只有登录认证了才展示注销按钮-- div sec:authorizeisAuthenticated()h2span sec:authenticationname/span, 您好您的角色有spansec:authenticationprincipal.authorities/span/h2form th:action{/logout} methodpostinput typesubmit value注销//form /divhr !--授权VIP1的模块展示-- div sec:authorizehasRole(VIP1)h3普通武林秘籍/h3ullia th:href{/level1/1}罗汉拳/a/lilia th:href{/level1/2}武当长拳/a/lilia th:href{/level1/3}全真剑法/a/li/ul /div !--授权VIP2的模块展示-- div sec:authorizehasRole(VIP2)h3高级武林秘籍/h3ullia th:href{/level2/1}太极拳/a/lilia th:href{/level2/2}七伤拳/a/lilia th:href{/level2/3}梯云纵/a/li/ul /div!--授权VIP3的模块展示-- div sec:authorizehasRole(VIP3)h3绝世武林秘籍/h3ullia th:href{/level3/1}葵花宝典/a/lilia th:href{/level3/2}龟派气功/a/lilia th:href{/level3/3}独孤九剑/a/li/ul /div/body /html2.2 login.html 请求/userlogin转发到自定义的登录页面 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta http-equivContent-Type contenttext/html charsetUTF-8titleTitle/title /head body h1 th:aligncenter欢迎来到武林秘籍管理系统/h1 hr/ div th:aligncenter!--默认post形式的/login代表处理登录提交--!--如果定制loginPage那么loginPage的post请求就是登录提交--form th:action{/userlogin} methodpost用户名: input typetext nameuname/br/密码input typepassword namepwd/br/input typecheckbox nameremember id/ remember mebr/input typesubmit value登录//form /div /body /html2.3 level1模块页面 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta http-equivContent-Type contenttext/html charsetUTF-8titleTitle/title /head body a th:href{/}返回/a h1罗汉拳/h1 p罗汉拳站当秧打起来不要慌/p /body /html其他模块页面一样简单改一下内容即可。 3. security配置类 WebSecurityConfigurerAdapter为创建WebSecurityConfigurer实例提供了一个方便的基类。允许通过重写方法进行定制实现自定义授权规则和认证规则。 EnableWebSecurity public class MySecurityConfig extends WebSecurityConfigurerAdapter {/*** 定制请求的授权规则** param http the {link HttpSecurity} to modify* throws Exception*/Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers(/).permitAll()// VIP1角色的用户才能访问level1的页面其他同理.antMatchers(/level1/**).hasRole(VIP1).antMatchers(/level2/**).hasRole(VIP2).antMatchers(/level3/**).hasRole(VIP3);// 开启自动配置的登录功能 // http.formLogin();http.formLogin().usernameParameter(uname).passwordParameter(pwd).loginPage(/userlogin).loginProcessingUrl(/userlogin);// 1. 如果没有访问权限转发到/login请求来到登录页// 2. 重定向到/login?error表示登录失败。 更多详细规定// 3. 默认post形式的/login代表处理登录提交// 4.如果定制loginPage那么loginPage的post请求就是登录提交// 开启自动配置的注销功能, 访问/logout表示用户注销清空session; 注销成功后来到首页;http.logout().logoutSuccessUrl(/);// 开启记住我的功能, 将cookie发给浏览器保存以后登录带上这个cookie只要通过服务器端的验证就可以免登录// 如果点击”注销“也会删除这个cookie // http.rememberMe();http.rememberMe().rememberMeParameter(remember);}/*** 定制认证规则** param auth the {link AuthenticationManagerBuilder} to use* throws Exception*/Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.inMemoryAuthentication().withUser(zhangsan).password(123456).roles(VIP1, VIP2).and().withUser(lisi).password(123456).roles(VIP2, VIP3).and().withUser(wangwu).password(123456).roles(VIP1, VIP3);} }启动应用后访问主页需要先登录认证。可以看到张三有访问VIP1, VIP2权限的区域展示。 登录认证成功后跳转到欢迎主页。
http://www.dnsts.com.cn/news/28952.html

相关文章:

  • 网站建设 佛山网站推广及seo方案
  • 汝阳网站开发合肥网站建设服务公司
  • 网站建设互联网加金属材料东莞网站建设
  • 北京开发网站垂直门户网站都有什么
  • seo蒙牛伊利企业网站专业性诊断wordpress创建配置文件 没反应
  • 自己做网站 什么软件平面设计包括什么
  • 大气网站模板下载动画设计毕业作品搞笑
  • 路桥建设网站中国能源建设集团有限公司董事长
  • 做维修注册网站wordpress 仿魔客吧
  • 学校网站开发系统的背景深圳网站建设公司哪家专业
  • 美橙网站开发seo推广方法有哪些
  • 北京建设工程教育中心网站重庆天气专业网站建设
  • .net 大型网站开发技术wordpress怎么修改模板文件
  • ftp给网站上传图片后图片的链接地址被改了access数据库做网站
  • 我想做京东网站淘宝怎么做易语言做网站客户端
  • 网站图片设置4:3网络营销的效果表现在哪几个方面
  • 一个空间做多个网站网站维护费计入什么科目
  • 域名注册服务商网站绿色食品网站模板.htm
  • html网页制作个人网站目前提供目录类搜索引擎的网站
  • 北京城市副中心投资建设公司网站国内永久免费网游
  • app开发公司职位南通优化网站价格
  • 提供模板网站制作多少钱网站 302重定向 备案
  • 内蒙古电子商务网站自己怎么建个网站
  • 网站怎么更新内容wordpress调整语言
  • 做什么软件做网站效率最好电子商务网站建设试卷.doc
  • 网站管理文档怎么写上海市工程建设协会网站
  • 天津建设教育培训中心网站网版制作过程
  • 有没有什么网站专门帮人做问卷河南建设工程造价信息
  • 进贤县住房和城乡建设局网站长沙关键词优化首选
  • 本地网站模板修改网站开发大致需要哪些步骤