escapehither / security-manager-bundle
此包的最新版本(v1.0.0)没有可用的许可信息。
一个管理安全和用户的symfony扩展包
v1.0.0
2022-01-29 21:25 UTC
Requires
- php: >=5.5.9
- doctrine/doctrine-bundle: ~1.6
- doctrine/doctrine-cache-bundle: ~1.2
- doctrine/orm: ^2.5
- lexik/jwt-authentication-bundle: ^2.4
- symfony/dependency-injection: ~3.0|~4.0
- symfony/form: ~3.0|~4.0
- symfony/framework-bundle: ~3.0|~4.0
- symfony/polyfill-apcu: ^1.0
- symfony/serializer: ~3.0|~4.0
Requires (Dev)
- fzaninotto/faker: ^1.8
- phpunit/php-invoker: ~1.1
- phpunit/phpunit: 4.8.6
- symfony/phpunit-bridge: ^3.0
This package is not auto-updated.
Last update: 2024-10-01 10:50:56 UTC
README
步骤 1: 下载扩展包
实际上,这个扩展包在一个私有仓库中。在你的 Composer.json 文件中添加
{ //.... "repositories": [{ "type": "composer", "url": "https://packages.escapehither.com" }] }
打开命令行,进入你的项目目录,然后执行以下命令以下载此扩展包的最新稳定版本
$ composer require escapehither/security-manager-bundle dev-master
此命令需要你全局安装了 Composer,如 Composer 文档的安装章节中所述。
步骤 2: 启用扩展包
然后,通过将其添加到项目 app/AppKernel.php
文件中注册的扩展包列表来启用扩展包
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new EscapeHither\CrudManagerBundle\StarterKitCrudBundle(), new EscapeHither\SecurityManagerBundle\StarterKitSecurityManagerBundle(), new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), new Knp\Bundle\MenuBundle\KnpMenuBundle(), new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(), new Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle(), ); // ... } // ... }
步骤 3: 创建你的用户类
假设你的扩展包名为 appBundle
id; } } ``` ```xml
Step 4: Import and define configuration
-------------------------
1. Import config file in `app/config/config.yml` for default filter set configuration:
```yaml
imports:
- { resource: "@EscapeHitherSecurityManagerBundle/Resources/config/services.yml" }
- { resource: "@EscapeHitherSecurityManagerBundle/Resources/config/config.yml" }
```
If you want a a backend to manage your resource. add in your config file
```yaml
escape_hither_crud_manager:
resources:
user:
controller: EscapeHither\SecurityManagerBundle\Controller
entity: AppBundle\Entity\User
form: EscapeHither\SecurityManagerBundle\Form\UserType
repository: AppBundle\Repository\UserRepository
```
Import user routing file in `app/config/routing.yml` :
Change administration to your secure area.
```yaml
escape_hither_manage_user:
resource: "@EscapeHitherSecurityManagerBundle/Resources/config/routing/user.yml"
prefix: /administration/user
```
2. Import routing files in `app/config/routing.yml`:
```yaml
escape_hither_security_manager:
resource: "@EscapeHitherSecurityManagerBundle/Resources/config/routing.yml"
prefix: /
```
3. Configuration reference:
```yaml
escape_hither_security_manager:
user_provider:
class : AppBundle\Entity\User
```
4. Import security files in `app/config/security.yml`:
```yaml
# To get started with security, check out the documentation:
# https://symfony.com.cn/doc/current/security.html
security:
# https://symfony.com.cn/doc/current/security.html#b-configuring-how-users-are-loaded
#providers:
#in_memory:
#memory: ~
role_hierarchy:
ROLE_MANAGER: [ROLE_USER]
ROLE_ADMIN: [ROLE_MANAGE_ROOM,ROLE_MANAGE_CUSTOMER,ROLE_MANAGE_RESERVATION]
ROLE_SUPER_ADMIN: [ROLE_ADMIN,ROLE_MANAGE_USER,ROLE_ALLOWED_TO_SWITCH]
providers:
our_users:
entity: { class: AppBundle\Entity\User, property: email }
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/api/login
stateless: true
anonymous: true
form_login:
check_path: /api/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
api:
pattern: ^/api
stateless: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
#- escapehither.security_jwt_token_authenticator #my authenticator
main:
anonymous: ~
guard:
entry_point: escapehither.security_login_form_authenticator
authenticators:
- escapehither.security_login_form_authenticator
logout:
path: /logout
secured_area:
# ...
form_login:
# ...
#csrf_token_generator: security.csrf.token_manager
encoders:
EscapeHither\SecurityManagerBundle\Entity\UserAccountInterface: bcrypt
access_control:
- { path: ^/admin, roles: ROLE_MANAGER }
- { path: ^/profile, roles: ROLE_USER }
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
```
4. Install LexikJWTAuthenticationBundle:
Add encoder for jwt.
```console
mkdir var/jwt
openssl genrsa -out var/jwt/private.pem -aes256 4096
openssl rsa -pubout -in var/jwt/private.pem -out var/jwt/public.pem
步骤 5: 更新数据库模式
$ bin/console doctrine:schema:update --force $ bin/console cache:clear -e prod $ bin/console cache:clear