From def5758f0ae642851048fda8b8120b087b76b380 Mon Sep 17 00:00:00 2001 From: Abhinab Kanrar Date: Mon, 21 Aug 2017 16:30:44 +0530 Subject: [PATCH] easy code added for simplicity (#2473) * moving jmh into libraries module * refactoring jmh * Update pom.xml * manual algorightm * with BM result * fix for space issue * Fixed indentation * change as per suggestion * vavr either * adding unit test and othe rutilities * adding concurrent module * concurrent package description * concurrent package description * Update EitherUnitTest.java * introducing lambda expression * jooby project * jooby project * reducing employee bean content * bootique module * bootique * bootique * undertow module * undertow module * refactoring * using lambda * as per baeldung formatter * easy code added for simplicity --- .../baeldung/undertow/secure/CustomIdentityManager.java | 3 ++- .../java/com/baeldung/undertow/secure/SecureServer.java | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/undertow/src/main/java/com/baeldung/undertow/secure/CustomIdentityManager.java b/undertow/src/main/java/com/baeldung/undertow/secure/CustomIdentityManager.java index e0984f65a5..16231f036d 100644 --- a/undertow/src/main/java/com/baeldung/undertow/secure/CustomIdentityManager.java +++ b/undertow/src/main/java/com/baeldung/undertow/secure/CustomIdentityManager.java @@ -8,9 +8,10 @@ import java.util.Set; import io.undertow.security.idm.Account; import io.undertow.security.idm.Credential; +import io.undertow.security.idm.IdentityManager; import io.undertow.security.idm.PasswordCredential; -public class CustomIdentityManager implements io.undertow.security.idm.IdentityManager { +public class CustomIdentityManager implements IdentityManager { private final Map users; diff --git a/undertow/src/main/java/com/baeldung/undertow/secure/SecureServer.java b/undertow/src/main/java/com/baeldung/undertow/secure/SecureServer.java index 6f520944db..9997883da6 100644 --- a/undertow/src/main/java/com/baeldung/undertow/secure/SecureServer.java +++ b/undertow/src/main/java/com/baeldung/undertow/secure/SecureServer.java @@ -29,13 +29,15 @@ public class SecureServer { final IdentityManager idm = new CustomIdentityManager(users); Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(addSecurity((exchange) -> { - final SecurityContext context = exchange.getSecurityContext(); - exchange.getResponseSender().send("Hello " + context.getAuthenticatedAccount().getPrincipal().getName(), - IoCallback.END_EXCHANGE); + setExchange(exchange); }, idm)).build(); server.start(); + } + private static void setExchange(HttpServerExchange exchange) { + final SecurityContext context = exchange.getSecurityContext(); + exchange.getResponseSender().send("Hello " + context.getAuthenticatedAccount().getPrincipal().getName(),IoCallback.END_EXCHANGE); } private static HttpHandler addSecurity(final HttpHandler toWrap, final IdentityManager identityManager) {