Skip to content

Commit 98f42ea

Browse files
authored
Merge pull request #5 from fschmtt/attack-detection
Complement attack detection
2 parents 11bbc92 + 78fbd83 commit 98f42ea

File tree

3 files changed

+125
-58
lines changed

3 files changed

+125
-58
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ More examples can be found in the [examples](examples) directory.
4949
| Endpoint | Status Code | Response | API |
5050
|----------|-------------|----------|-----|
5151
| `DELETE /auth/admin/realms/{realm}/attack-detection/brute-force/users` | `204` | `n/a` | [AttackDetection::clear()](src/Resource/AttackDetection.php) |
52+
| `GET /auth/admin/realms/{realm}/attack-detection/brute-force/users/{userId}` | `204` | [Map](src/Type/Map.php) | [AttackDetection::user()](src/Resource/AttackDetection.php) |
53+
| `DELETE /auth/admin/realms/{realm}/attack-detection/brute-force/users/{userId}` | `204` | `n/a` | [AttackDetection::clearUser()](src/Resource/AttackDetection.php) |
5254

5355
### [Realms Admin](https://www.keycloak.org/docs-api/13.0/rest-api/index.html#_realms_admin_resource)
5456
| Endpoint | Status Code | Response | API |

src/Representation/User.php

+100-58
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,107 @@
44

55
namespace Fschmtt\Keycloak\Representation;
66

