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.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

    
14
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
15

    
16

    
17
    private String frontEndURI;
18

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

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

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