1
|
package eu.dnetlib.openaire.usermanagement.registry.beans;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
import org.springframework.beans.factory.annotation.Value;
|
5
|
import org.springframework.context.annotation.Bean;
|
6
|
import org.springframework.context.annotation.Configuration;
|
7
|
import org.springframework.context.annotation.PropertySource;
|
8
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
9
|
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
|
10
|
import org.springframework.session.web.http.CookieSerializer;
|
11
|
import org.springframework.session.web.http.DefaultCookieSerializer;
|
12
|
|
13
|
/**
|
14
|
* Created by stefanos on 14/6/2017.
|
15
|
*/
|
16
|
@PropertySource(value = { "classpath:eu/dnet/openaire/usermanagement/redis.properties", "classpath:eu/dnet/openaire/usermanagement/springContext-dnetOpenaireUsersService.properties"} )
|
17
|
@Configuration
|
18
|
@EnableRedisHttpSession
|
19
|
public class Config {
|
20
|
|
21
|
private static Logger logger = Logger.getLogger(Config.class);
|
22
|
|
23
|
@Value("${redis.host:localhost}")
|
24
|
private String host;
|
25
|
|
26
|
@Value("${redis.port:6379}")
|
27
|
private String port;
|
28
|
|
29
|
@Value("${redis.password:#{null}}")
|
30
|
private String password;
|
31
|
|
32
|
@Value("${webbapp.front.domain:.openaire.eu}")
|
33
|
private String domain;
|
34
|
|
35
|
@Bean
|
36
|
public LettuceConnectionFactory connectionFactory() {
|
37
|
logger.info(String.format("Redis connection listens to %s:%s ",host,port));
|
38
|
LettuceConnectionFactory factory = new LettuceConnectionFactory(host,Integer.parseInt(port));
|
39
|
if(password != null) factory.setPassword(password);
|
40
|
return factory;
|
41
|
}
|
42
|
|
43
|
@Bean
|
44
|
public CookieSerializer cookieSerializer() {
|
45
|
logger.info("Cookie Serializer: Domain is "+domain);
|
46
|
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
|
47
|
serializer.setCookieName("openAIRESession"); // <1>
|
48
|
serializer.setCookiePath("/"); // <2>
|
49
|
// serializer.setDomainNamePattern(""); //with value "" set's the domain of the service e.g scoobydoo.di.uoa.gr
|
50
|
serializer.setDomainName(domain);
|
51
|
return serializer;
|
52
|
}
|
53
|
}
|