根据教程,我删除了内存提供程序和DemoBundle,并添加了数据库提供程序.但我得到InvalidArgumentException:"你必须至少添加一个身份验证提供程序".
我的security.yml:
# you can read more about security in the related section of the documentation
# http://symfony.com/doc/current/book/security.html
security:
# http://symfony.com/doc/current/book/security.html#encoding-the-user-s-password
encoders:
AppBundle\Entity\User:
algorithm: bcrypt
# http://symfony.com/doc/current/book/security.html#hierarchical-roles
role_hierarchy:
ROLE_GLOBAL_MODERATOR: ROLE_USER
ROLE_ADMIN: ROLE_GLOBAL_MODERATOR
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
db:
entity:
class: AppBundle:User
property: email
# if you're using multiple entity managers
# manager_name: customer
# the main part of the security, where you can set up firewalls
# for specific sections of your app
firewalls:
# disables authentication for …Run Code Online (Sandbox Code Playgroud) 我在 Symfony3 上做了一个注册/登录表单示例。
用户登录后仍可访问 login.html.twig
我如何控制security.yml或重定向login.html.twig?
我的访问控制;
access_control:
- { path: ^/registration-form-submission$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/(login|register)$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ROLE_USER }
Run Code Online (Sandbox Code Playgroud) 我正在 mysql 中创建组织表。
\n\n该实体被称为Organisation并且它有一个password字段。
当我尝试使用UserPasswordEncoderInterface它时,它需要user实体,所以这不起作用。我尝试使用PasswordEncoderInterface,但它说该服务不存在。这里可以做什么?
这是我的代码:
\n\n public function register(Request $request, EntityManagerInterface $entityManager, PasswordEncoderInterface $encoder)\n {\n $organisation = new Organisation();\n\n $form = $this->createForm(OrganisationRegisterType::class, $organisation);\n\n $form->handleRequest($request);\n\n if ($form->isSubmitted() && $form->isValid()) {\n $plainPassword = $form->getData()->getPassword();\n $encoded = $encoder->encodePassword($plainPassword, null);\n $organisation->setPassword($encoded);\n\n $entityManager = $this->getDoctrine()->getManager();\n $entityManager->persist($organisation);\n $entityManager->flush();\n\n $this->addFlash(\n \'success\',\n \'Organizacija sukurta s\xc4\x97kmingai. Nurodytu el. pa\xc5\xa1tu buvo i\xc5\xa1si\xc5\xb3sta prisijungimo informacija\'\n );\n }\nRun Code Online (Sandbox Code Playgroud)\n\n这是我得到的错误:
\n\n\n\n无法自动装配“App\\Controller\\OrganizationController::register()”的参数 $encoder:它引用接口“Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface”,但不存在此类服务。您是否创建了一个实现此接口的类?
\n
是否可以有 2 个实体来实现UserInterface?
如何在我的警卫中使用它来检查两个类并使用相同的防火墙?
这个想法是公司可以拥有自己的CVTheque或共享的(与CVTheque具有 OneToMany 关系Company)。
我想拥有Candidate和User实体。
Candidate并且User将用在该应用被认证同一登录表单。所以我不知道这是否可能以及如何在我的警卫身份验证器上实现这一点。
他们将被重定向到他们自己的仪表板,具体取决于连接的用户(Candidate或User)的实例。
我是 symfony 的新手,我正在使用 LexikJWTAuthenticationBundle 进行授权。我正在使用 symfony 6.0.2 和 2.14 lexic 版本。我正在使用 Postgresql 12.9。我的 security.yaml:
security:
enable_authenticator_manager: true
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
App\Entity\User:
algorithm: auto
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
login:
pattern: ^/api/login
stateless: true
json_login:
check_path: /api/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
api:
pattern: ^/api
stateless: true
jwt: ~
main:
lazy: true
provider: app_user_provider
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
# activate different ways …Run Code Online (Sandbox Code Playgroud) TL;DR:如何向转换添加自定义约束(即安全投票者)?
我的应用程序需要一些工作流管理系统,所以我想尝试 Symfony 的新Workflow Component。让我们以拉取请求工作流程为例。
在此示例中,仅描述状态及其转换。但是如果我想向此工作流程添加其他约束怎么办?我可以想象一些限制:
虽然在这种情况下您可以使用事件,但我认为这不是处理它的最佳方法,因为事件是在$workflow->apply(). 我想事先知道是否允许用户更改状态,以便我可以隐藏或禁用该按钮。(不是这样的)。
LexikWorkflowBundle通过向步骤(转换)添加角色部分解决了这个问题。切换到这个捆绑包可能是一个好主意,但我想弄清楚如何在没有这个捆绑包的情况下解决这个问题。
添加自定义实体约束(“超过 1 年的 PR 不能重新打开”)和安全约束(“只有管理员可以接受 PR ”,也许通过使用 Symfony 的安全投票者)到转换的最佳方法是什么?
更新: 澄清一下:我想向我的工作流程添加权限控制,但这并不一定意味着我想将其紧密耦合到工作流程组件。我想坚持良好的做法,因此给定的解决方案应该尊重单一责任原则。
我设置了一个Symfony项目,以使用in_memory提供程序中的一些凭据:
providers:
in_memory:
memory:
users:
user1:
password: password1
roles: 'ROLE1'
Run Code Online (Sandbox Code Playgroud)
现在,此应用程序的代码将在github上发布,我显然希望将凭据保密。
有没有办法从其他(非版本)文件加载此配置?我正在寻找一种解决方案,允许我尽可能少地编辑代码,并在可能的情况下避免更改所使用的安全提供程序。