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

网站域名更换相应内容网站开发工具 晴天娃娃

网站域名更换相应内容,网站开发工具 晴天娃娃,手机版网站制作,宁德营销型网站建设此文之前#xff0c;项目已经添加了数据库DAO服务接口、资源访问目录、以及数据访问的html页面#xff0c;同时项目集成了spring security#xff0c;并替换了登录授权页面#xff1b;但是#xff0c;系统用户存储代码之中#xff0c;而且只注册了admin和user两个用户。在…        此文之前项目已经添加了数据库DAO服务接口、资源访问目录、以及数据访问的html页面同时项目集成了spring security并替换了登录授权页面但是系统用户存储代码之中而且只注册了admin和user两个用户。在实际上线项目中用户的数量和全限时需要不定时更改的登录的账户也需要进行角色和失效的确认。 为了更好的维护用户数据更好的保护系统资源我们引入Oauth2.0。OAuth是一个开放标准也就是一个授权框架使应用程序能够访问项目外的资源允许用户在第三方应用访问存储在其他服务器上的私密资源而在整个过程不需要提供用户名和密码给到第三方应用可以通过提供一个令牌(token)实现该功能采用令牌的方式可以让用户灵活的对第三方应用授权或收回权限。 1、修改醒目pom.xml文件引入Oauth2.0 jar包添加如下依赖 !--oauth2-- dependency groupIdorg.springframework.security.oauth/groupId artifactIdspring-security-oauth2/artifactId version2.2.1.Release/version /dependency      !--页面要用到的框架-- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-thymeleaf/artifactId /dependency 添加完成之后右键点击项目名称弹出菜单中选择“maven”→“update project”更新系统jar包。 2、开启EnableAuthorizationServer注解 开启EnableAuthorizationServer注解该注解会自动添加OAuth2的多个endpoint。 /oauth/authorize验证接口 AuthorizationEndpoint/oauth/token获取token/oauth/confirm_access用户授权/oauth/error认证失败/oauth/check_token资源服务器用来校验token/oauth/token_keyjwt模式下获取公钥位于TokenKeyEndpoint 通过 JwtAccessTokenConverter 访问key 继承AuthorizationServerConfigurerAdapter配置OAuth2认证服务器需要配置授权和Token相关的三个配置。 AuthorizationServerSecurityConfigurer声明安全约束允许那些请求可以访问和禁止访问。ClientDetailsServiceConfigurer配置独立的client客户端信息包括授权范围、授权方式、客户端权限等。授权方式包括password、implicit、client_redentials、authorization_code四种方式其中密码授权方式必须结合 AuthenticationManager 进行配置。AuthorizationServerEndpointsConfigurer配置授权服务器的Token存储方式、Token配置、授权模式 Token存储配置默认使用DefaultTokenServices管理生命周期。Token存储通过配置 TokenStore默认使用内存存储包括一下存储方式。 InMemoryTokenStore 默认方式保存在本地内存JdbcTokenStore 存储数据库RedisTokenStore 存储Redis这应该是微服务下比较常用方式JwtTokenStore 分布式跨域JWT存储方式 此项目采用JdbcTokenStore方式进行存储配置文件如下 package com.SJL.Spring.Oauth.Config; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; import org.springframework.security.oauth2.provider.ClientDetailsService; import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore; Configuration EnableAuthorizationServer public class OAuthAuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { Autowired private DataSource dataSource; Autowired    private BCryptPasswordEncoder passwordEncoder; Autowired private AuthenticationManager authenticationManager; Autowired private OAuthWebSecurityConfig oauthWebSecurityConfig; Override public void configure(final AuthorizationServerSecurityConfigurer oauthServer) throws Exception { oauthServer //客户端token调用许可 .tokenKeyAccess(permitAll()) //客户端校验token访问许可 .checkTokenAccess(permitAll())  .allowFormAuthenticationForClients();        } //refresh_token 单独配置UserDetailsService Bean public UserDetailsService userDetailsServiceRefresh_token() {  return oauthWebSecurityConfig.userDetailsService(); }  Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { endpoints  .tokenStore(new JdbcTokenStore(dataSource)).userDetailsService(userDetailsServiceRefresh_token())// 设置令牌 .authenticationManager(authenticationManager); } Bean // 声明 ClientDetails实现 public ClientDetailsService clientDetailsService() { return new JdbcClientDetailsService(dataSource); } Override public void configure(final ClientDetailsServiceConfigurer clients) throws Exception { clients.withClientDetails(clientDetailsService()); }    } 备注文件拷贝过程如下几个函数需要自行定义自动生成代码中未生成代码详细如下 1sysUserMapper.findByName(username); 2sysUserMapper.updateUNLockedByUserId(username); 3sysUserMapper.updatelockTimeByUserId(username, 0L); 4sysUserMapper.updatenLockByUserId(username, 0L); 5sysUserService.findPermissions(username) 3、开启EnableResourceServer注解在服务中声明资源服务器。 打开ActionApp.java文件添加EnableResourceServer 1删除WebSecurityConfig.java文件拷贝OAuthWebSecurityConfig.java文件 2配置App客户端ID和密码 打开“application.yml”文件添加如下代码 spring: security: oauth2: client: clientId: zrBm49l73k996cJj9471 clientSecret: b400wT1D62  accessTokenUri: ${auth-server}/oauth/token userAuthorizationUri: ${auth-server}/oauth/authorize scope: all resource: userInfoUri: ${auth-server}/user   备注clientIdy和clientSecret为app唯一标识码注册在库表“oauth_client_details”中 4、获取服务令牌 上述配置采用“授权码”模式获取令牌首先获取授权码再用授权码换取令牌用户使用令牌访问系统资源 1获取授权码 在浏览器中输入测试地址http://localhost:2885/oauth/authorize?client_idzrBm49l73k996cJj9471response_typecoderedirect_urihttp://localhost:2885/assets/img 浏览器返回http://localhost:2885/assets/img?code 56Lv8n 2换取令牌 利用postman的post方式发送http://localhost:2885/oauth/token?grant_typeauthorization_codecode56Lv8nclient_idzrBm49l73k996cJj9471client_secretb400wT1D62redirect_urihttp://localhost:2885/assets/img获取令牌postman返回如下所示 其中 access_token: c334c2ab-aaf7-49c6-8ce5-f23459a6274f,就是我们获得令牌 3利用令牌访问资源 浏览器中输入http://localhost:2885/assets/img/%E6%B5%B7%E8%B1%9A.png?access_tokenc334c2ab-aaf7-49c6-8ce5-f23459a6274f,即可访问资源如下图所示 到此springbootspring securityOauth2.0的授权服务器和资源服务器的搭建工作就结束了。下文讲详细讲解Oauth2.0的几个重要结构文件详细配置以及授权错误处理实现系统登陆的闭环测试。
http://www.pierceye.com/news/110542/

