2019-12-18 12:09:03 +01:00
|
|
|
package eu.dnetlib.repo.manager.config;
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.context.annotation.*;
|
|
|
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
|
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
|
|
|
|
import org.springframework.session.web.http.CookieSerializer;
|
|
|
|
import org.springframework.session.web.http.DefaultCookieSerializer;
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@EnableRedisHttpSession
|
|
|
|
@ComponentScan(basePackages = {
|
|
|
|
"org.eurocris.openaire.cris.validator.service",
|
|
|
|
"eu.dnetlib.repo.manager.*"})
|
|
|
|
public class RedisConfiguration {
|
|
|
|
|
|
|
|
private static Logger LOGGER = Logger.getLogger(RedisConfiguration.class);
|
|
|
|
|
2021-10-26 13:46:08 +02:00
|
|
|
@Value("${services.provide.redis.host}")
|
2019-12-18 12:09:03 +01:00
|
|
|
private String host;
|
|
|
|
|
2021-10-26 13:46:08 +02:00
|
|
|
@Value("${services.provide.redis.port:6379}")
|
2019-12-18 12:09:03 +01:00
|
|
|
private String port;
|
|
|
|
|
2021-10-26 13:46:08 +02:00
|
|
|
@Value("${services.provide.redis.password}")
|
2019-12-18 12:09:03 +01:00
|
|
|
private String password;
|
|
|
|
|
2021-10-26 13:46:08 +02:00
|
|
|
@Value("${services.provide.aai.oidc.domain}")
|
|
|
|
private String domain;
|
2019-12-18 12:09:03 +01:00
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
private void init(){
|
|
|
|
LOGGER.info(String.format("Redis : %s Port : %s Password : %s",host,port,password));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
public JedisConnectionFactory connectionFactory() {
|
|
|
|
LOGGER.info(String.format("Redis : %s Port : %s Password : %s",host,port,password));
|
|
|
|
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
|
|
|
|
jedisConnectionFactory.setHostName(host);
|
|
|
|
jedisConnectionFactory.setPort(Integer.parseInt(port));
|
|
|
|
jedisConnectionFactory.setUsePool(true);
|
|
|
|
if(password != null) jedisConnectionFactory.setPassword(password);
|
|
|
|
return jedisConnectionFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
public CookieSerializer cookieSerializer() {
|
|
|
|
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
|
|
|
|
serializer.setCookieName("openAIRESession");
|
|
|
|
serializer.setCookiePath("/");
|
2021-10-26 13:46:08 +02:00
|
|
|
serializer.setDomainName(domain);
|
2019-12-18 12:09:03 +01:00
|
|
|
LOGGER.info("Serializer : " + serializer);
|
|
|
|
return serializer;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
public RestTemplate restTemplate() {
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
|
|
|
HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
|
httpHeaders.set("Content-Type", "application/json");
|
|
|
|
return restTemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|