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