相关文章:

  • app网站怎么下载个人备案做视频网站
  • 西宁建一个网站公司广东网站备案
  • 网站数据比较北京网站优化推广公司
  • 想做网站的客户在哪找美间在线设计平台
  • 网站设计规划的目的和要求营销外贸网站建设案例
  • 网站营销力一级a做爰片2017免费网站
  • 昌图网站网页界面设计的要求
  • 做一个网站赚钱什么 门户网站
  • 中国建设银行购物网站帝国织梦wordpress
  • 瑞安网站网站建设松原公司做网站的流程
  • 做网站按页面收费视频解析网站如何做搜索
  • 太原网站的公司赣州安全教育平台
  • 淮北建投网站网站推广与维护有什么不同
  • 深圳网站备案注销平果县免费网站哪家好
  • 如何区分网站开发语言做网站多少钱一般
  • 定制专业app开发seo数据统计分析工具有哪些
  • 某服装公司网站建设论文网站建设seo虾哥网络
  • 网站建设销售员工作内容网站访问量过大
  • 企业网站加快企业信息化建设设计网站名称
  • 做网站的技术要求高吗农业推广专业
  • 在百度做个卷闸门网站怎么做成都高端网站
  • 个人网站备案名称填写货运网站建设公司
  • 有网页源码 怎么做网站外链发布软件
  • 医疗网站建设基本流程wordpress速度加快
  • 网站建设优化开发公司哪家好泰州东方医院男科
  • 怎么自己做歌曲网站大连网站制作公司费用多少
  • 网站专题设计稿用vue做商城网站常用的js
  • 怎么在免费空间里面做网站深圳英文站seo
  • 学风建设网站版块如何用visual studio做网站
  • 山东响应式网站设置字体颜色的网站