fsb/proxy-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fsb/proxy-bundle

最新稳定版本:v0.1.1

Composer 安装命令:

composer require fsb/proxy-bundle

包简介

Authenticated symfony bundle: provides an authentication layer on top of a PHP proxy.

README 文档

README

Authenticated symfony bundle: provides an authentication layer on top of a PHP proxy.

This bundle provides a User model and a UserProvider, to authenticate users based on a yml file. It also provides a Symfony command to add users with encrypted passwords.

Once the user is connected, it provides a PHP proxy thanks to 8p/Guzzle-Bundle and the Guzzle PHP library, currently v6.

Why?

This bundle is usefull if you want to proxy an HTTP application, with an authentication layer stronger than http standards such as HTTP_BASIC.

Requirements

  • Symfony 2.7 or above
  • 8p/GuzzleBundle (included by composer)

Installation

To install this bundle, run the command below and you will get the latest version by Packagist.

composer require fsb/proxy-bundle

Usage

Load required bundles in AppKernel.php:

// app/AppKernel.php
public function registerBundles()
{
  $bundles = array(
    // [...]
    new EightPoints\Bundle\GuzzleBundle\GuzzleBundle()
    new Fsb\Bundle\ProxyBundle\FsbProxyBundle()
  );
}

Set up configuration

# app/config/config.yml
twig:
  # [...]
  globals:
    proxy_title: Your Proxy HTML title

# FsbProxyBundle uses assetic, and for the login page,
# Both CSS, SASS and JS resources.
# However, you can override the templates and manage it yourself.
assetic:
  # [...]
  bundles: [ FsbProxyBundle ]
  filters:
    # [...]
    scss:
      # Requires ruby-sass
      apply_to: "\.scss$"
    # OPTIONALLY, you can install uglifyjs and uglifycss to minify the assets
    uglifyjs2:
      bin: "path/of/your/node_modules/.bin/uglifyjs"
    uglifycss:
      bin: "path/of/your/node_modules/.bin/uglifycss"

guzzle:
  base_url: http://localhost:8888/
  
fsb_proxy:
  users_provider_file_path: "path/of/users.yml"

Set up routing

app/config/routing.yml or any other routing file

fsb_proxy:
  resource: "@FsbProxyBundle/Resources/config/routing.yml"
  prefix:   /

Set up security

# app/config/security.yml
security:
  encoders:
    # The FsbProxyBundle User model class, you can choose your favorite encoder
    Fsb\Bundle\ProxyBundle\Model\User:
      algorithm:            pbkdf2
      hash_algorithm:       sha512
      iterations:           1000000
      encode_as_base64:     true

  providers:
    # [...]
    proxy_users:
      id: fsb_proxy.provider.yaml_user_provider

  firewalls:
    # [...]
    fsb_proxy_app_login:
      pattern:  ^/login$
      security: false
  
    fsb_proxy_app:
      pattern:  ^/
      provider: proxy_users
      form_login:
        check_path: fsb_proxy_login_check_page
        login_path: fsb_proxy_login_page
        always_use_default_target_path: true
        default_target_path: /
      logout:
        path:   fsb_proxy_logout_page
        target: /

  access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/, roles: ROLE_USER }

Authentication and users management

Here we are!

This bundle comes with a service called YamlUserProvider, providing users from a yaml file. To add an access, add a new yaml array of this user's informations :

# /path/of/your/users.yml
username:
  salt: # the salt used to encrypt the password
  password: # the encrypted password

You also have two commands to manage users from the console :

To create a new user :

php app/console fsb-proxy:users:create [username] [password] [--all]

Both username and password arguments are optionnal, the command will ask for it if you do not provide it. The --override (or ````-o`````) option allow to replace an existing user's password (if the user does not exists, he will be created).

To remove an existing user :

php app/console fsb-proxy:users:remove [username] [--all]

Username argument is optionnal, the command will ask for it if you do not provide it. The --all option allow to remove every existing users from the file.

Extend the bundle

The Bundle itself provides the security layer, with login and logout routes ; And a default login page, before "proxying" routes through the Guzzle client.

As a symfony bundle, you can extend it, to benefits of Symfony inheritance, Then override resources and / or controllers:

Controller/
  RestController.php --> Manage PHP proxy once authenticated
  Security/
    AuthenticationController.php --> Manage authentication
Resources/
  views/
    layout.html.twig --> Base template with HTML doctype
    Security/
      login.html.twig --> Login page template

All you need to do is setting up your own bundle as child of FsbProxyBundle:

// src/You/YourBundleName/YouYourBundleName.php
namespace You\YourBundleName;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class YouYourBundleName extends Bundle
{
  public function getParent()
  {
    return 'FsbProxyBundle';
  }
}

Authors

License

This bundle is released under the MIT license

fsb/proxy-bundle 适用场景与选型建议

fsb/proxy-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「curl」 「rest」 「security」 「http client」 「Authentication」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fsb/proxy-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fsb/proxy-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 fsb/proxy-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-03