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

网站制作 信科网络进入百度搜索网站

网站制作 信科网络,进入百度搜索网站,深圳小程序服务商,平面设计到题目uaa 授权在上一篇文章中#xff0c;我介绍了如何使用Cloud Foundry UAA项目启动OAuth2授权服务器#xff0c;以及如何使用OAuth2授权代码流程中涉及的一些参与者来填充它。 我在Digital Ocean网站上发现这篇文章在描述OAuth2授权代码流方面做得很好#xff0c;因此#xf… uaa 授权 在上一篇文章中我介绍了如何使用Cloud Foundry UAA项目启动OAuth2授权服务器以及如何使用OAuth2授权代码流程中涉及的一些参与者来填充它。 我在Digital Ocean网站上发现这篇文章在描述OAuth2授权代码流方面做得很好因此与其重新哈希该流中涉及的内容不如直接使用Spring Boot / Spring Security实现该流。 下图受此处的启发显示了授权码授予类型的高级流程 我将有两个应用程序-资源服务器公开用户的某些资源以及客户端应用程序代表用户访问这些资源。 如前面的博客文章所述可以启动授权服务器本身。 文章的其余部分可以更轻松地跟随我的github存储库中的代码 授权服务器 可以使用我之前的博客文章中描述的步骤轻松启动Cloud Foundry UAA服务器。 一旦完成可以使用以下uaac命令来填充运行样本所需的不同凭据。 这些脚本将为客户端应用程序创建客户端凭据并添加一个名为“ user1”的用户其范围为“ resource.read”和“ resource.write”。 # Login as a canned client uaac token client get admin -s adminsecret# Add a client credential with client_id of client1 and client_secret of client1 uaac client add client1 \--name client1 \--scope resource.read,resource.write \-s client1 \--authorized_grant_types authorization_code,refresh_token,client_credentials \--authorities uaa.resource# Another client credential resource1/resource1 uaac client add resource1 \--name resource1 \-s resource1 \--authorized_grant_types client_credentials \--authorities uaa.resource# Add a user called user1/user1 uaac user add user1 -p user1 --emails user1user1.com# Add two scopes resource.read, resource.write uaac group add resource.read uaac group add resource.write# Assign user1 both resource.read, resource.write scopes.. uaac member add resource.read user1 uaac member add resource.write user1资源服务器 资源服务器通过以下方式公开了一些端点这些端点使用Spring MVC表示并使用Spring Security进行保护 RestController public class GreetingsController {PreAuthorize(#oauth2.hasScope(resource.read))RequestMapping(method RequestMethod.GET, value /secured/read)ResponseBodypublic String read(Authentication authentication) {return String.format(Read Called: Hello %s, authentication.getCredentials());}PreAuthorize(#oauth2.hasScope(resource.write))RequestMapping(method RequestMethod.GET, value /secured/write)ResponseBodypublic String write(Authentication authentication) {return String.format(Write Called: Hello %s, authentication.getCredentials());} } 公开了两个端点uri –授权用于范围“ resource.read”的“ /安全/读取”和授权用于范围“ resource.write”的“ /安全/写入” 保护这些端点并将应用程序标记为资源服务器的配置如下 Configuration EnableResourceServer EnableWebSecurity EnableGlobalMethodSecurity(securedEnabled true, prePostEnabled true) public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {Overridepublic void configure(ResourceServerSecurityConfigurer resources) throws Exception {resources.resourceId(resource);}Overridepublic void configure(HttpSecurity http) throws Exception {http.antMatcher(/secured/**).authorizeRequests().anyRequest().authenticated();} } 该配置以及描述如何验证令牌的属性是使资源服务器运行所需的全部。 客户 使用Spring Security OAuth2的OAuth2的客户端配置也相当简单 EnableAuth2SSO批注提取所有必需的配置以为OAuth2流连接Spring安全过滤器 EnableOAuth2Sso Configuration public class OAuth2SecurityConfig extends WebSecurityConfigurerAdapter {Overridepublic void configure(WebSecurity web) throws Exception {super.configure(web);}Overrideprotected void configure(HttpSecurity http) throws Exception {http.csrf().disable();//formatter:offhttp.authorizeRequests().antMatchers(/secured/**).authenticated().antMatchers(/).permitAll().anyRequest().authenticated();//formatter:on}} 要调用下游系统客户端必须在下游调用中将OAuth令牌作为标头传递这是通过挂钩称为OAuth2RestTemplate的专用RestTemplate来完成的该模板可以从上下文中获取访问令牌并将其传递到下游连接了一个安全的下游呼叫如下所示 public class DownstreamServiceHandler {private final OAuth2RestTemplate oAuth2RestTemplate;private final String resourceUrl;public DownstreamServiceHandler(OAuth2RestTemplate oAuth2RestTemplate, String resourceUrl) {this.oAuth2RestTemplate oAuth2RestTemplate;this.resourceUrl resourceUrl;}public String callRead() {return callDownstream(String.format(%s/secured/read, resourceUrl));}public String callWrite() {return callDownstream(String.format(%s/secured/write, resourceUrl));}public String callInvalidScope() {return callDownstream(String.format(%s/secured/invalid, resourceUrl));}private String callDownstream(String uri) {try {ResponseEntityString responseEntity this.oAuth2RestTemplate.getForEntity(uri, String.class);return responseEntity.getBody();} catch(HttpStatusCodeException statusCodeException) {return statusCodeException.getResponseBodyAsString();}} }示范 可以使用此处的说明启动客户端和资源服务器。 一旦所有系统启动访问客户端将向用户显示一个页面如下所示 访问安全页面将导致授权服务器显示登录页面 客户端正在向用户请求“ resource.read”和“ resource.write”范围提示用户授权这些范围 假设用户已授权“ resource.read”但未授权“ resource.write”则令牌将呈现给用户 在这一点上如果要求下游资源的范围为“ resource.read”则应获取它 并且如果请求的下游资源具有用户未授权的范围在这种情况下为“ resource.write” 参考 大多数代码基于此处提供的Cloud Foundry UAA应用程序示例– https://github.com/pivotal-cf/identity-sample-apps 帖子中的代码在这里 https://github.com/bijukunjummen/oauth-uaa-sample 翻译自: https://www.javacodegeeks.com/2017/03/using-uaa-oauth2-authorization-server-client-resource.htmluaa 授权
http://www.zqtcl.cn/news/338643/

