Commit bdcc0ead authored by Ashutosh Shimpi's avatar Ashutosh Shimpi
Browse files

Code refactored

parent 3f148d6d
Pipeline #124294 passed with stages
in 19 minutes and 9 seconds
......@@ -164,20 +164,20 @@ public class DataEdgeConfig {
final CachingMultipleRemoteTokenService remoteTokenServices = new CachingMultipleRemoteTokenService();
// EGA AAI
CachingRemoteTokenService b = new CachingRemoteTokenService();
b.setCheckTokenEndpointUrl(checkTokenUrl);
b.setClientId(clientId);
b.setClientSecret(clientSecret);
b.setAccessTokenConverter(accessTokenConverter);
remoteTokenServices.addRemoteTokenService(b);
CachingRemoteTokenService egaAAICachingRemoteTokenService = new CachingRemoteTokenService();
egaAAICachingRemoteTokenService.setCheckTokenEndpointUrl(checkTokenUrl);
egaAAICachingRemoteTokenService.setClientId(clientId);
egaAAICachingRemoteTokenService.setClientSecret(clientSecret);
egaAAICachingRemoteTokenService.setAccessTokenConverter(accessTokenConverter);
remoteTokenServices.addRemoteTokenService(egaAAICachingRemoteTokenService);
// ELIXIR AAI
CachingRemoteTokenService a = new CachingRemoteTokenService();
a.setCheckTokenEndpointUrl(zuulCheckTokenUrl);
a.setClientId(zuulClientId);
a.setClientSecret(zuulClientSecret);
a.setAccessTokenConverter(accessTokenConverter);
remoteTokenServices.addRemoteTokenService(a);
CachingRemoteTokenService elixirAAICachingRemoteTokenService = new CachingRemoteTokenService();
elixirAAICachingRemoteTokenService.setCheckTokenEndpointUrl(zuulCheckTokenUrl);
elixirAAICachingRemoteTokenService.setClientId(zuulClientId);
elixirAAICachingRemoteTokenService.setClientSecret(zuulClientSecret);
elixirAAICachingRemoteTokenService.setAccessTokenConverter(accessTokenConverter);
remoteTokenServices.addRemoteTokenService(elixirAAICachingRemoteTokenService);
return remoteTokenServices;
}
......
......@@ -17,6 +17,10 @@
*/
package eu.elixir.ega.ebi.htsget.config;
import eu.elixir.ega.ebi.commons.config.CachingMultipleRemoteTokenService;
import eu.elixir.ega.ebi.commons.config.CachingRemoteTokenService;
import eu.elixir.ega.ebi.commons.config.MyAccessTokenConverter;
import eu.elixir.ega.ebi.commons.config.MyUserAuthenticationConverter;
import eu.elixir.ega.ebi.commons.shared.dto.MyExternalConfig;
import eu.elixir.ega.ebi.commons.shared.service.FileDatasetService;
import eu.elixir.ega.ebi.commons.shared.service.FileInfoService;
......@@ -35,8 +39,17 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.security.oauth2.provider.token.AccessTokenConverter;
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
......@@ -95,4 +108,65 @@ public class HtsGetConfiguration {
public UserDetailsService initUserDetailsServiceImpl(final RestTemplate restTemplate) {
return new UserDetailsServiceImpl(restTemplate);
}
// This is a bit of a Hack! MitreID doesn't return 'user_name' but 'user_id', The
// customized User Authentication Converter simply changes the field name for extraction
@Bean
public AccessTokenConverter accessTokenConverter(final JWTService jwtService,
final Ga4ghService ga4ghService,
final FileDatasetService fileDatasetService,
final UserDetailsService userDetailsService) {
return new MyAccessTokenConverter(
jwtService,
ga4ghService,
fileDatasetService,
new MyUserAuthenticationConverter(),
userDetailsService
);
}
@Profile("enable-aai")
@Primary
@Bean
public RemoteTokenServices remoteTokenServices(HttpServletRequest request,
final @Value("${auth.server.url}") String checkTokenUrl,
final @Value("${auth.server.clientId}") String clientId,
final @Value("${auth.server.clientsecret}") String clientSecret,
final @Value("${auth.zuul.server.url}") String zuulCheckTokenUrl,
final @Value("${auth.zuul.server.clientId}") String zuulClientId,
final @Value("${auth.zuul.server.clientsecret}") String zuulClientSecret,
final AccessTokenConverter accessTokenConverter) {
final CachingMultipleRemoteTokenService remoteTokenServices = new CachingMultipleRemoteTokenService();
// EGA AAI
CachingRemoteTokenService egaAAICachingRemoteTokenService = new CachingRemoteTokenService();
egaAAICachingRemoteTokenService.setCheckTokenEndpointUrl(checkTokenUrl);
egaAAICachingRemoteTokenService.setClientId(clientId);
egaAAICachingRemoteTokenService.setClientSecret(clientSecret);
egaAAICachingRemoteTokenService.setAccessTokenConverter(accessTokenConverter);
remoteTokenServices.addRemoteTokenService(egaAAICachingRemoteTokenService);
// ELIXIR AAI
CachingRemoteTokenService elixirAAICachingRemoteTokenService = new CachingRemoteTokenService();
elixirAAICachingRemoteTokenService.setCheckTokenEndpointUrl(zuulCheckTokenUrl);
elixirAAICachingRemoteTokenService.setClientId(zuulClientId);
elixirAAICachingRemoteTokenService.setClientSecret(zuulClientSecret);
remoteTokenServices.addRemoteTokenService(elixirAAICachingRemoteTokenService);
return remoteTokenServices;
}
@Bean
@Order(0)
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}
......@@ -16,20 +16,8 @@
package eu.elixir.ega.ebi.htsget.config;
import eu.elixir.ega.ebi.commons.config.CachingMultipleRemoteTokenService;
import eu.elixir.ega.ebi.commons.config.CachingRemoteTokenService;
import eu.elixir.ega.ebi.commons.config.MyAccessTokenConverter;
import eu.elixir.ega.ebi.commons.config.MyUserAuthenticationConverter;
import eu.elixir.ega.ebi.commons.shared.service.FileDatasetService;
import eu.elixir.ega.ebi.commons.shared.service.Ga4ghService;
import eu.elixir.ega.ebi.commons.shared.service.JWTService;
import eu.elixir.ega.ebi.commons.shared.service.UserDetailsService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
......@@ -38,12 +26,7 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.E
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor;
import org.springframework.security.oauth2.provider.authentication.TokenExtractor;
import org.springframework.security.oauth2.provider.token.AccessTokenConverter;
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
......@@ -90,68 +73,5 @@ public class OAuth2ResourceConfig extends ResourceServerConfigurerAdapter {
.and()
.csrf().disable();
}
// This is a bit of a Hack! MitreID doesn't return 'user_name' but 'user_id', The
// customized User Authentication Converter simply changes the field name for extraction
@Bean
public AccessTokenConverter accessTokenConverter(final JWTService jwtService,
final Ga4ghService ga4ghService,
final FileDatasetService fileDatasetService,
final UserDetailsService userDetailsService) {
return new MyAccessTokenConverter(
jwtService,
ga4ghService,
fileDatasetService,
new MyUserAuthenticationConverter(),
userDetailsService
);
}
@Profile("enable-aai")
@Primary
@Bean
public RemoteTokenServices remoteTokenServices(HttpServletRequest request,
//public RemoteTokenServices combinedTokenServices(HttpServletRequest request,
final @Value("${auth.server.url}") String checkTokenUrl,
final @Value("${auth.server.clientId}") String clientId,
final @Value("${auth.server.clientsecret}") String clientSecret,
final @Value("${auth.zuul.server.url}") String zuulCheckTokenUrl,
final @Value("${auth.zuul.server.clientId}") String zuulClientId,
final @Value("${auth.zuul.server.clientsecret}") String zuulClientSecret,
final AccessTokenConverter accessTokenConverter) {
final CachingMultipleRemoteTokenService remoteTokenServices = new CachingMultipleRemoteTokenService();
// EGA AAI
CachingRemoteTokenService b = new CachingRemoteTokenService();
b.setCheckTokenEndpointUrl(checkTokenUrl);
b.setClientId(clientId);
b.setClientSecret(clientSecret);
b.setAccessTokenConverter(accessTokenConverter);
remoteTokenServices.addRemoteTokenService(b);
// ELIXIR AAI
CachingRemoteTokenService a = new CachingRemoteTokenService();
a.setCheckTokenEndpointUrl(zuulCheckTokenUrl);
a.setClientId(zuulClientId);
a.setClientSecret(zuulClientSecret);
remoteTokenServices.addRemoteTokenService(a);
return remoteTokenServices;
}
@Bean
@Order(0)
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment