Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
15 / 18
88.24% covered (warning)
88.24%
15 / 17
86.67% covered (warning)
86.67%
13 / 15
85.71% covered (warning)
85.71%
12 / 14
CRAP
0.00% covered (danger)
0.00%
0 / 1
User
83.33% covered (warning)
83.33%
15 / 18
88.24% covered (warning)
88.24%
15 / 17
86.67% covered (warning)
86.67%
13 / 15
92.86% covered (success)
92.86%
13 / 14
15.53
0.00% covered (danger)
0.00%
0 / 1
 setSamlAttributes
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setEnvAttributes
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUserIdentifier
100.00% covered (success)
100.00%
1 / 1
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
2.50
 getGinaRoles
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFirstName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFullName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEmail
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAttributes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAuthentificationMethode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasLogout
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRoles
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setRoles
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 eraseCredentials
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Security;
4
5use Nbgrp\OneloginSamlBundle\Security\User\SamlUserInterface;
6
7class User implements SamlUserInterface
8{
9    // definition saml2 attribut name
10    public const string USERNAME = 'Login';
11    public const string ROLES = 'Roles';
12    public const string FULLNAME = 'FullName';
13    public const string FIRSTNAME = 'Firstname';
14    public const string NAME = 'Name';
15    public const string EMAIL = 'Email';
16
17    public const string AUTHENTIFICATION_SAML = 'SAML2';
18    public const string AUTHENTIFICATION_ENV_VAR = 'ENV VAR';
19    public string $authentificationMethode;
20    /** @var array<string, list<string|null>> */
21    protected array $attributes = [];
22    protected string $userIdentifier;
23
24    /**
25     * @var string[]
26     */
27    protected array $roles = [];
28
29    /**
30     * @param array<string, list<string>> $attributes
31     */
32    public function setSamlAttributes(array $attributes): void
33    {
34        $this->authentificationMethode = self::AUTHENTIFICATION_SAML;
35        $this->attributes = $attributes;
36        $this->userIdentifier = (string) mb_strtoupper($attributes[self::USERNAME][0] ?? '');
37    }
38
39    /**
40     * @param array<string, list<string>> $attributes
41     */
42    public function setEnvAttributes(array $attributes): void
43    {
44        $this->authentificationMethode = self::AUTHENTIFICATION_ENV_VAR;
45        $this->attributes = $attributes;
46        $this->userIdentifier = (string) mb_strtoupper($attributes[self::USERNAME][0] ?? '');
47    }
48
49    public function getUserIdentifier(): string
50    {
51        return '' === $this->userIdentifier ? '?' : $this->userIdentifier;
52    }
53
54    /**
55     * @return array<int,string|null>
56     */
57    public function getGinaRoles(): array
58    {
59        return $this->attributes[self::ROLES] ?? [];
60    }
61
62    public function getName(): ?string
63    {
64        return $this->attributes[self::NAME][0] ?? null;
65    }
66
67    public function getFirstName(): ?string
68    {
69        return $this->attributes[self::FIRSTNAME][0] ?? null;
70    }
71
72    public function getFullName(): ?string
73    {
74        return $this->attributes[self::FULLNAME][0] ?? null;
75    }
76
77    public function getEmail(): ?string
78    {
79        return $this->attributes[self::EMAIL][0] ?? null;
80    }
81
82    /**
83     * @return array<string,list<string|null>>
84     */
85    public function getAttributes(): array
86    {
87        return $this->attributes;
88    }
89
90    public function getAuthentificationMethode(): string
91    {
92        return $this->authentificationMethode;
93    }
94
95    public function hasLogout(): bool
96    {
97        return self::AUTHENTIFICATION_SAML === $this->authentificationMethode;
98    }
99
100    /**
101     * @return string[]
102     */
103    public function getRoles(): array
104    {
105        return $this->roles;
106    }
107
108    /**
109     * @param string[] $roles
110     */
111    public function setRoles(array $roles): void
112    {
113        $this->roles = $roles;
114    }
115
116    public function eraseCredentials(): void
117    {
118        // not used
119    }
120}