Skip to content

struct Athena::Security::Bundle
inherits Athena::DependencyInjection::AbstractBundle #

Integrates the Security component with the dependency injection and HTTP kernel components, such as within an Athena Framework application.

Require athena-security/bundle to register the bundle, then configure at least one firewall:

require "athena"
require "athena-security/bundle"

ADI.configure({
  security: {
    password_hashers: {
      ASEC::User::InMemory => :auto,
    },
    providers: {
      users_in_memory: {
        memory: {
          users: {"admin" => {password: "$2y$13$...", roles: ["ROLE_ADMIN"]}},
        },
      },
    },
    firewalls: {
      main: {
        pattern:               /^\/api/,
        custom_authenticators: ["api_token_authenticator"],
      },
    },
    access_control: [
      {path: /^\/api\/admin/, role: "ROLE_ADMIN"},
      {path: /^\/api/, role: "IS_AUTHENTICATED"},
    ],
  },
})

See Schema for the full set of possible configuration options.

Each request belongs to the first firewall matching it, which authenticates its user via the custom authenticators of the firewall, see ASEC::Authenticator::Interface. The users are loaded via the provider of the firewall, which defaults to the only configured provider. The access_control rules then require an attribute for the requests they match, e.g. a role.

Services inheriting from ASEC::Authorization::Voter are automatically used to decide the access of users, e.g. via the ASEC::Authorization::CheckerInterface service. Listeners of ASEC::Events handle the events of every firewall.