Completed
Push — develop ( 511001...8b4d6d )
by A.
03:05
created

AuthenticatedUser::__toString()   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
     * @param AssertionAdapter $assertionAdapter
39
     * @return AuthenticatedUser
40
     */
41
    public static function createFrom(AssertionAdapter $assertionAdapter)
42
    {
43
        return new self($assertionAdapter->getNameId(), $assertionAdapter->getAttributeSet());
44
    }
45
46
    /**
47
     * @param string $nameId
48
     * @param AttributeSet $attributes
49
     */
50
    private function __construct($nameId, AttributeSet $attributes)
51
    {
52
        Assert::string($nameId);
53
54
        $this->nameId = $nameId;
55
        $this->attributes = $attributes;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getNameId()
62
    {
63
        return $this->nameId;
64
    }
65
66
    /**
67
     * @return AttributeSet
68
     */
69
    public function getAttributes()
70
    {
71
        return $this->attributes;
72
    }
73
74
    /**
75
     * Using toString in order to comply with AbstractToken's setUser method,
76
     * which uses the string representation to detect changes in the user object.
77
     * Not implementing a UserInterface, because methods defined there will not be used.
78
     *
79
     * @return string
80
     */
81
    public function __toString()
82
    {
83
        return $this->nameId;
84
    }
85
}
86