|
37 | 37 | import org.springframework.security.core.userdetails.UsernameNotFoundException; |
38 | 38 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
39 | 39 | import org.springframework.security.jwt.crypto.sign.MacSigner; |
| 40 | +import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; |
40 | 41 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; |
41 | 42 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; |
42 | 43 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; |
43 | 44 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; |
44 | 45 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; |
45 | 46 | import org.springframework.security.oauth2.provider.AuthorizationRequest; |
| 47 | +import org.springframework.security.oauth2.provider.ClientDetails; |
46 | 48 | import org.springframework.security.oauth2.provider.ClientDetailsService; |
47 | 49 | import org.springframework.security.oauth2.provider.OAuth2RequestFactory; |
48 | 50 | import org.springframework.security.oauth2.provider.approval.DefaultUserApprovalHandler; |
|
52 | 54 | import org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService; |
53 | 55 | import org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint; |
54 | 56 | import org.springframework.security.oauth2.provider.endpoint.CheckTokenEndpoint; |
| 57 | +import org.springframework.security.oauth2.provider.endpoint.RedirectResolver; |
55 | 58 | import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint; |
56 | 59 | import org.springframework.security.oauth2.provider.error.DefaultWebResponseExceptionTranslator; |
57 | 60 | import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; |
@@ -107,7 +110,9 @@ public static List<Object[]> parameters() { |
107 | 110 | new Object[] { null, new Class<?>[] { AuthorizationServerAllowsOnlyPost.class } }, |
108 | 111 | new Object[] { BeanCreationException.class, new Class<?>[] { AuthorizationServerTypes.class } }, |
109 | 112 | new Object[] { null, new Class<?>[] { AuthorizationServerCustomGranter.class } }, |
110 | | - new Object[] { null, new Class<?>[] { AuthorizationServerSslEnabled.class } } |
| 113 | + new Object[] { null, new Class<?>[] { AuthorizationServerSslEnabled.class } }, |
| 114 | + new Object[] { null, new Class<?>[] { AuthorizationServerCustomRedirectResolver.class } }, |
| 115 | + new Object[] { null, new Class<?>[] { AuthorizationServerDefaultRedirectResolver.class } } |
111 | 116 | // @formatter:on |
112 | 117 | ); |
113 | 118 | } |
@@ -545,6 +550,51 @@ public void run() { |
545 | 550 |
|
546 | 551 | } |
547 | 552 |
|
| 553 | + @EnableWebSecurity |
| 554 | + @EnableAuthorizationServer |
| 555 | + protected static class AuthorizationServerCustomRedirectResolver extends AuthorizationServerConfigurerAdapter |
| 556 | + implements Runnable { |
| 557 | + |
| 558 | + @Autowired |
| 559 | + private ApplicationContext context; |
| 560 | + |
| 561 | + @Override |
| 562 | + public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { |
| 563 | + endpoints.redirectResolver(new CustomRedirectResolver()); |
| 564 | + } |
| 565 | + |
| 566 | + @Override |
| 567 | + public void run() { |
| 568 | + RedirectResolver resolver = (RedirectResolver) ReflectionTestUtils.getField(context.getBean(AuthorizationEndpoint.class), "redirectResolver"); |
| 569 | + |
| 570 | + assertNotNull(resolver); |
| 571 | + assertTrue(resolver instanceof CustomRedirectResolver); |
| 572 | + } |
| 573 | + |
| 574 | + static class CustomRedirectResolver implements RedirectResolver { |
| 575 | + @Override |
| 576 | + public String resolveRedirect(final String requestedRedirect, final ClientDetails client) throws OAuth2Exception { |
| 577 | + return "go/here"; |
| 578 | + } |
| 579 | + } |
| 580 | + } |
| 581 | + |
| 582 | + @EnableWebSecurity |
| 583 | + @EnableAuthorizationServer |
| 584 | + protected static class AuthorizationServerDefaultRedirectResolver extends AuthorizationServerConfigurerAdapter |
| 585 | + implements Runnable { |
| 586 | + |
| 587 | + @Autowired |
| 588 | + private ApplicationContext context; |
| 589 | + |
| 590 | + @Override |
| 591 | + public void run() { |
| 592 | + assertNotNull( |
| 593 | + ReflectionTestUtils.getField(context.getBean(AuthorizationEndpoint.class), "redirectResolver")); |
| 594 | + } |
| 595 | + |
| 596 | + } |
| 597 | + |
548 | 598 | @Configuration |
549 | 599 | @EnableWebMvcSecurity |
550 | 600 | @EnableAuthorizationServer |
|
0 commit comments