Project

General

Profile

1
package eu.dnetlib.openaire.usermanagement;
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

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

    
13
public class OverviewServlet extends HttpServlet {
14

    
15
    public void doGet(HttpServletRequest request, HttpServletResponse response)
16
            throws ServletException, IOException {
17

    
18
        boolean isAuthenticated = !SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()
19
                .equals("anonymousUser");
20

    
21
        if (isAuthenticated) {
22
            OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
23

    
24
            StringBuilder name = new StringBuilder().append(authentication.getUserInfo().getGivenName().charAt(0));
25
            name.append(authentication.getUserInfo().getFamilyName().charAt(0));
26
            request.getSession().setAttribute("authenticated", isAuthenticated);
27
            request.getSession().setAttribute("name", name.toString());
28
        }
29

    
30
        response.setContentType("text/html");
31
        request.getRequestDispatcher("./overview.jsp").include(request, response);
32
    }
33
}
(5-5/18)