Project

General

Profile

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

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

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

    
14

    
15
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
16

    
17

    
18
    private String frontEndURI;
19

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

    
31
    public String getFrontEndURI() {
32
        return frontEndURI;
33
    }
34

    
35
    public void setFrontEndURI(String frontEndURI) {
36
        this.frontEndURI = frontEndURI;
37
    }
38
}
(3-3/5)