Completed
Pull Request — develop (#35)
by A.
03:37
created

AuthenticatedUser::getNameId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright 2015 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace OpenConext\Profile\Entity;
20
21
use OpenConext\Profile\Assert;
22
use Surfnet\SamlBundle\SAML2\Attribute\AttributeSet;
23
use Surfnet\SamlBundle\SAML2\Response\AssertionAdapter;
24
25
final class AuthenticatedUser
26
{
27
    /**
28
     * @var string
29
     */
30
    private $nameId;
31
32
    /**
33
     * @var AttributeSet
34
     */
35
    private $attributes;
36
37
    /**
38
     * @var array
39
     */
40
    private $authenticatingAuthorities;
41
42
    /**
43
     * @param AssertionAdapter $assertionAdapter
44
     * @param array $authenticatingAuthorities
45
     * @return AuthenticatedUser
46
     */
47
    public static function createFrom(AssertionAdapter $assertionAdapter, array $authenticatingAuthorities)
48
    {
49
        return new self(
50
            $assertionAdapter->getNameId(),
51
            $assertionAdapter->getAttributeSet(),
52
            $authenticatingAuthorities
53
        );
54
    }
55
56
    /**
57
     * @param string $nameId
58
     * @param AttributeSet $attributes
59
     * @param array $authenticatingAuthorities
60
     */
61
    private function __construct($nameId, AttributeSet $attributes, array $authenticatingAuthorities)
62
    {
63
        Assert::string($nameId);
64
65
        $this->nameId                    = $nameId;
66
        $this->attributes                = $attributes;
67
        $this->authenticatingAuthorities = $authenticatingAuthorities;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getNameId()
74
    {
75
        return $this->nameId;
76
    }
77
78
    /**
79
     * @return AttributeSet
80
     */
81
    public function getAttributes()
82
    {
83
        return $this->attributes;
84
    }
85
86
    /**
87
     * @return array
88
     */
89
    public function getAuthenticatingAuthorities()
90
    {
91
        return $this->authenticatingAuthorities;
92
    }
93
94
    /**
95
     * Using toString in order to comply with AbstractToken's setUser method,
96
     * which uses the string representation to detect changes in the user object.
97
     * Not implementing a UserInterface, because methods defined there will not be used.
98
     *
99
     * @return string
100
     */
101
    public function __toString()
102
    {
103
        return $this->nameId;
104
    }
105
}
106