@ Override public void handle ( final RoutingContext routingContext ) { // No longer sufficient to check whether we have a user, as the user must have an appropriate pac4j profile // so a user != null check is insufficient, so we'll go straight to the pac4j logic check // Note that at present the security logic call is blocking (and authorization contained within can also // be blocking) so we have to wrap the following call in an executeBlocking call to avoid blocking the // event loop final VertxWebContext webContext = new VertxWebContext ( routingContext , sessionStore ) ; // Strip out DirectClients from pac4j user at this point final Pac4jUser pac4jUser = ( Pac4jUser ) routingContext . user ( ) ; if ( pac4jUser != null ) { final Map < String , CommonProfile > indirectProfiles = pac4jUser . pac4jUserProfiles ( ) . entrySet ( ) . stream ( ) . filter ( e -> { final String clientName = e . getValue ( ) . getClientName ( ) ; return ( config . getClients ( ) . findClient ( clientName ) instanceof IndirectClient ) ; } ) . collect ( toMap ( e -> e . getKey ( ) , e -> e . getValue ( ) ) ) ; if ( ! indirectProfiles . isEmpty ( ) ) { pac4jUser . pac4jUserProfiles ( ) . clear ( ) ; pac4jUser . pac4jUserProfiles ( ) . putAll ( indirectProfiles ) ; } else { routingContext . clearUser ( ) ; } } vertx . executeBlocking ( future -> securityLogic . perform ( webContext , config , ( ctx , profiles , parameters ) -> { // This is what should occur if we are authenticated and authorized to view the requested // resource future . complete ( ) ; return null ; } , httpActionAdapter , clientNames , authorizerName , matcherName , multiProfile ) , asyncResult -> { // If we succeeded we're all good here, the job is done either through approving, or redirect, or // forbidding // However, if an error occurred we need to handle this here if ( asyncResult . failed ( ) ) { unexpectedFailure ( routingContext , asyncResult . cause ( ) ) ; } else { LOG . info ( "Authorised to view resource " + routingContext . request ( ) . path ( ) ) ; routingContext . next ( ) ; } } ) ; }
Port of Pac4J auth to a handler in vert . x 3 .