相关文章:

  • 中国建设基础设施总公司 网站怒江网站建设
  • 做电脑网站手机能显示不出来怎么办有友情链接的网站
  • 潘家园做网站的公司网络营销管理系统
  • 如何在各大平台推广博客网站seo
  • 网站地图那么建设国内哪个网站做水产比较大
  • 可以做图片视频的网站网站策划网
  • 在阿里云做的网站怎么移动南宁seo咨询
  • 电子商务网站开发课程设计论文温州市微网站制作电话
  • 常州住房和城乡建设部网站网站开发哪家公司口碑好
  • 网站备案 登录名巴中交通建设有限公司网站
  • 门户资源分享网站模板软件网站开发市场前景
  • 海南省住房和城乡建设厅官方网站列举五种常用的网站推广方法
  • aso优化服务平台东莞优化seo
  • 高唐做创建网站的公司网站开发费怎么做账
  • 域名有没有被注册哪个网站最好中企动力网站建设方案
  • 无锡网站制作计划我的世界寻找建筑网站
  • 烟台建设集团招聘信息网站青岛百度公司总部
  • php网站模板怎么用怎么做链接网站
  • 完整网站开发视频教程安丘营销型网站建设
  • 女与男爱做电影网站免费网站外包公司
  • 传统文化传播公司网站建设wordpress 插件开启
  • 哪些网站是做外贸生意的网站建设所需美工
  • 网站建设哪个公司比较好惠州网络问政平台
  • 河南网站备案系统短信广州注册公司程序
  • 苏晋建设集团网站跨专业的简历怎么制作
  • 交互网站怎么做设计师作品网站
  • 国外网站的分析工具有哪些办公室装修计入什么会计科目
  • 手机网站 需求模板3000元建设个人网站
  • 请人做网站域名和主机thinkphp网站开发实战教程
  • 做地产网站哪家好饮料网站建设价格