11package com .baeldung .undertow .secure ;
22
3- import java .util .Collections ;
4- import java .util .HashMap ;
5- import java .util .List ;
6- import java .util .Map ;
7-
83import io .undertow .Undertow ;
94import io .undertow .io .IoCallback ;
105import io .undertow .security .api .AuthenticationMechanism ;
1914import io .undertow .server .HttpHandler ;
2015import io .undertow .server .HttpServerExchange ;
2116
17+ import java .util .Collections ;
18+ import java .util .HashMap ;
19+ import java .util .List ;
20+ import java .util .Map ;
21+
2222public class SecureServer {
2323
2424 public static void main (String [] args ) {
@@ -28,24 +28,24 @@ public static void main(String[] args) {
2828
2929 final IdentityManager idm = new CustomIdentityManager (users );
3030
31- Undertow server = Undertow .builder (). addHttpListener ( 8080 , "localhost" ). setHandler ( addSecurity (( exchange ) -> {
32- setExchange ( exchange );
33- } , idm )).build ();
31+ Undertow server = Undertow .builder ()
32+ . addHttpListener ( 8080 , "localhost" )
33+ . setHandler ( addSecurity ( SecureServer :: setExchange , idm )).build ();
3434
3535 server .start ();
3636 }
3737
3838 private static void setExchange (HttpServerExchange exchange ) {
3939 final SecurityContext context = exchange .getSecurityContext ();
40- exchange .getResponseSender ().send ("Hello " + context .getAuthenticatedAccount ().getPrincipal ().getName (),IoCallback .END_EXCHANGE );
40+ exchange .getResponseSender ().send ("Hello " + context .getAuthenticatedAccount ().getPrincipal ().getName (), IoCallback .END_EXCHANGE );
4141 }
4242
4343 private static HttpHandler addSecurity (final HttpHandler toWrap , final IdentityManager identityManager ) {
4444 HttpHandler handler = toWrap ;
4545 handler = new AuthenticationCallHandler (handler );
4646 handler = new AuthenticationConstraintHandler (handler );
4747 final List <AuthenticationMechanism > mechanisms = Collections
48- .< AuthenticationMechanism > singletonList (new BasicAuthenticationMechanism ("Baeldung_Realm" ));
48+ . singletonList (new BasicAuthenticationMechanism ("Baeldung_Realm" ));
4949 handler = new AuthenticationMechanismsHandler (handler , mechanisms );
5050 handler = new SecurityInitialHandler (AuthenticationMode .PRO_ACTIVE , identityManager , handler );
5151 return handler ;
0 commit comments