|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2014 SURFnet bv |
|
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 Surfnet\StepupMiddlewareClientBundle\Identity\Dto; |
|
20
|
|
|
|
|
21
|
|
|
use Serializable; |
|
22
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Dto\Dto; |
|
23
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
24
|
|
|
|
|
25
|
|
|
class Identity implements Dto, Serializable |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @Assert\NotBlank(message="middleware_client.dto.identity.id.must_not_be_blank") |
|
29
|
|
|
* @Assert\Type(type="string", message="middleware_client.dto.identity.id.must_be_string") |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
public $id; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @Assert\NotBlank(message="middleware_client.dto.identity.name_id.must_not_be_blank") |
|
36
|
|
|
* @Assert\Type(type="string", message="middleware_client.dto.identity.name_id.must_be_string") |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
public $nameId; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @Assert\NotBlank(message="middleware_client.dto.identity.institution.must_not_be_blank") |
|
43
|
|
|
* @Assert\Type(type="string", message="middleware_client.dto.identity.institution.must_be_string") |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
public $institution; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @Assert\NotBlank(message="middleware_client.dto.identity.email.must_not_be_blank") |
|
50
|
|
|
* @Assert\Type(type="string", message="middleware_client.dto.identity.email.must_be_string") |
|
51
|
|
|
* @var string |
|
52
|
|
|
*/ |
|
53
|
|
|
public $email; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @Assert\NotBlank(message="middleware_client.dto.identity.common_name.must_not_be_blank") |
|
57
|
|
|
* @Assert\Type(type="string", message="middleware_client.dto.identity.common_name.must_be_string") |
|
58
|
|
|
* @var string |
|
59
|
|
|
*/ |
|
60
|
|
|
public $commonName; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @Assert\NotBlank(message="middleware_client.dto.identity.preferred_locale.must_not_be_blank") |
|
64
|
|
|
* @Assert\Type(type="string", message="middleware_client.dto.identity.preferred_locale.must_be_string") |
|
65
|
|
|
* @var string |
|
66
|
|
|
*/ |
|
67
|
|
|
public $preferredLocale; |
|
68
|
|
|
|
|
69
|
|
|
public static function fromData(array $data) |
|
70
|
|
|
{ |
|
71
|
|
|
$identity = new self(); |
|
72
|
|
|
$identity->id = $data['id']; |
|
73
|
|
|
$identity->nameId = $data['name_id']; |
|
74
|
|
|
$identity->institution = $data['institution']; |
|
75
|
|
|
$identity->email = $data['email']; |
|
76
|
|
|
$identity->commonName = $data['common_name']; |
|
77
|
|
|
$identity->preferredLocale = $data['preferred_locale']; |
|
78
|
|
|
|
|
79
|
|
|
return $identity; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Used so that we can serialize the Identity within the SAMLToken, so we can store the token in a session. |
|
84
|
|
|
* This to support persistent login |
|
85
|
|
|
* |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
public function serialize() |
|
89
|
|
|
{ |
|
90
|
|
|
return serialize( |
|
91
|
|
|
[ |
|
92
|
|
|
$this->id, |
|
93
|
|
|
$this->nameId, |
|
94
|
|
|
$this->institution, |
|
95
|
|
|
$this->email, |
|
96
|
|
|
$this->commonName, |
|
97
|
|
|
$this->preferredLocale |
|
98
|
|
|
] |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Used so that we can unserialize the Identity within the SAMLToken, so that it can be loaded from the session |
|
104
|
|
|
* for persistent login. |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $serialized |
|
107
|
|
|
*/ |
|
108
|
|
|
public function unserialize($serialized) |
|
109
|
|
|
{ |
|
110
|
|
|
list ( |
|
111
|
|
|
$this->id, |
|
112
|
|
|
$this->nameId, |
|
113
|
|
|
$this->institution, |
|
114
|
|
|
$this->email, |
|
115
|
|
|
$this->commonName, |
|
116
|
|
|
$this->preferredLocale |
|
117
|
|
|
) = unserialize($serialized); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* This is a requirement to be able to set the identity as user in the TokenInterface. |
|
122
|
|
|
* (so we can use it as user in SF) |
|
123
|
|
|
* |
|
124
|
|
|
* @return string |
|
125
|
|
|
*/ |
|
126
|
|
|
public function __toString() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->id; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|