自定义WhitelabelApprovalEndpoint的/oauth/confirm_access页面内容有两种方法:
-
通过在@Controller注解的类下再添加@SessionAttributes("authorizationRequest")注解.
import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.SessionAttributes; @Controller @SessionAttributes("authorizationRequest") public class OAuth2ApprovalController { @RequestMapping("/oauth/confirm_access") public String getAccessConfirmation(Map<String, Object> model, HttpServletRequest request) throws Exception { return "oauth/oauth_approval"; } }
需要注意的地方是@Controller下必须有@SessionAttributes注解,以及相同的@RequestMapping("/oauth/confirm_access")地址。 -
另一种是直接在AuthorizationServerEndpointsConfigurer类下通过pathMapping(default,new)来映射新的地址
@Configuration @EnableAuthorizationServer public class OAuth2Config extends AuthorizationServerConfigurerAdapter { @Resource(name = "mongoClientDetailsService") protected ClientDetailsService clientDetailsService; @Resource(name = "mongoAuthorizationCodeServices") protected AuthorizationCodeServices authorizationCodeServices; @Resource protected AuthenticationManager authenticationManager; protected OAuth2RequestFactory requestFactory; @Resource(name = "oAuth2AccessDeniedHandler") AccessDeniedHandler accessDeniedHandler; @Bean(name = "tokenStore") public TokenStore tokenStore() { return new MongoTokenStore(); } @Bean public ApprovalStore approvalStore() { TokenApprovalStore approvalStore = new TokenApprovalStore(); approvalStore.setTokenStore(tokenStore()); return approvalStore; } // AuthenticationSuccessHandler authenticationSuccessHandler() { // return new OAuth2AuthenticationSuccessHandler(); // } // AuthenticationFailureHandler authenticationFailureHandler() { // return new OAuth2AuthenticationFailureHandler(); // } @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clients.withClientDetails(clientDetailsService); } @Override public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { // 允许表单鉴权 oauthServer.allowFormAuthenticationForClients().accessDeniedHandler(accessDeniedHandler); } private AuthorizationServerTokenServices tokenServices() { CusTokenServices tokenServices = new CusTokenServices(); tokenServices.setTokenStore(tokenStore()); tokenServices.setSupportRefreshToken(true); tokenServices.setClientDetailsService(clientDetailsService); return tokenServices; } private OAuth2RequestFactory requestFactory() { if (requestFactory != null) { return requestFactory; } requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService); return requestFactory; } private TokenGranter tokenGranter() throws Exception { List<TokenGranter> tokenGranters = new ArrayList<TokenGranter>(); tokenGranters.add(new AuthorizationCodeTokenGranter(tokenServices(), authorizationCodeServices, clientDetailsService, requestFactory())); tokenGranters .add(new RefreshTokenGranter(tokenServices(), clientDetailsService, requestFactory())); tokenGranters .add(new ImplicitTokenGranter(tokenServices(), clientDetailsService, requestFactory())); tokenGranters.add( new ClientCredentialsTokenGranter(tokenServices(), clientDetailsService, requestFactory())); tokenGranters.add(new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices(), clientDetailsService, requestFactory())); TokenGranter tokenGranter = new CompositeTokenGranter(tokenGranters); return tokenGranter; } @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { endpoints.approvalStore(approvalStore()).authorizationCodeServices(authorizationCodeServices) .tokenStore(tokenStore()).tokenGranter(tokenGranter()); endpoints.pathMapping("/oauth/confirm_access", "/extenal/oauth/confirm_access"); } }
再添加一个普通的@Controller类即可@Controller //@SessionAttributes("authorizationRequest") public class OAuth2ApprovalController { @RequestMapping("/oauth/confirm_access") public String getAccessConfirmation(Map<String, Object> model, HttpServletRequest request) throws Exception { return "oauth/oauth_approval"; } }
此种方式不需要再配置@SessionAttributes注解了
自定义了WhitelabelApprovalEndpoint后,那么WhitelabelErrorEndpoint就不多说了。
.
相关推荐
《Spring Boot、Spring Security与OAuth2的完整示例解析》 在现代Web开发中,安全性是不可忽视的重要一环。Spring Boot、Spring Security和OAuth2是Java生态系统中用于构建安全Web应用的三大利器。本篇文章将围绕...
基于 Spring Cloud Hoxton 、Spring Boot 2.2、 OAuth2 的RBAC权限管理系统 基于数据驱动视图的理念封装 Ant Design Vue,即使没有 vue 的使用经验也能快速上手 提供 lambda 、stream api 、webflux 的生产实践 ...
本篇文章将探讨如何利用Spring Boot、Spring Security以及OAuth2来实现第三方登录功能,特别是在集成GitHub登录时的实现细节。 OAuth 2.0是一种授权框架,它允许第三方应用在用户授权的情况下访问其存储在另一服务...
基于 Spring Cloud 2021 、Spring Boot 2.7、 OAuth2 的 RBAC 权限管理系统源码
OAuth2则是一种授权框架,用于保护API资源的安全,允许第三方应用在用户授权下访问资源服务器的数据。本篇文章将深入探讨如何在Spring Boot 2项目中结合Security和OAuth2实现安全认证,并将令牌存储到数据库中。 ...
系统说明:基于 Spring Cloud 2021 、Spring Boot 2.6、 OAuth2 的 RBAC 权限管理系统 基于数据驱动视图的理念封装 element-ui,即使没有 vue 的使用经验也能快速上手 提供对常见容器化支持 Docker、Kubernetes、...
OAuth2 授权框架与 Spring Boot 集成指南 OAuth2 授权框架是一种协议,允许用户授权第三方网站或应用程序访问用户受保护的资源,而不必披露其长期凭据甚至身份。OAuth 引入了一个授权层,将客户端角色与资源所有者...
Spring Boot Security OAuth2 是一个广泛使用的框架,用于构建安全、授权的API服务。本项目重点在于实现一个支持JWT(JSON Web Token)令牌的授权服务器,这将使我们能够为客户端提供安全的认证和授权。 首先,让...
Spring Boot、Spring Security、JWT 和 OAuth2 是现代Web应用程序开发中的关键组件,它们共同构建了一个安全、高效的身份验证和授权框架。在这个项目中,我们看到一个整合了这些技术的实战应用,下面将详细阐述这些...
spring boot 整合OAuth2,基于数据库实现,另附有生成clientId,clientSecret的util类以及clientSecret加密util类。
2. **主应用类**(如 Oauth2serviceApplication):启动 Spring Boot 应用。 3. **OAuth2Controller**:处理授权请求,包括重定向至登录页面(authorize 方法)和用户登录验证(login 方法)。 4. **...
Spring Boot 2 Oauth2资源和授权服务器 使用用户和客户端数据库(JPA,Hibernate,MySQL)的Spring Boot 2 OAuth2资源和授权服务器实现 入门 这些说明将为您提供在本地计算机上运行并运行的项目的副本,以进行开发...
本篇文章将深入探讨如何使用Spring Boot 2实现OAuth2 JWT资源服务器,通过在令牌和自定义主体中添加自定义详细信息,提升系统的安全性与灵活性。 OAuth2是一种授权框架,它允许第三方应用以用户代理的身份访问特定...
本教程将探讨如何使用Spring Boot结合Spring Security、OAuth2和JWT(JSON Web Token)来搭建一个认证服务器、API网关以及微服务之间的权限认证和授权机制。 首先,Spring Security是Spring框架的一个模块,专门...
资源包中有2个文件:FeignRequestInterceptor.java(拦截器)、OAuth2RestTemplateConfiguration.java(设置header),2个JAVA类,在spring boot框架下,客户端只需要正常引入了授权的JAR包,并把这2两个类放到可以...
基于 Spring Cloud Hoxton 、Spring Boot 2.2、 OAuth2 的RBAC权限管理系统;基于数据驱动视图的理念封装 Ant Design Vue,即使没有 vue 的使用经验也能快速上手;提供 lambda 、stream api 、webflux 的生产实践
基于 Spring Cloud 2021 、Spring Boot 2.7、 OAuth2 的 RBAC 权限管理系统;基于数据驱动视图的理念封装 element-plus,即使没有 vue 的使用经验也能快速上手;提供对常见容器化支持 Docker、Kubernetes、Rancher2 ...
Spring Boot OAuth2是一个基于Spring Boot实现的OAuth2认证框架,用于构建安全的Web应用程序和服务。OAuth2是一个授权框架,允许第三方应用在用户许可的情况下访问其存储在另一应用上的私有资源,而无需共享用户凭证...
Spring Boot 2 OAuth2 JWT授权服务器 链接到项目 关于如何使用Spring Boot 2 , JPA , Hibernate和MySQL使用JWT令牌设置OAuth2授权服务器的简单项目。 简而言之 所有和客户端都存储在数据库中。 可以具有许多与之相...
2. OAuth2集成:支持OAuth2认证服务器和资源服务器的实现。 七、Spring Boot测试 1. @SpringBootTest:用于集成测试,加载整个Spring Boot应用上下文。 2. @WebMvcTest:针对Web层进行单元测试,只加载Web相关组件...