1
|
package eu.dnetlib.openaire.usermanagement;
|
2
|
|
3
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
4
|
import org.springframework.security.core.context.SecurityContextHolder;
|
5
|
|
6
|
import javax.servlet.ServletException;
|
7
|
import javax.servlet.http.HttpServlet;
|
8
|
import javax.servlet.http.HttpServletRequest;
|
9
|
import javax.servlet.http.HttpServletResponse;
|
10
|
import java.io.IOException;
|
11
|
|
12
|
public class OverviewServlet extends HttpServlet {
|
13
|
|
14
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
15
|
throws ServletException, IOException {
|
16
|
|
17
|
boolean isAuthenticated = !SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()
|
18
|
.equals("anonymousUser");
|
19
|
|
20
|
if (isAuthenticated) {
|
21
|
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
22
|
StringBuilder name = new StringBuilder().append(authentication.getUserInfo().getGivenName().charAt(0));
|
23
|
name.append(authentication.getUserInfo().getFamilyName().charAt(0));
|
24
|
request.getSession().setAttribute("authenticated", isAuthenticated);
|
25
|
request.getSession().setAttribute("name", name.toString());
|
26
|
}
|
27
|
|
28
|
response.setContentType("text/html");
|
29
|
request.getRequestDispatcher("./overview.jsp").include(request, response);
|
30
|
}
|
31
|
}
|