7+
use Fschmtt\Keycloak\Type\Map;
8+
9+
/**
10+
* @method Map|null getAccess()
11+
* @method Map|null getAttributes()
12+
* @method UserConsent[]|null getClientConsents()
13+
* @method Map|null getClientRoles()
14+
* @method int|null getCreatedTimestamp()
15+
* @method Credential[]|null getCredentials()
16+
* @method array|null getDisableableCredentialTypes()
17+
* @method string|null getEmail()
18+
* @method bool|null getEmailVerified()
19+
* @method bool|null getEnabled()
20+
* @method FederatedIdentity[]|null getFederatedIdentities()
21+
* @method string|null getFederationLink()
22+
* @method string|null getFirstName()
23+
* @method array|null getGroups()
24+
* @method string|null getId()
25+
* @method string|null getLastName()
26+
* @method int|null getNotBefore()
27+
* @method string|null getOrigin()
28+
* @method array|null getRealmRoles()
29+
* @method array|null getRequiredActions()
30+
* @method string|null getSelf()
31+
* @method string|null getServiceAccountClientId()
32+
* @method string|null getUsername()
33+
* @method self withAccess(?Map $access)
34+
* @method self withAttributes(?Map $attributes)
35+
* @method self withClientConsents(?array $clientConsents)
36+
* @method self withClientRoles(?array $clientRoles)
37+
* @method self withCreatedTimestamp(?int $createdTimestamp)
38+
* @method self withCredentials(?array $credentials)
39+
* @method self withDisableableCredentialTypes(?bool $disableableCredentialTypes)
40+
* @method self withEmail(?string $email)
41+
* @method self withEmailVerified(?bool $emailVerified)
42+
* @method self withEnabled(?bool $enabled)
43+
* @method self withFederatedIdentities(?array $federatedIdentites)
44+
* @method self withFederationLink(?string $federationLink)
45+
* @method self withFirstName(?string $firstName)
46+
* @method self withGroups(?array $groups)
47+
* @method self withId(?string $id)
48+
* @method self withLastName(?string $lastName)
49+
* @method self withNotBefore(?int $notBefore)
50+
* @method self withOrigin(?string $origin)
51+
* @method self withRealmRoles(?array $realmRoles)
52+
* @method self withRequiredActions(?array $requiredActions)
53+
* @method self withSelf(?string $self)
54+
* @method self withServiceAccountClientId(?string $serviceAccountClientId)
55+
* @method self withUsername(?string $username)
56+
*/
757
class User extends Representation
858
{
9-
protected ?array $access;
10-
11-
protected ?array $attributes;
12-
13-
/**
14-
* @var UserConsent[]|null
15-
*/
16-
protected ?array $clientConsents;
17-
18-
protected ?array $clientRoles;
19-
20-
protected ?int $createdTimestamp;
21-
22-
/**
23-
* @var Credential[]|null
24-
*/
25-
protected ?array $credentials;
26-
27-
protected ?array $disableableCredentialTypes;
28-
29-
protected ?string $email;
30-
31-
protected ?bool $emailVerified;
32-
33-
protected ?bool $enabled;
34-
35-
/**
36-
* @var FederatedIdentity[]|null
37-
*/
38-
protected ?array $federatedIdentities;
39-
40-
protected ?string $federationLink;
41-
42-
protected ?string $firstName;
43-
44-
protected ?array $groups;
45-
46-
protected ?string $id;
47-
48-
protected ?string $lastName;
49-
50-
protected ?int $notBefore;
51-
52-
protected ?string $origin;
53-
54-
protected $realmRoles;
55-
56-
protected ?array $requiredActions;
57-
58-
protected ?string $self;
59-
60-
protected ?string $serviceAccountClientId;
61-
62-
protected ?string $username;
63-
64-
public static function from(array $properties): static
65-
{
66-
return parent::from($properties); // TODO: Change the autogenerated stub
59+
public function __construct(
60+
protected ?Map $access = null,
61+
protected ?Map $attributes = null,
62+
protected ?array $clientConsents = null,
63+
protected ?Map $clientRoles = null,
64+
protected ?int $createdTimestamp = null,
65+
protected ?array $credentials = null,
66+
protected ?array $disableableCredentialTypes = null,
67+
protected ?string $email = null,
68+
protected ?bool $emailVerified = null,
69+
protected ?bool $enabled = null,
70+
protected ?array $federatedIdentities = null,
71+
protected ?string $federationLink = null,
72+
protected ?string $firstName = null,
73+
protected ?array $groups = null,
74+
protected ?string $id = null,
75+
protected ?string $lastName = null,
76+
protected ?int $notBefore = null,
77+
protected ?string $origin = null,
78+
protected ?array $realmRoles = null,
79+
protected ?array $requiredActions = null,
80+
protected ?string $self = null,
81+
protected ?string $serviceAccountClientId = null,
82+
protected ?string $username = null,
83+
) {
84+
parent::__construct(
85+
$access,
86+
$attributes,
87+
$clientConsents,
88+
$clientRoles,
89+
$createdTimestamp,
90+
$credentials,
91+
$disableableCredentialTypes,
92+
$email,
93+
$emailVerified,
94+
$enabled,
95+
$federatedIdentities,
96+
$federationLink,
97+
$firstName,
98+
$groups,
99+
$id,
100+
$lastName,
101+
$notBefore,
102+
$origin,
103+
$realmRoles,
104+
$requiredActions,
105+
$self,
106+
$serviceAccountClientId,
107+
$username,
108+
);
67109
}
68110
}

src/Resource/AttackDetection.php

+23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
namespace Fschmtt\Keycloak\Resource;
66

7+
use Fschmtt\Keycloak\Json\JsonDecoder;
78
use Fschmtt\Keycloak\Representation\Realm;
9+
use Fschmtt\Keycloak\Representation\User;
10+
use Fschmtt\Keycloak\Type\Map;
811

912
class AttackDetection extends Resource
1013
{
@@ -18,6 +21,26 @@ public function clear(Realm $realm): void
1821
);
1922
}
2023

24+
public function user(Realm $realm, User $user): Map
25+
{
26+
return new Map(
27+
(new JsonDecoder())->decode(
28+
(string) $this->httpClient->request(
29+
'GET',
30+
sprintf('%s/%s', $this->replaceRealmInBasePath($realm->getRealm()), $user->getId())
31+
)->getBody()
32+
)
33+
);
34+
}
35+
36+
public function clearUser(Realm $realm, User $user): void
37+
{
38+
$this->httpClient->request(
39+
'DELETE',
40+
sprintf('%s/%s', $this->replaceRealmInBasePath($realm->getRealm()), $user->getId())
41+
);
42+
}
43+
2144
private function replaceRealmInBasePath(string $realm): string
2245
{
2346
return str_replace(

0 commit comments

Comments
 (0)