class ServiceAuthenticationDecorator {

    public void process(HttpRequest request) {
        final RequestContext context = RequestContext.getCurrentContext();

        if (context.get(AUTHENTICATION_COMMAND_KEY) instanceof ServiceAuthenticationServiceImpl.UniversalAuthenticationCommand) {
            InstanceInfo info = RequestContextUtils.getInstanceInfo().orElseThrow(
                () -> new RequestContextNotPreparedException("InstanceInfo of loadbalanced instance is not present in RequestContext")
            );
            final Authentication authentication = serviceAuthenticationService.getAuthentication(info);
            AuthenticationCommand cmd;

            try {
                final String jwtToken = authenticationService.getJwtTokenFromRequest(context.getRequest()).orElse(null);

                cmd = serviceAuthenticationService.getAuthenticationCommand(authentication, jwtToken);

                if (cmd == null) {
                    return;
                }

                if (cmd.isRequiredValidJwt()) {
                    if (jwtToken == null || !authenticationService.validateJwtToken(jwtToken).isAuthenticated()) {
                        throw new RequestAbortException(new TokenNotValidException("JWT Token is not authenticated"));
                    }
                }
            }
            catch (AuthenticationException ae) {
                throw new RequestAbortException(ae);
            }

            cmd.applyToRequest(request);
        }
    }

}