Project

General

Profile

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

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

    
7
import javax.servlet.ServletException;
8
import javax.servlet.http.Cookie;
9
import javax.servlet.http.HttpServletRequest;
10
import javax.servlet.http.HttpServletResponse;
11
import java.io.IOException;
12

    
13
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
14

    
15
    private String frontEndURI;
16

    
17
    @Override
18
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
19
        OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
20
        Cookie sessionCookie = new Cookie("currentUser", authOIDC.getSub());
21
        int expireSec = -1;
22
        sessionCookie.setMaxAge(expireSec);
23
        sessionCookie.setPath("/");
24
        response.addCookie(sessionCookie);
25
        response.sendRedirect(frontEndURI);
26
    }
27

    
28
    public String getFrontEndURI() {
29
        return frontEndURI;
30
    }
31

    
32
    public void setFrontEndURI(String frontEndURI) {
33
        this.frontEndURI = frontEndURI;
34
    }
35
}
36

    
(3-3/4)