1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package edu.internet2.middleware.shibboleth.idp.authn.provider;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22
23 import org.opensaml.saml2.core.AuthnContext;
24 import org.opensaml.xml.util.DatatypeHelper;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 import edu.internet2.middleware.shibboleth.idp.authn.AuthenticationEngine;
29 import edu.internet2.middleware.shibboleth.idp.authn.LoginHandler;
30 import edu.internet2.middleware.shibboleth.idp.session.Session;
31
32
33 public class PreviousSessionLoginHandler extends AbstractLoginHandler {
34
35
36 private final Logger log = LoggerFactory.getLogger(PreviousSessionLoginHandler.class);
37
38
39 private String servletPath;
40
41
42 private boolean reportPreviousSessionAuthnMethod;
43
44
45 public PreviousSessionLoginHandler() {
46 super();
47 servletPath = null;
48 setSupportsPassive(true);
49 setSupportsForceAuthentication(false);
50 }
51
52
53
54
55
56
57
58
59 public String getServletPath() {
60 return servletPath;
61 }
62
63
64
65
66
67
68
69
70 public void setServletPath(String path) {
71 servletPath = DatatypeHelper.safeTrimOrNullString(path);
72 }
73
74
75
76
77
78
79 public boolean reportPreviousSessionAuthnMethod() {
80 return reportPreviousSessionAuthnMethod;
81 }
82
83
84
85
86
87
88 public void setReportPreviousSessionAuthnMethod(boolean report) {
89 reportPreviousSessionAuthnMethod = report;
90 }
91
92
93 public boolean supportsPassive() {
94 if (servletPath == null) {
95 return true;
96 }
97
98 return super.supportsPassive();
99 }
100
101
102 public void login(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
103 if (reportPreviousSessionAuthnMethod) {
104 httpRequest.setAttribute(LoginHandler.AUTHENTICATION_METHOD_KEY, AuthnContext.PREVIOUS_SESSION_AUTHN_CTX);
105 }
106
107 Session idpSession = (Session) httpRequest.getAttribute(Session.HTTP_SESSION_BINDING_ATTRIBUTE);
108 if(idpSession == null){
109 log.warn("No existing IdP session available.");
110 httpRequest.setAttribute(LoginHandler.AUTHENTICATION_ERROR_KEY, "No existing IdP session available");
111 }else{
112 log.debug("Using existing IdP session for {}", idpSession.getPrincipalName());
113 httpRequest.setAttribute(LoginHandler.PRINCIPAL_NAME_KEY, idpSession.getPrincipalName());
114 }
115
116 AuthenticationEngine.returnToAuthenticationEngine(httpRequest, httpResponse);
117 }
118 }