Project

General

Profile

1
package eu.dnetlib.repo.manager.server.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

    
16
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
17

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

    
21
    private String frontEndURI;
22

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

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

    
31
        LOGGER.debug(authentication.getName());
32

    
33
        OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
34
        Cookie sessionCookie = new Cookie("currentUser", authOIDC.getSub());
35

    
36
        int expireSec = -1;
37
        sessionCookie.setMaxAge(expireSec);
38
        sessionCookie.setPath("/");
39
        response.addCookie(sessionCookie);
40
        response.sendRedirect(frontEndURI);
41
    }
42

    
43
    public String getFrontEndURI() {
44
        return frontEndURI;
45
    }
46

    
47
    public void setFrontEndURI(String frontEndURI) {
48
        this.frontEndURI = frontEndURI;
49
    }
50

    
51
}
(3-3/4)