add missing bean

This commit is contained in:
Loredana 2020-10-26 16:28:28 +02:00
parent 32ae02a1d0
commit d6c22e1c93
1 changed files with 9 additions and 3 deletions

View File

@ -12,6 +12,8 @@ import org.springframework.core.env.Environment;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.oauth2.client.CommonOAuth2Provider; import org.springframework.security.config.oauth2.client.CommonOAuth2Provider;
import org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient;
import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest;
@ -58,11 +60,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
return accessTokenResponseClient; return accessTokenResponseClient;
} }
// additional configuration for non-Spring Boot projects // additional configuration for non-Spring Boot projects
private static List<String> clients = Arrays.asList("google", "facebook"); private static List<String> clients = Arrays.asList("google", "facebook");
//@Bean // @Bean
public ClientRegistrationRepository clientRegistrationRepository() { public ClientRegistrationRepository clientRegistrationRepository() {
List<ClientRegistration> registrations = clients.stream() List<ClientRegistration> registrations = clients.stream()
.map(c -> getRegistration(c)) .map(c -> getRegistration(c))
@ -72,6 +73,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
return new InMemoryClientRegistrationRepository(registrations); return new InMemoryClientRegistrationRepository(registrations);
} }
// @Bean
public OAuth2AuthorizedClientService authorizedClientService() {
return new InMemoryOAuth2AuthorizedClientService(clientRegistrationRepository());
}
private static String CLIENT_PROPERTY_KEY = "spring.security.oauth2.client.registration."; private static String CLIENT_PROPERTY_KEY = "spring.security.oauth2.client.registration.";
@Autowired @Autowired