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

dw制作wap网站怎么做开发比较实用的软件

dw制作wap网站怎么做,开发比较实用的软件,网站建设公司专业公司,要钱吗oidc auth2.0“我喜欢编写身份验证和授权代码。” 〜从来没有Java开发人员。 厌倦了一次又一次地建立相同的登录屏幕#xff1f; 尝试使用Okta API进行托管身份验证#xff0c;授权和多因素身份验证。 Spring Security不仅是一个功能强大且可高度自定义的身份验证和访问控制… oidc auth2.0 “我喜欢编写身份验证和授权代码。” 〜从来没有Java开发人员。 厌倦了一次又一次地建立相同的登录屏幕 尝试使用Okta API进行托管身份验证授权和多因素身份验证。 Spring Security不仅是一个功能强大且可高度自定义的身份验证和访问控制框架它还是保护基于Spring的应用程序的实际标准。 从前Spring Security需要使用大量的XML来配置所有内容但是那段日子已经过去了。 如今Spring Security通过Spring的JavaConfig提供了更简单的配置。 如果您看一下我最近写的JHipster OIDC示例中的SecurityConfiguration.java类您会发现它少于100行代码 Spring Security 5.0可以解析400多个票证并且具有许多新功能 OAuth 2.0登录 React性支持 EnableWebFluxSecurity EnableReactiveMethodSecurity和WebFlux测试支持 现代化的密码编码 今天我将向您展示如何在Okta中使用OAuth 2.0登录支持。 我还将向您展示如何通过OpenID ConnectOIDC检索用户的信息。 您知道Okta提供免费的开发人员帐户 每月最多有7,000个活跃用户对吗 这应该足以使您的杀手级应用破土动工。 Spring Security使使用OAuth 2.0进行身份验证变得非常容易。 它还提供了通过OIDC获取用户信息的功能。 请按照以下步骤了解更多信息 什么是OIDC 如果您不熟悉OAuth或OIDC建议您阅读OAuth到底是什么 。 Open ID Connect流涉及以下步骤 发现OIDC元数据 执行OAuth流以获取ID令牌和访问令牌 获取JWT签名密钥并可以选择动态注册客户端应用程序 根据内置日期和签名在本地验证JWT ID令牌 根据需要使用访问令牌获取其他用户属性 创建一个Spring Boot应用 在浏览器中打开start.spring.io 。 Spring Initialzr是一个站点可让您快速轻松地创建新的Spring Boot应用程序。 将Spring Boot版本在右上角设置为2.0.0.M7 。 输入组和工件名称。 从下面的屏幕快照中可以看到我选择了com.okta.developer和oidc 。 对于依赖项选择Web Reactive Web Security和Thymeleaf 。 单击“ 生成项目” 下载zip在硬盘上展开然后在您喜欢的IDE中打开项目。 使用./mvnw spring-boot:run运行该应用程序 ./mvnw spring-boot:run将提示您登录。 Spring Security 4.x通过基本身份验证而不是登录表单提示您因此这与Spring Security 5有所不同。 Spring Security启动程序会创建一个默认用户其用户名为“ user”并且密码每次启动应用程序时都会更改。 您可以在终端中找到该密码类似于以下密码。 Using default security password: 103c55b4-2760-4830-9bca-a06a87d384f9 在表单中为“用户”输入“ user”并为“密码”输入生成的密码。 下一个屏幕将是404因为您的应用没有为/路径配置默认路由。 在Spring Boot 1.x中您可以更改用户的密码因此每次都通过在src/main/resources/application.properties添加以下内容来更改密码。 security.user.passwordspring security is ph! 但是这是Spring Boot 2.0中不推荐使用的功能。 好消息是此更改可能会在GA发布之前恢复 。 同时您可以将打印的密码复制到控制台并与HTTPie一起使用 。 $ http --auth user:bf91316f-f894-453a-9268-4826cdd7e151 localhost:8080 HTTP/1.1 404 Cache-Control: no-cache, no-store, max-age0, must-revalidate Content-Type: application/json;charsetUTF-8 Date: Sun, 03 Dec 2017 19:11:50 GMT Expires: 0 Pragma: no-cache Set-Cookie: JSESSIONID65283FCBDB9E6EF1C0679290AA994B0D; Path/; HttpOnly Transfer-Encoding: chunked X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 1; modeblock 响应也将是404。 {error: Not Found,message: No message available,path: /,status: 404,timestamp: 2017-12-03T19:11:50.8460000 } 您可以通过在与OidcApplication.java src/main/java/com/okta/developer/oidc 相同的目录中创建MainController.java来摆脱404。 创建一个home()方法该方法映射到/并返回用户名。 package com.okta.developer.oidc;import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;import java.security.Principal;RestController public class MainController {GetMapping(/)String home(Principal user) {return Hello user.getName();} } 重新启动服务器使用user和生成的密码登录您应该看到Hello user 。 $ http --auth user:d7c4138d-a1cc-4cc9-8975-97f37567594a localhost:8080 HTTP/1.1 200 Cache-Control: no-cache, no-store, max-age0, must-revalidate Content-Length: 10 Content-Type: text/plain;charsetUTF-8 Date: Sun, 03 Dec 2017 19:26:54 GMT Expires: 0 Pragma: no-cache Set-Cookie: JSESSIONID22A5A91051B7AFBA1DC8BD30C0B53365; Path/; HttpOnly X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 1; modeblockHello user使用Okta添加身份验证 在上一教程中 我向您展示了如何使用Spring Security OAuth为您的应用程序提供SSO。 您可以在Spring Security 5中执行相同的操作但是您现在还可以指定多个提供程序而以前是做不到的。 Spring Security 5有一个OAuth 2.0登录示例 以及有关所有工作原理的文档 。 创建一个OpenID Connect应用 要与Okta集成您需要在developer.okta.com上注册一个帐户 。 确认电子邮件并登录后导航至应用程序 添加应用程序 。 单击Web 然后单击下一步 。 给应用程序起一个您将记住的名称将http://localhost:8080指定为基本URI并将http://localhost:8080/login/oauth2/code/okta为登录重定向URI。 将src/main/resources/application.properties重命名为src/main/resources/application.yml 并使用以下内容进行填充。 spring:thymeleaf:cache: falsesecurity:oauth2:client:registration:okta:client-id: {clientId}client-secret: {clientSecret}provider:okta:authorization-uri: https://{yourOktaDomain}.com/oauth2/default/v1/authorizetoken-uri: https://{yourOktaDomain}.com/oauth2/default/v1/tokenuser-info-uri: https://{yourOktaDomain}.com/oauth2/default/v1/userinfojwk-set-uri: https://{yourOktaDomain}.com/oauth2/default/v1/keys 将客户端ID和密码从OIDC应用程序复制到application.yml文件中。 对于{yourOktaDomain} 请使用您的域的值例如dev-158606.oktapreview.com 。 请确保它不包括-admin在里面。 您需要将一些依赖项添加到pom.xml Spring Security 5的OAuth配置才能正确初始化。 dependencygroupIdorg.springframework.security/groupIdartifactIdspring-security-config/artifactId /dependency dependencygroupIdorg.springframework.security/groupIdartifactIdspring-security-oauth2-client/artifactId /dependency dependencygroupIdorg.springframework.security/groupIdartifactIdspring-security-oauth2-jose/artifactId /dependency dependencygroupIdorg.thymeleaf.extras/groupIdartifactIdthymeleaf-extras-springsecurity4/artifactId /dependency 重新启动您的应用程序然后再次导航到http://localhost:8080 。 您会看到一个链接单击该链接可以使用Okta登录。 注意如果您想学习如何自定义Spring Security显示的登录屏幕请参阅其OAuth 2.0登录页面文档 。 单击链接后您应该会看到一个登录屏幕。 输入用于创建帐户的凭据登录后您应该会看到类似以下的屏幕。 注意可以更改某些内容以便Principal#getName()返回不同的值。 但是 Spring Boot 2.0.0.M7中存在一个错误 阻止了配置属性的工作。 使用OIDC获取用户信息 更改您的MainController.java使其具有以下代码。 这段代码添加了一个/userinfo映射该映射使用Spring WebFlux的WebClient从用户信息端点获取用户信息。 我从Spring Security 5的OAuth 2.0登录示例复制了以下代码。 /* * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.okta.developer.oidc;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ExchangeFilterFunction; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono;import java.util.Collections; import java.util.Map;/** * author Joe Grandja */ Controller public class MainController {private final OAuth2AuthorizedClientService authorizedClientService;public MainController(OAuth2AuthorizedClientService authorizedClientService) {this.authorizedClientService authorizedClientService;}RequestMapping(/)public String index(Model model, OAuth2AuthenticationToken authentication) {OAuth2AuthorizedClient authorizedClient this.getAuthorizedClient(authentication);model.addAttribute(userName, authentication.getName());model.addAttribute(clientName, authorizedClient.getClientRegistration().getClientName());return index;}RequestMapping(/userinfo)public String userinfo(Model model, OAuth2AuthenticationToken authentication) {OAuth2AuthorizedClient authorizedClient this.getAuthorizedClient(authentication);Map userAttributes Collections.emptyMap();String userInfoEndpointUri authorizedClient.getClientRegistration().getProviderDetails().getUserInfoEndpoint().getUri();if (!StringUtils.isEmpty(userInfoEndpointUri)) { // userInfoEndpointUri is optional for OIDC ClientsuserAttributes WebClient.builder().filter(oauth2Credentials(authorizedClient)).build().get().uri(userInfoEndpointUri).retrieve().bodyToMono(Map.class).block();}model.addAttribute(userAttributes, userAttributes);return userinfo;}private OAuth2AuthorizedClient getAuthorizedClient(OAuth2AuthenticationToken authentication) {return this.authorizedClientService.loadAuthorizedClient(authentication.getAuthorizedClientRegistrationId(), authentication.getName());}private ExchangeFilterFunction oauth2Credentials(OAuth2AuthorizedClient authorizedClient) {return ExchangeFilterFunction.ofRequestProcessor(clientRequest - {ClientRequest authorizedRequest ClientRequest.from(clientRequest).header(HttpHeaders.AUTHORIZATION,Bearer authorizedClient.getAccessToken().getTokenValue()).build();return Mono.just(authorizedRequest);});} } 在src/main/resources/templates/index.html创建Thymeleaf索引页面。 您可以使用Thymeleaf对Spring Security的支持根据用户的身份验证状态显示/隐藏页面的不同部分。 !DOCTYPE html html xmlnshttp://www.w3.org/1999/xhtml xmlns:thhttp://www.thymeleaf.orgxmlns:sechttp://www.thymeleaf.org/thymeleaf-extras-springsecurity4 headtitleSpring Security - OAuth 2.0 Login/titlemeta charsetutf-8 / /head body div stylefloat: right th:fragmentlogout sec:authorizeisAuthenticated()div stylefloat:leftspan stylefont-weight:boldUser: /spanspan sec:authenticationname/span/divdiv stylefloat:none /divdiv stylefloat:rightform action# th:action{/logout} methodpostinput typesubmit valueLogout //form/div /div h1OAuth 2.0 Login with Spring Security/h1 divYou are successfully logged in span stylefont-weight:bold th:text${userName}/spanvia the OAuth 2.0 Client span stylefont-weight:bold th:text${clientName}/span /div div /div diva href/userinfo th:href{/userinfo}Display User Info/a /div /body /html 在src/main/resources/userinfo.html上创建另一个模板以显示用户的属性。 !DOCTYPE html html xmlnshttp://www.w3.org/1999/xhtml xmlns:thhttp://www.thymeleaf.org headtitleSpring Security - OAuth 2.0 User Info/titlemeta charsetutf-8 / /head body div th:replaceindex::logout/div h1OAuth 2.0 User Info/h1 divspan stylefont-weight:boldUser Attributes:/spanulli th:eachuserAttribute : ${userAttributes}span stylefont-weight:bold th:text${userAttribute.key}/span: span th:text${userAttribute.value}/span/li/ul /div /body /html 现在当您登录时您将看到一个显示用户信息的链接。 单击链接您将看到从用户信息端点检索到的ID令牌的内容。 了解有关Spring Security和OIDC的更多信息 本文向您展示了如何使用OAuth 2.0和Spring Security 5实现登录。我还向您展示了如何使用OIDC检索用户信息。 本文开发的应用程序的源代码可以在GitHub上找到 。 这些资源提供了有关Okta和OIDC的其他信息 Okta开发人员文档及其OpenID Connect API 身份声明和令牌– OpenID Connect入门第1部分共3部分 行动中的OIDC – OpenID Connect入门第2部分共3部分 令牌中有什么 – OpenID Connect入门第3部分共3部分 使用Spring Security和Thymeleaf向您的应用程序添加基于角色的访问控制 如果您对此帖子有任何疑问请在下面发表评论。 您还可以使用okta标签将其发布到Stack Overflow或使用我们的开发人员论坛 。 在Twitter上关注OktaDev以获取更多精彩内容 “我喜欢编写身份验证和授权代码。” 〜从来没有Java开发人员。 厌倦了一次又一次地建立相同的登录屏幕 尝试使用Okta API进行托管身份验证授权和多因素身份验证。 Spring Security 5.0和OIDC入门最初于2017年12月18日发布在Okta开发人员博客上。 翻译自: https://www.javacodegeeks.com/2018/03/build-authentication-easy-way-spring-security-5-0-oidc.htmloidc auth2.0
http://www.pierceye.com/news/140721/

