|
46 | 46 | public class FormAuthenticationMechanism implements AuthenticationMechanism {
|
47 | 47 |
|
48 | 48 | public static final String LOCATION_ATTRIBUTE = FormAuthenticationMechanism.class.getName() + ".LOCATION";
|
49 |
| - |
50 | 49 | public static final String DEFAULT_POST_LOCATION = "/j_security_check";
|
51 |
| - |
| 50 | + protected static final String ORIGINAL_SESSION_TIMEOUT = "io.undertow.servlet.form.auth.orig.session.timeout";; |
52 | 51 | private final String name;
|
53 | 52 | private final String loginPage;
|
54 | 53 | private final String errorPage;
|
55 | 54 | private final String postLocation;
|
56 | 55 | private final FormParserFactory formParserFactory;
|
57 | 56 | private final IdentityManager identityManager;
|
58 | 57 |
|
| 58 | + /** |
| 59 | + * If the authentication process creates a session, this is the maximum session timeout (in seconds) during the |
| 60 | + * authentication process. Once authentication is complete, the default session timeout will apply. Sessions that |
| 61 | + * exist before the authentication process starts will retain their original session timeout throughout. |
| 62 | + */ |
| 63 | + protected final int authenticationSessionTimeout = 120; |
| 64 | + |
59 | 65 | public FormAuthenticationMechanism(final String name, final String loginPage, final String errorPage) {
|
60 | 66 | this(FormParserFactory.builder().build(), name, loginPage, errorPage);
|
61 | 67 | }
|
@@ -166,6 +172,10 @@ public AuthenticationMechanismOutcome runFormAuth(final HttpServerExchange excha
|
166 | 172 | protected void handleRedirectBack(final HttpServerExchange exchange) {
|
167 | 173 | final Session session = Sessions.getSession(exchange);
|
168 | 174 | if (session != null) {
|
| 175 | + final Integer originalSessionTimeout = (Integer) session.removeAttribute(ORIGINAL_SESSION_TIMEOUT); |
| 176 | + if (originalSessionTimeout != null) { |
| 177 | + session.setMaxInactiveInterval(originalSessionTimeout); |
| 178 | + } |
169 | 179 | final String location = (String) session.removeAttribute(LOCATION_ATTRIBUTE);
|
170 | 180 | if(location != null) {
|
171 | 181 | exchange.addDefaultResponseListener(new DefaultResponseListener() {
|
@@ -208,7 +218,19 @@ public ChallengeResult sendChallenge(final HttpServerExchange exchange, final Se
|
208 | 218 | }
|
209 | 219 |
|
210 | 220 | protected void storeInitialLocation(final HttpServerExchange exchange) {
|
211 |
| - Session session = Sessions.getOrCreateSession(exchange); |
| 221 | + Session session = Sessions.getSession(exchange); |
| 222 | + boolean newSession = false; |
| 223 | + if (session == null) { |
| 224 | + session = Sessions.getOrCreateSession(exchange); |
| 225 | + newSession = true; |
| 226 | + } |
| 227 | + if (newSession) { |
| 228 | + int originalMaxInactiveInterval = session.getMaxInactiveInterval(); |
| 229 | + if (originalMaxInactiveInterval > authenticationSessionTimeout) { |
| 230 | + session.setAttribute(ORIGINAL_SESSION_TIMEOUT, session.getMaxInactiveInterval()); |
| 231 | + session.setMaxInactiveInterval(authenticationSessionTimeout); |
| 232 | + } |
| 233 | + } |
212 | 234 | session.setAttribute(LOCATION_ATTRIBUTE, RedirectBuilder.redirect(exchange, exchange.getRelativePath()));
|
213 | 235 | }
|
214 | 236 |
|
|
0 commit comments