自定义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 Cloud Hoxton 、Spring Boot 2.2、 OAuth2 的RBAC权限管理系统 基于数据驱动视图的理念封装 Ant Design Vue,即使没有 vue 的使用经验也能快速上手 提供 lambda 、stream api 、webflux 的生产实践 ...
spring-boot spring-security-oauth2 完整demo,可以使用微信的方式来获取token和查看资源,注意看代码中的备注
基于 Spring Cloud 2021 、Spring Boot 2.7、 OAuth2 的 RBAC 权限管理系统源码
系统说明:基于 Spring Cloud 2021 、Spring Boot 2.6、 OAuth2 的 RBAC 权限管理系统 基于数据驱动视图的理念封装 element-ui,即使没有 vue 的使用经验也能快速上手 提供对常见容器化支持 Docker、Kubernetes、...
1.理解OAuth 2.0http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html2.github第三方登录h
spring boot 整合OAuth2,基于数据库实现,另附有生成clientId,clientSecret的util类以及clientSecret加密util类。
Spring Boot 2 Oauth2资源和授权服务器 使用用户和客户端数据库(JPA,Hibernate,MySQL)的Spring Boot 2 OAuth2资源和授权服务器实现 入门 这些说明将为您提供在本地计算机上运行并运行的项目的副本,以进行开发...
spring boot oauth2 jwt 中文文档.docx
springboot2 + security+ oauth2 进行认证,并将令牌存储到数据库中。
Spring Boot Security OAuth2 实现支持JWT令牌的服务器源码
Spring Boot 2 OAuth2 JWT资源服务器链接到项目
基于 Spring Cloud Hoxton 、Spring Boot 2.2、 OAuth2 的RBAC权限管理系统;基于数据驱动视图的理念封装 Ant Design Vue,即使没有 vue 的使用经验也能快速上手;提供 lambda 、stream api 、webflux 的生产实践
Spring Boot 2 OAuth2 JWT授权服务器 链接到项目 关于如何使用Spring Boot 2 , JPA , Hibernate和MySQL使用JWT令牌设置OAuth2授权服务器的简单项目。 简而言之 所有和客户端都存储在数据库中。 可以具有许多与之相...
SpringCloud+SpringBoot+OAuth2+Spring Security+Redis实现的微服务统一认证授权
security-oauth2-auth-code|[基于spring boot实现oauth2授权模式](https://github.com/smltq/spring-boot-demo/blob/master/security-oauth2-auth-code/README.md) mybatis-multi-datasource|[mybatis、数据库集群...
一个springboot为框架的security oauth2应用例子,同时集成了swagger2的 restful API查看页面,druid数据源监控, mybatis自动生成和分页插件,远程资源服务器的认证和授权,也可以去github下载 ...
Spring Security5后基于Oauth2.1的Authorization Server 实现,采用spring-boot: 2.6.4 + spring: 5.3.16 + spring-security-oauth2-authorization-server: 0.2.3
资源包中有2个文件:FeignRequestInterceptor.java(拦截器)、OAuth2RestTemplateConfiguration.java(设置header),2个JAVA类,在spring boot框架下,客户端只需要正常引入了授权的JAR包,并把这2两个类放到可以...
使用spring oauth2框架做授权鉴定。想获取当前用户信息怎么办? 我们知道spring oauth2是基于spring security的实现的。 spring security可以通过SecurityContextHolder.getContext().getAuthentication()....
运行defender-oauth2-authorization模块下AuthorizationApplication类的main方法。 ###启动资源服务器 运行defender-oauth2-resource模块下ResourceApplication类的main方法。 ###启动客户端服务器 运行...