Fix Deposit Configuration's Authentication system
This commit is contained in:
parent
4e08d9f073
commit
3c799063cc
|
@ -2,33 +2,35 @@ package eu.eudat.configurations;
|
|||
|
||||
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
||||
import eu.eudat.repository.DepositRepository;
|
||||
import gr.cite.commons.web.oidc.apikey.ApiKeyCacheService;
|
||||
import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyExchangeFilterFunction;
|
||||
import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyWebfluxModel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.oauth2.client.AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager;
|
||||
import org.springframework.security.oauth2.client.InMemoryReactiveOAuth2AuthorizedClientService;
|
||||
import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizedClientService;
|
||||
import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
||||
import org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository;
|
||||
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
|
||||
import org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction;
|
||||
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({DepositProperties.class})
|
||||
public class DepositConfiguration {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DepositConfiguration.class);
|
||||
|
||||
private final DepositProperties properties;
|
||||
|
||||
private final ApiKeyCacheService apiKeyCacheService;
|
||||
|
||||
@Autowired
|
||||
public DepositConfiguration(DepositProperties properties) {
|
||||
public DepositConfiguration(DepositProperties properties, ApiKeyCacheService apiKeyCacheService) {
|
||||
this.properties = properties;
|
||||
this.apiKeyCacheService = apiKeyCacheService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -36,19 +38,12 @@ public class DepositConfiguration {
|
|||
public List<RepositoryDeposit> depositClients() {
|
||||
List<RepositoryDeposit> clients = new ArrayList<>();
|
||||
for (DepositProperties.DepositSource source: properties.getSources()) {
|
||||
// ClientRegistration clientRegistration = ClientRegistration
|
||||
// .withRegistrationId(source.getClientId())
|
||||
// .clientId(source.getClientId())
|
||||
// .clientSecret(source.getClientSecret())
|
||||
// .scope(source.getScope())
|
||||
// .issuerUri(source.getIssuerUrl())
|
||||
// .authorizationGrantType(AuthorizationGrantType.JWT_BEARER)
|
||||
// .build();
|
||||
// ReactiveClientRegistrationRepository clientRegistrationRepository = new InMemoryReactiveClientRegistrationRepository(clientRegistration);
|
||||
// ReactiveOAuth2AuthorizedClientService clientService = new InMemoryReactiveOAuth2AuthorizedClientService(clientRegistrationRepository);
|
||||
// AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager authorizedClientManager = new AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(clientRegistrationRepository, clientService);
|
||||
// ServerOAuth2AuthorizedClientExchangeFilterFunction oauth = new ServerOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager);
|
||||
// clients.add(new DepositRepository(WebClient.builder().baseUrl(source.getUrl() + "/api/deposit").filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(oauth)).build()));
|
||||
|
||||
String host = URI.create(source.getUrl()).getHost();
|
||||
ApiKeyWebfluxModel apiKeyWebfluxModel = new ApiKeyWebfluxModel(host + "_" + source.getClientId(), source.getIssuerUrl(), source.getClientId(), source.getClientSecret(), source.getScope());
|
||||
ApiKeyExchangeFilterFunction apiKeyExchangeFilterFunction = new ApiKeyExchangeFilterFunction(this.apiKeyCacheService, apiKeyWebfluxModel);
|
||||
|
||||
clients.add(new DepositRepository(WebClient.builder().baseUrl(source.getUrl() + "/api/deposit").filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(apiKeyExchangeFilterFunction)).build()));
|
||||
}
|
||||
return clients;
|
||||
}
|
||||
|
|
|
@ -309,7 +309,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>oidc-authn</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
|
|
Loading…
Reference in New Issue