Project

General

Profile

1
package eu.dnetlib.repo.manager.service.config;
2

    
3
import org.apache.log4j.Logger;
4
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
5
import org.springframework.security.core.Authentication;
6
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
7

    
8
import javax.annotation.PostConstruct;
9
import javax.servlet.ServletException;
10
import javax.servlet.http.Cookie;
11
import javax.servlet.http.HttpServletRequest;
12
import javax.servlet.http.HttpServletResponse;
13
import java.io.IOException;
14

    
15
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
16

    
17
    private String frontEndURI;
18

    
19
    private static final Logger LOGGER = Logger
20
            .getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class);
21

    
22
    @PostConstruct
23
    public void init(){
24
        LOGGER.debug(frontEndURI);
25
    }
26

    
27
    @Override
28
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
29

    
30
        OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
31
        Cookie sessionCookie = new Cookie("currentUser", authOIDC.getSub());
32
        int expireSec = -1;
33
        sessionCookie.setMaxAge(expireSec);
34
        sessionCookie.setPath("/");
35
//        sessionCookie.setDomain();
36
        response.addCookie(sessionCookie);
37
        response.sendRedirect(frontEndURI);
38
    }
39

    
40
    public String getFrontEndURI() {
41
        return frontEndURI;
42
    }
43

    
44
    public void setFrontEndURI(String frontEndURI) {
45
        this.frontEndURI = frontEndURI;
46
    }
47
}
48

    
(3-3/6)