Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c734a7ed9 |
@@ -5,7 +5,6 @@ namespace ABEL\Bundle\keycloakBearerOnlyAdapterBundle;
|
|||||||
|
|
||||||
|
|
||||||
use ABEL\Bundle\keycloakBearerOnlyAdapterBundle\DependencyInjection\ABELkeycloakBearerOnlyAdapterExtension;
|
use ABEL\Bundle\keycloakBearerOnlyAdapterBundle\DependencyInjection\ABELkeycloakBearerOnlyAdapterExtension;
|
||||||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
|
||||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||||
|
|
||||||
class ABELkeycloakBearerOnlyAdapterBundle extends Bundle
|
class ABELkeycloakBearerOnlyAdapterBundle extends Bundle
|
||||||
@@ -13,7 +12,7 @@ class ABELkeycloakBearerOnlyAdapterBundle extends Bundle
|
|||||||
/**
|
/**
|
||||||
* @return ExtensionInterface|null
|
* @return ExtensionInterface|null
|
||||||
*/
|
*/
|
||||||
public function getContainerExtension(): ?ExtensionInterface
|
public function getContainerExtension()
|
||||||
{
|
{
|
||||||
if (null === $this->extension) {
|
if (null === $this->extension) {
|
||||||
$this->extension = new ABELkeycloakBearerOnlyAdapterExtension();
|
$this->extension = new ABELkeycloakBearerOnlyAdapterExtension();
|
||||||
|
|||||||
@@ -5,25 +5,21 @@ namespace ABEL\Bundle\keycloakBearerOnlyAdapterBundle\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||||
|
|
||||||
class ABELkeycloakBearerOnlyAdapterExtension extends Extension
|
class ABELkeycloakBearerOnlyAdapterExtension extends Extension
|
||||||
{
|
{
|
||||||
|
|
||||||
public function load(array $configs, ContainerBuilder $container): void
|
public function load(array $configs, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$loader = new PhpFileLoader(
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||||
$container,
|
$loader->load('services.xml');
|
||||||
new FileLocator(__DIR__ . '/../Resources/config')
|
|
||||||
);
|
|
||||||
$loader->load('services.php');
|
|
||||||
|
|
||||||
$configuration = $this->getConfiguration($configs, $container);
|
$configuration = $this->getConfiguration($configs, $container);
|
||||||
$config = $this->processConfiguration($configuration, $configs);
|
$config = $this->processConfiguration($configuration, $configs);
|
||||||
|
|
||||||
$definition = $container->getDefinition('abel_keycloak_bearer_only_adapter.keycloak_bearer_user_provider');
|
$definition = $container->getDefinition('abel_keycloak_bearer_only_adapter.keycloak_bearer_user_provider');
|
||||||
|
|
||||||
$definition->replaceArgument(0, $config['issuer']);
|
$definition->replaceArgument(0, $config['issuer']);
|
||||||
$definition->replaceArgument(1, $config['realm']);
|
$definition->replaceArgument(1, $config['realm']);
|
||||||
$definition->replaceArgument(2, $config['client_id']);
|
$definition->replaceArgument(2, $config['client_id']);
|
||||||
@@ -31,7 +27,7 @@ class ABELkeycloakBearerOnlyAdapterExtension extends Extension
|
|||||||
$definition->replaceArgument(4, $config['ssl_verification']);
|
$definition->replaceArgument(4, $config['ssl_verification']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAlias(): string
|
public function getAlias()
|
||||||
{
|
{
|
||||||
return 'abel_keycloak_bearer_only_adapter';
|
return 'abel_keycloak_bearer_only_adapter';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
|
|||||||
class Configuration implements ConfigurationInterface
|
class Configuration implements ConfigurationInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public function getConfigTreeBuilder(): TreeBuilder
|
public function getConfigTreeBuilder()
|
||||||
{
|
{
|
||||||
$treeBuilder = new TreeBuilder("abel_keycloak_bearer_only_adapter");
|
$treeBuilder = new TreeBuilder("abel_keycloak_bearer_only_adapter");
|
||||||
|
|
||||||
|
|||||||
@@ -56,11 +56,6 @@ OAUTH_KEYCLOAK_CLIENT_SECRET=my_bearer_client_secret
|
|||||||
###< Abel_keycloak_bearer_only_adapter ###
|
###< Abel_keycloak_bearer_only_adapter ###
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
> Since Keycloak 17 the default distribution is now powered by **Quarkus**, while the legacy **WildFly** powered distribution will still be around until June 2022 <br>
|
|
||||||
> The new distribution introduces a number of breaking changes, including: <br>
|
|
||||||
> - `/auth` removed from the default context path <br>
|
|
||||||
> ⚠️ **If you are using a legacy version make sure to include /auth in OAUTH_KEYCLOAK_ISSUER** <br>
|
|
||||||
> Example: `keycloak:8080/auth`
|
|
||||||
|
|
||||||
In case of using Keycloak with Docker locally replace **issuer** value with your keycloak container reference in the network
|
In case of using Keycloak with Docker locally replace **issuer** value with your keycloak container reference in the network
|
||||||
|
|
||||||
@@ -108,4 +103,3 @@ To configure keycloak to work with this bundle, [here](./Resources/docs/keycloak
|
|||||||
| V1.0.1 | >=4.0.0 <5.0.0 |
|
| V1.0.1 | >=4.0.0 <5.0.0 |
|
||||||
| V1.1.* (uses old authentication systeme with guard) | >=5.0.0 <6.0.0 |
|
| V1.1.* (uses old authentication systeme with guard) | >=5.0.0 <6.0.0 |
|
||||||
| V1.2.* (uses new authentication systeme) | >=5.3.0 <6.0.0 |
|
| V1.2.* (uses new authentication systeme) | >=5.3.0 <6.0.0 |
|
||||||
| V1.3.* | >=6.0.0 <7.0.0 |
|
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
|
||||||
use ABEL\Bundle\keycloakBearerOnlyAdapterBundle\Security\User\KeycloakBearerUserProvider;
|
|
||||||
|
|
||||||
return static function (ContainerConfigurator $configurator): void {
|
|
||||||
$services = $configurator->services();
|
|
||||||
|
|
||||||
$services
|
|
||||||
->defaults()
|
|
||||||
->autowire()
|
|
||||||
->autoconfigure();
|
|
||||||
|
|
||||||
$services->load('ABEL\\Bundle\\keycloakBearerOnlyAdapterBundle\\', '../../*')
|
|
||||||
->exclude('../../{Entity,Migrations,Tests}');
|
|
||||||
|
|
||||||
// empty args → will be replaced later
|
|
||||||
$services->set('abel_keycloak_bearer_only_adapter.keycloak_bearer_user_provider', KeycloakBearerUserProvider::class)
|
|
||||||
->args([null, null, null, null, null]);
|
|
||||||
|
|
||||||
$services->alias(
|
|
||||||
KeycloakBearerUserProvider::class,
|
|
||||||
'abel_keycloak_bearer_only_adapter.keycloak_bearer_user_provider'
|
|
||||||
);
|
|
||||||
};
|
|
||||||
26
Resources/config/services.xml
Normal file
26
Resources/config/services.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<container xmlns="http://symfony.com/schema/dic/services"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/dic/services
|
||||||
|
https://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||||
|
|
||||||
|
<services>
|
||||||
|
<!-- Default configuration for services in *this* file -->
|
||||||
|
<defaults autowire="true" autoconfigure="true"/>
|
||||||
|
|
||||||
|
<!-- makes classes available to be used as services -->
|
||||||
|
<!-- this creates a service per class whose id is the fully-qualified class name -->
|
||||||
|
<prototype namespace="ABEL\Bundle\keycloakBearerOnlyAdapterBundle\" resource="../../*" exclude="../../{Entity,Migrations,Tests}"/>
|
||||||
|
|
||||||
|
<service id="abel_keycloak_bearer_only_adapter.keycloak_bearer_user_provider" class="ABEL\Bundle\keycloakBearerOnlyAdapterBundle\Security\User\KeycloakBearerUserProvider">
|
||||||
|
<argument/>
|
||||||
|
<argument/>
|
||||||
|
<argument/>
|
||||||
|
<argument/>
|
||||||
|
<argument/>
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<service id="ABEL\Bundle\keycloakBearerOnlyAdapterBundle\Security\User\KeycloakBearerUserProvider" alias="abel_keycloak_bearer_only_adapter.keycloak_bearer_user_provider" />
|
||||||
|
|
||||||
|
</services>
|
||||||
|
</container>
|
||||||
@@ -6,7 +6,7 @@ namespace ABEL\Bundle\keycloakBearerOnlyAdapterBundle\Security\User;
|
|||||||
|
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
|
||||||
class KeycloakBearerUser implements UserInterface
|
class KeycloakBearerUser implements UserInterface, \Serializable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
@@ -202,7 +202,7 @@ class KeycloakBearerUser implements UserInterface
|
|||||||
*
|
*
|
||||||
* @return array (Role|string)[] The user roles
|
* @return array (Role|string)[] The user roles
|
||||||
*/
|
*/
|
||||||
public function getRoles(): array
|
public function getRoles()
|
||||||
{
|
{
|
||||||
return $this->roles;
|
return $this->roles;
|
||||||
}
|
}
|
||||||
@@ -258,11 +258,8 @@ class KeycloakBearerUser implements UserInterface
|
|||||||
*
|
*
|
||||||
* This is important if, at any given point, sensitive information like
|
* This is important if, at any given point, sensitive information like
|
||||||
* the plain-text password is stored on this object.
|
* the plain-text password is stored on this object.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
#[\Deprecated]
|
public function eraseCredentials()
|
||||||
public function eraseCredentials(): void
|
|
||||||
{
|
{
|
||||||
// TODO: Implement eraseCredentials() method.
|
// TODO: Implement eraseCredentials() method.
|
||||||
}
|
}
|
||||||
@@ -273,7 +270,7 @@ class KeycloakBearerUser implements UserInterface
|
|||||||
* @return string the string representation of the object or null
|
* @return string the string representation of the object or null
|
||||||
* @since 5.1.0
|
* @since 5.1.0
|
||||||
*/
|
*/
|
||||||
public function __serialize()
|
public function serialize()
|
||||||
{
|
{
|
||||||
return serialize(array(
|
return serialize(array(
|
||||||
$this->sub,
|
$this->sub,
|
||||||
@@ -296,7 +293,7 @@ class KeycloakBearerUser implements UserInterface
|
|||||||
* @return void
|
* @return void
|
||||||
* @since 5.1.0
|
* @since 5.1.0
|
||||||
*/
|
*/
|
||||||
public function __unserialize($serialized)
|
public function unserialize($serialized)
|
||||||
{
|
{
|
||||||
list (
|
list (
|
||||||
$this->sub,
|
$this->sub,
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class KeycloakBearerUserProvider implements UserProviderInterface{
|
|||||||
* @param string $class
|
* @param string $class
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function supportsClass(string $class): bool
|
public function supportsClass(string $class)
|
||||||
{
|
{
|
||||||
return KeycloakBearerUser::class === $class || is_subclass_of($class, KeycloakBearerUser::class);
|
return KeycloakBearerUser::class === $class || is_subclass_of($class, KeycloakBearerUser::class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
{
|
{
|
||||||
"name": "tothbt/keycloak-adapter-bundle",
|
"name": "abel/keycloak-bearer-only-adapter-bundle",
|
||||||
"description": "Keycloak security adapter for bearer only clients",
|
"description": "Keycloak security adapter for bearer only clients",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "symfony-bundle",
|
"type": "symfony-bundle",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Richard Toth",
|
"name": "Abdellah Elmakhroubi",
|
||||||
"email": "info@totbt.com"
|
"email": "abdellah.elmakhroubi@gmail.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.3",
|
"php": ">=7.2.5",
|
||||||
"symfony/config": "^6.0 || ^7.0",
|
"symfony/config": "^5.3",
|
||||||
"symfony/dependency-injection": "^6.0 || ^7.0",
|
"symfony/dependency-injection": "^5.3",
|
||||||
"symfony/http-kernel": "^6.0 || ^7.0",
|
"symfony/http-kernel": "^5.3",
|
||||||
"symfony/security-bundle": "^6.0 || ^7.0",
|
"symfony/security-bundle": "^5.3",
|
||||||
"guzzlehttp/guzzle": "^7",
|
"guzzlehttp/guzzle": "^6.3",
|
||||||
"ext-json": "*"
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
Reference in New Issue
Block a user