Project

General

Profile

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.ComponentScan;
7
import org.springframework.context.annotation.Configuration;
8
import org.springframework.context.annotation.PropertySource;
9
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
10
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
11
import org.springframework.session.web.http.CookieSerializer;
12
import org.springframework.session.web.http.DefaultCookieSerializer;
13

    
14
/**
15
 * Created by stefanos on 14/6/2017.
16
 */
17

    
18
@Configuration
19
@EnableRedisHttpSession
20
//@PropertySource(value = { "classpath:eu/dnet/openaire/usermanagement/redis.properties"} )
21
public class Config {
22

    
23
    private static Logger logger = Logger.getLogger(Config.class);
24

    
25
    @Value("${redis.host:localhost}")
26
    private String host;
27

    
28
    @Value("${redis.port:6379}")
29
    private String port;
30

    
31
    @Value("${redis.password:#{null}}")
32
    private String password;
33

    
34
    @Bean
35
    public LettuceConnectionFactory connectionFactory() {
36
        logger.info(String.format("Redis connection listens to %s:%s",host,port));
37
        LettuceConnectionFactory factory = new LettuceConnectionFactory(host,Integer.parseInt(port));
38
        if(password != null) factory.setPassword(password);
39
        return factory;
40
    }
41

    
42
    @Bean
43
    public CookieSerializer cookieSerializer() {
44
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();
45
        serializer.setCookieName("SESSION"); // <1>
46
        serializer.setCookiePath("/"); // <2>
47
        serializer.setDomainNamePattern("");
48
        return serializer;
49
    }
50
}
    (1-1/1)