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
        LOGGER.info(request);
31
        LOGGER.info(response);
32

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

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

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

    
(3-3/5)