Add a firewall record
@param Application $app
@param string|RequestMatcher $pattern
@param string $authType (oauth, anonymous, oauth-optional, etc)
553219
protected function addFirewall(Application $app, $pattern, $authType)
    {
        $firewalls = $app['security.firewalls'];
        $key = is_object($pattern) ? spl_object_hash($pattern) : $pattern;
        $firewalls[$key] =  [
            'pattern' => $pattern,
            $authType => true,
        ];

        $app['security.firewalls'] = $firewalls;
    }
91959
public function createAuthenticationProvider(\Silex\Application $app,
                                                 UserProviderInterface $userProvider,
                                                 $providerKey)
    {
        return new LdapBindAuthenticationProvider($userProvider, $app['security.user_checker'], $providerKey, $this->ldapClient, $this->dnString);
    }
732893
public function register(Application $app)
    {
        $app["swagger.apiDocPath"] = "/api/api-docs";
        $app["swagger.excludePath"] = array();
        $app["swagger.prettyPrint"] = true;
        $app["swagger.cache"] = array();
        $app["swagger.basePath"] = null;
        $app["swagger.apiVersion"] = null;
        $app["swagger.swaggerVersion"] = "1.2";
        $app["swagger.resourcePrefix"] = "/";
        $app["swagger.resourceSuffix"] = "";

        $app["swagger"] = $app->share(new SwaggerService());
    }
258970
public function setApiAuthType($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->api_auth_type !== $v) {
            $this->api_auth_type = $v;
            $this->modifiedColumns[] = RemoteAppPeer::API_AUTH_TYPE;
        }


        return $this;
    }
724246
public function connect(Application $app)
    {
        $ctrl = $app['controllers_factory'];



        /**
         * Homepage
         */
        $ctrl
            ->get(
                '/',
                function () use ($app) {
                    $root = str_replace('index.php/', '', $app['url_generator']->generate('home'));

                    if ($app['request']->getRequestURI() != $root) {
                        return $app->redirect($root, Response::HTTP_MOVED_PERMANENTLY);
                    }

                    return $app['twig']->render('front/partials/home.twig');
                }
            )
            ->bind('home');



        /**
         * Admin root
         */
        $ctrl
            ->get(
                '/admin',
                function () use ($app) {
                    return $app->redirect($app['url_generator']->generate($app['config']['admin']['root']));
                }
            );


        /**
         * robots.txt
         */
        $ctrl
            ->get(
                '/robots.txt',
                function () use ($app) {
                    $response = new Response(
                        'User-agent: *'.PHP_EOL.(
                            $app['debug']
                                ? 'Disallow: /'
                                : 'Sitemap: '.$app['url_generator']->generate('home').'sitemap.xml'
                        )
                    );

                    $response->headers->set('Content-Type', 'text/plain');
                    return $response;
                }
            );



        return $ctrl;
    }
334078
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $requestHandler = $request->getAttributes()['requestHandler'][2]['handler'] ?? '';
        $service = App::getBean(AuthServiceInterface::class);
        if (!$service instanceof AuthServiceInterface) {
            throw new AuthException(ErrorCode::POST_DATA_NOT_PROVIDED, 'AuthService should implement Swoft\Auth\Mapping\AuthServiceInterface');
        }
        if (!$service->auth($requestHandler, $request)) {
            throw new AuthException(ErrorCode::ACCESS_DENIED);
        }
        $response = $handler->handle($request);
        return $response;
    }
983808
public function addFirewall(FirewallInterface $firewall)
    {
        $this->firewalls[$firewall->getName()] = $firewall;

        if ($this->app) {
            $firewall->register($this);
        }
    }
779342
public function addHandler($destination, $pattern=Logger::ALL, $level='LOG_INFO', $type='file')
    {
        $this->_logPatterns[$pattern] = $this->buildHandler($destination, $level, $type);

    }
586313
public function routeMatched($request_type, $route_pattern, $query_path)
    {
        $matched = $this->app->trigger(
            'system.request.route.matching', 
            array($this, 'processRouteMatching'),
            array(
                'request_type'=> $request_type, 
                'query_path' => $query_path,
                'route_pattern' => $route_pattern
            )
        );

        return $matched;
    }