相关文章:

  • 网站运营做产品需要哪些知识开启wordpress多站点
  • flash网站源码 免费怎么可以自己制作网站
  • wordpress文章站主题如何删除自己建的网站
  • 徐州网站建设哪家好薇深圳找工作的网站
  • 局域网站点建设方案东莞企业营销型网站
  • 中国光大国际建设工程公司网站自己开店
  • 手机建站程序昆山设计公司
  • 网站泛解析中国新闻社是国企还是私企
  • dw做静态网站手机app制作视频教程
  • 惠州做网站公司网页游戏排行榜前十名歌
  • 会ps的如何做网站高等教材建筑电气久久建筑网
  • 甘肃住房城乡建设厅网站wordpress风格化页面
  • 起名网站建设免费找素材软件
  • 网站基本信息设置链接搜索
  • 广州海珠网站开发营销策划
  • 医院网站制作公司专门做spa的网站
  • 企业网页制作与网站设计网站必须天天更新吗
  • 乌苏市城乡建设局网站外贸网网站建设
  • html5网站开发实例书籍凡科建站代理
  • 与建设部网站网站注册登录页面设计
  • 企业网站推广计划免费最新如何建设网站教程视频
  • 17一起做网站普宁站好看个人网页模板
  • 民治营销网站专业网站建设价格最优
  • 免费的html网站做柜子喜欢上哪些网站看
  • 网站没备案怎么做加速现代装修风格三室两厅效果图
  • 互助平台网站建设网上商城怎么购物
  • 百度知道山东网站建设建设网站成本预算
  • 人人做免费网站网站建站是 什么
  • 以背景做网站视频为单位网站建设实施方案
  • 简洁大气企业网站模板西安个人做网站