-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ChainAuthHandler should invoke postAuthentication (#2582)
See #2408 Some auth handlers have postAuthentication methods that must be invoked. For example, FormLoginHandler may have to redirect the client after authentication. ChainAuthHandler was not able to invoke the post-authentication method of the handler that authenticated the user. Signed-off-by: Thomas Segismont <[email protected]>
- Loading branch information
1 parent
3f38d9b
commit f856512
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package io.vertx.ext.web.handler; | ||
|
||
import io.vertx.core.MultiMap; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.http.HttpHeaders; | ||
import io.vertx.core.http.HttpMethod; | ||
import io.vertx.ext.auth.authentication.AuthenticationProvider; | ||
import io.vertx.ext.auth.htdigest.HtdigestAuth; | ||
|
@@ -91,4 +94,42 @@ public void testWithMultipleWWWAuthenticate() throws Exception { | |
assertTrue(headers.get(1).startsWith("Digest realm=\"[email protected]\"")); | ||
},401, "Unauthorized", "Unauthorized"); | ||
} | ||
|
||
@Test | ||
public void testWithPostAuthenticationAction() throws Exception { | ||
router.clear(); | ||
|
||
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); | ||
|
||
chain = ChainAuthHandler.any() | ||
// Direct login is implemented as a post-authentication action | ||
.add(FormLoginHandler.create(authProvider).setDirectLoggedInOKURL("/welcome")); | ||
|
||
router.post("/login") | ||
.handler(BodyHandler.create()) | ||
.handler(chain); | ||
|
||
testRequest(HttpMethod.POST, "/login", req -> { | ||
String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO"; | ||
Buffer buffer = Buffer.buffer(); | ||
String str = | ||
"--" + boundary + "\r\n" + | ||
"Content-Disposition: form-data; name=\"" + FormLoginHandler.DEFAULT_USERNAME_PARAM + "\"\r\n\r\ntim\r\n" + | ||
"--" + boundary + "\r\n" + | ||
"Content-Disposition: form-data; name=\"" + FormLoginHandler.DEFAULT_PASSWORD_PARAM + "\"\r\n\r\ndelicious:sausages\r\n" + | ||
"--" + boundary + "--\r\n"; | ||
buffer.appendString(str); | ||
req.putHeader("content-length", String.valueOf(buffer.length())); | ||
req.putHeader("content-type", "multipart/form-data; boundary=" + boundary); | ||
req.write(buffer); | ||
}, resp -> { | ||
MultiMap headers = resp.headers(); | ||
// session will be upgraded | ||
String setCookie = headers.get("set-cookie"); | ||
assertNotNull(setCookie); | ||
// client will be redirected | ||
assertTrue(headers.contains(HttpHeaders.LOCATION, "/welcome", false)); | ||
}, 302, "Found", null); | ||
} | ||
|
||
} |