741797
public RouteMatcher trace(String pattern, Handler<HttpServerRequest> handler) {
		addPattern(pattern, handler, traceBindings);
		return this;
	}
556307
public function register(Application $app)
    {
        $app['rest_normalizer.version'] = '0.1.0';
        $app['rest_normalizer.builder'] = $app->protect(
            function ($object = null) use ($app) {
                $version = $app['rest_normalizer.version'];
                $request = $app['request'];
                /** @var $request \Symfony\Component\HttpFoundation\Request */

                $builder = ResponseBuilder::create(
                    $version,
                    HttpMethod::valueOf($request->getMethod()),
                    $object
                );

                foreach ($request->request->all() as $key => $value) {
                    $parameter = Parameter::create($key, $value);
                    $builder->addParameter($parameter);
                }

                return $builder;
            }
        );
    }
237907
public function write(Request $request, Application $app)
    {
        $username = $request->request->get('username');
        $password = $request->request->get('password');

        $user = $this->userProvider->loadUserByUsername($username);
        if (!$this->passwordEncoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) {
            throw new BadCredentialsException;
        }

        $this->userManager->loginUser($user);
        // get latest revision of user
        $user = $this->userProvider->loadUserByIdentifier($user->getAggregateId());
        $request->attributes->set('user', $user);

        return [LoginSuccessView::class];
    }
32620
function auth(app, config) {
  /* Ensure authorizer */
  if (!type.is(config.authorizer, Function)) {
    throw new Error("Authorizer must be a [Function]!");
  }

  /* Check debug type */
  if (type.is(config.debug, Function)) {
    debug = config.debug;
  } else if (config.debug) {
    debug = console.log;
  }

  app.use(function (req, res, next) {
    /* Set the session authorized property */
    req.session.authorized = config.authorizer(req);

    next();
  });

  /* Set authorization rules for each path */
  config.routes.forEach(function (route) {
    if (!type.is(route.path, Array) && !type.is(route.path, String)) {
      throw new Error("The route's path must be a [String] or an [Array] of [String]s!");
    }

    debug(route.method + " " + route.path + " --> " + route.allows);

    /* Callback for each method */
    function callback(req, res, next) {
      authorize(route, req, res, next);
    }

    /* The base router */
    var router = app.route(route.path);

    /* If method is an array */
    if (type.is(route.method, Array)) {
      return route.method.forEach(function (method) {
        router[method.toLowerCase()](callback);
      });
    }

    /* If method is a string */
    if (type.is(route.method, String)) {
      return router[route.method.toLowerCase()](callback);
    }

    /* If no method is specified default to ALL */
    router(callback);
  });
}
66537
static public function create($templateName, App $app, $templateType = null) {
        if ($templateType === null) {
            $tmp          = explode('.', $templateName);
            $templateType = $tmp[count($tmp) - 1];
        } else {
            $templateType = strtolower($templateType);
        }

        return self::loadTemplate($templateName, $app, $templateType);
    }
713148
protected function loadAccount(
        ApplicationInterface $application,
        LoginAttempt $loginAttempt
    ) {
        // run grant extension result
        return $this->grantExtensions
            ->get($loginAttempt->getData('grant_type'))
            ->grant($application, $loginAttempt)
        ;
    }
1088386
public function register(Application $app)
    {
        $app[Service::PASSWORD_HASH] = $app->share(function () use ($app) {
            return new Service\DefaultPasswordHashService();
        });
    }
612340
protected function setFirewalls(Application $app)
    {
        $app->extend('security.firewalls', function ($firewalls, $app) {
            $logout = new RequestMatcher('^/oauth/logout', null, ['POST']);
            $oAuth  = new RequestMatcher('^/oauth');

            $breedFirewalls = [
                'oauth-logout' => [
                    'pattern' => $logout,
                    'oauth'   => true,
                ],
                'oauth-public' => [
                    'pattern'   => $oAuth,
                    'anonymous' => true,
                ],
            ];

            return array_merge($breedFirewalls, $firewalls);
        });
    }