| @@ 34-162 (lines=129) @@ | ||
| 31 | use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable; |
|
| 32 | use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData; |
|
| 33 | ||
| 34 | class PhonePossessionProvenAndVerifiedEvent extends IdentityEvent implements Forgettable, PossessionProvenAndVerified |
|
| 35 | { |
|
| 36 | /** |
|
| 37 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorId |
|
| 38 | */ |
|
| 39 | public $secondFactorId; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * @var \Surfnet\Stepup\Identity\Value\PhoneNumber |
|
| 43 | */ |
|
| 44 | public $phoneNumber; |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @var \Surfnet\Stepup\Identity\Value\CommonName |
|
| 48 | */ |
|
| 49 | public $commonName; |
|
| 50 | ||
| 51 | /** |
|
| 52 | * @var \Surfnet\Stepup\Identity\Value\Email |
|
| 53 | */ |
|
| 54 | public $email; |
|
| 55 | ||
| 56 | /** |
|
| 57 | * @var \Surfnet\Stepup\Identity\Value\Locale Eg. "en_GB" |
|
| 58 | */ |
|
| 59 | public $preferredLocale; |
|
| 60 | ||
| 61 | /** |
|
| 62 | * @var \Surfnet\Stepup\DateTime\DateTime |
|
| 63 | */ |
|
| 64 | public $registrationRequestedAt; |
|
| 65 | ||
| 66 | /** |
|
| 67 | * @var string |
|
| 68 | */ |
|
| 69 | public $registrationCode; |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param IdentityId $identityId |
|
| 73 | * @param Institution $identityInstitution |
|
| 74 | * @param SecondFactorId $secondFactorId |
|
| 75 | * @param PhoneNumber $phoneNumber |
|
| 76 | * @param CommonName $commonName |
|
| 77 | * @param Email $email |
|
| 78 | * @param Locale $locale |
|
| 79 | * @param DateTime $registrationRequestedAt |
|
| 80 | * @param string $registrationCode |
|
| 81 | */ |
|
| 82 | public function __construct( |
|
| 83 | IdentityId $identityId, |
|
| 84 | Institution $identityInstitution, |
|
| 85 | SecondFactorId $secondFactorId, |
|
| 86 | PhoneNumber $phoneNumber, |
|
| 87 | CommonName $commonName, |
|
| 88 | Email $email, |
|
| 89 | Locale $locale, |
|
| 90 | DateTime $registrationRequestedAt, |
|
| 91 | $registrationCode |
|
| 92 | ) { |
|
| 93 | parent::__construct($identityId, $identityInstitution); |
|
| 94 | ||
| 95 | $this->secondFactorId = $secondFactorId; |
|
| 96 | $this->phoneNumber = $phoneNumber; |
|
| 97 | $this->commonName = $commonName; |
|
| 98 | $this->email = $email; |
|
| 99 | $this->preferredLocale = $locale; |
|
| 100 | $this->registrationRequestedAt = $registrationRequestedAt; |
|
| 101 | $this->registrationCode = $registrationCode; |
|
| 102 | } |
|
| 103 | ||
| 104 | public function getAuditLogMetadata() |
|
| 105 | { |
|
| 106 | $metadata = new Metadata(); |
|
| 107 | $metadata->identityId = $this->identityId; |
|
| 108 | $metadata->identityInstitution = $this->identityInstitution; |
|
| 109 | $metadata->secondFactorId = $this->secondFactorId; |
|
| 110 | $metadata->secondFactorType = new SecondFactorType('sms'); |
|
| 111 | $metadata->secondFactorIdentifier = $this->phoneNumber; |
|
| 112 | ||
| 113 | return $metadata; |
|
| 114 | } |
|
| 115 | ||
| 116 | public static function deserialize(array $data) |
|
| 117 | { |
|
| 118 | // BC compatibility for event replay in test-environment only (2.8.0, fixed in 2.8.1) |
|
| 119 | if (!isset($data['preferred_locale'])) { |
|
| 120 | $data['preferred_locale'] = 'en_GB'; |
|
| 121 | } |
|
| 122 | ||
| 123 | return new self( |
|
| 124 | new IdentityId($data['identity_id']), |
|
| 125 | new Institution($data['identity_institution']), |
|
| 126 | new SecondFactorId($data['second_factor_id']), |
|
| 127 | PhoneNumber::unknown(), |
|
| 128 | CommonName::unknown(), |
|
| 129 | Email::unknown(), |
|
| 130 | new Locale($data['preferred_locale']), |
|
| 131 | DateTime::fromString($data['registration_requested_at']), |
|
| 132 | (string) $data['registration_code'] |
|
| 133 | ); |
|
| 134 | } |
|
| 135 | ||
| 136 | public function serialize() |
|
| 137 | { |
|
| 138 | return [ |
|
| 139 | 'identity_id' => (string) $this->identityId, |
|
| 140 | 'identity_institution' => (string) $this->identityInstitution, |
|
| 141 | 'second_factor_id' => (string) $this->secondFactorId, |
|
| 142 | 'registration_requested_at' => (string) $this->registrationRequestedAt, |
|
| 143 | 'registration_code' => $this->registrationCode, |
|
| 144 | 'preferred_locale' => (string) $this->preferredLocale, |
|
| 145 | ]; |
|
| 146 | } |
|
| 147 | ||
| 148 | public function getSensitiveData() |
|
| 149 | { |
|
| 150 | return (new SensitiveData) |
|
| 151 | ->withCommonName($this->commonName) |
|
| 152 | ->withEmail($this->email) |
|
| 153 | ->withSecondFactorIdentifier($this->phoneNumber, new SecondFactorType('sms')); |
|
| 154 | } |
|
| 155 | ||
| 156 | public function setSensitiveData(SensitiveData $sensitiveData) |
|
| 157 | { |
|
| 158 | $this->phoneNumber = $sensitiveData->getSecondFactorIdentifier(); |
|
| 159 | $this->email = $sensitiveData->getEmail(); |
|
| 160 | $this->commonName = $sensitiveData->getCommonName(); |
|
| 161 | } |
|
| 162 | } |
|
| 163 | ||
| @@ 34-162 (lines=129) @@ | ||
| 31 | use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable; |
|
| 32 | use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData; |
|
| 33 | ||
| 34 | class U2fDevicePossessionProvenAndVerifiedEvent extends IdentityEvent implements Forgettable, PossessionProvenAndVerified |
|
| 35 | { |
|
| 36 | /** |
|
| 37 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorId |
|
| 38 | */ |
|
| 39 | public $secondFactorId; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * @var \Surfnet\Stepup\Identity\Value\U2fKeyHandle |
|
| 43 | */ |
|
| 44 | public $keyHandle; |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @var \Surfnet\Stepup\Identity\Value\CommonName |
|
| 48 | */ |
|
| 49 | public $commonName; |
|
| 50 | ||
| 51 | /** |
|
| 52 | * @var \Surfnet\Stepup\Identity\Value\Email |
|
| 53 | */ |
|
| 54 | public $email; |
|
| 55 | ||
| 56 | /** |
|
| 57 | * @var \Surfnet\Stepup\Identity\Value\Locale Eg. "en_GB" |
|
| 58 | */ |
|
| 59 | public $preferredLocale; |
|
| 60 | ||
| 61 | /** |
|
| 62 | * @var \Surfnet\Stepup\DateTime\DateTime |
|
| 63 | */ |
|
| 64 | public $registrationRequestedAt; |
|
| 65 | ||
| 66 | /** |
|
| 67 | * @var string |
|
| 68 | */ |
|
| 69 | public $registrationCode; |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param IdentityId $identityId |
|
| 73 | * @param Institution $identityInstitution |
|
| 74 | * @param SecondFactorId $secondFactorId |
|
| 75 | * @param U2fKeyHandle $keyHandle |
|
| 76 | * @param CommonName $commonName |
|
| 77 | * @param Email $email |
|
| 78 | * @param Locale $locale |
|
| 79 | * @param DateTime $registrationRequestedAt |
|
| 80 | * @param string $registrationCode |
|
| 81 | */ |
|
| 82 | public function __construct( |
|
| 83 | IdentityId $identityId, |
|
| 84 | Institution $identityInstitution, |
|
| 85 | SecondFactorId $secondFactorId, |
|
| 86 | U2fKeyHandle $keyHandle, |
|
| 87 | CommonName $commonName, |
|
| 88 | Email $email, |
|
| 89 | Locale $locale, |
|
| 90 | DateTime $registrationRequestedAt, |
|
| 91 | $registrationCode |
|
| 92 | ) { |
|
| 93 | parent::__construct($identityId, $identityInstitution); |
|
| 94 | ||
| 95 | $this->secondFactorId = $secondFactorId; |
|
| 96 | $this->keyHandle = $keyHandle; |
|
| 97 | $this->commonName = $commonName; |
|
| 98 | $this->email = $email; |
|
| 99 | $this->preferredLocale = $locale; |
|
| 100 | $this->registrationRequestedAt = $registrationRequestedAt; |
|
| 101 | $this->registrationCode = $registrationCode; |
|
| 102 | } |
|
| 103 | ||
| 104 | public function getAuditLogMetadata() |
|
| 105 | { |
|
| 106 | $metadata = new Metadata(); |
|
| 107 | $metadata->identityId = $this->identityId; |
|
| 108 | $metadata->identityInstitution = $this->identityInstitution; |
|
| 109 | $metadata->secondFactorId = $this->secondFactorId; |
|
| 110 | $metadata->secondFactorType = new SecondFactorType('sms'); |
|
| 111 | $metadata->secondFactorIdentifier = $this->keyHandle; |
|
| 112 | ||
| 113 | return $metadata; |
|
| 114 | } |
|
| 115 | ||
| 116 | public static function deserialize(array $data) |
|
| 117 | { |
|
| 118 | // BC compatibility for event replay in test-environment only (2.8.0, fixed in 2.8.1) |
|
| 119 | if (!isset($data['preferred_locale'])) { |
|
| 120 | $data['preferred_locale'] = 'en_GB'; |
|
| 121 | } |
|
| 122 | ||
| 123 | return new self( |
|
| 124 | new IdentityId($data['identity_id']), |
|
| 125 | new Institution($data['identity_institution']), |
|
| 126 | new SecondFactorId($data['second_factor_id']), |
|
| 127 | U2fKeyHandle::unknown(), |
|
| 128 | CommonName::unknown(), |
|
| 129 | Email::unknown(), |
|
| 130 | new Locale($data['preferred_locale']), |
|
| 131 | DateTime::fromString($data['registration_requested_at']), |
|
| 132 | (string) $data['registration_code'] |
|
| 133 | ); |
|
| 134 | } |
|
| 135 | ||
| 136 | public function serialize() |
|
| 137 | { |
|
| 138 | return [ |
|
| 139 | 'identity_id' => (string) $this->identityId, |
|
| 140 | 'identity_institution' => (string) $this->identityInstitution, |
|
| 141 | 'second_factor_id' => (string) $this->secondFactorId, |
|
| 142 | 'registration_requested_at' => (string) $this->registrationRequestedAt, |
|
| 143 | 'registration_code' => $this->registrationCode, |
|
| 144 | 'preferred_locale' => (string) $this->preferredLocale, |
|
| 145 | ]; |
|
| 146 | } |
|
| 147 | ||
| 148 | public function getSensitiveData() |
|
| 149 | { |
|
| 150 | return (new SensitiveData) |
|
| 151 | ->withCommonName($this->commonName) |
|
| 152 | ->withEmail($this->email) |
|
| 153 | ->withSecondFactorIdentifier($this->keyHandle, new SecondFactorType('u2f')); |
|
| 154 | } |
|
| 155 | ||
| 156 | public function setSensitiveData(SensitiveData $sensitiveData) |
|
| 157 | { |
|
| 158 | $this->keyHandle = $sensitiveData->getSecondFactorIdentifier(); |
|
| 159 | $this->email = $sensitiveData->getEmail(); |
|
| 160 | $this->commonName = $sensitiveData->getCommonName(); |
|
| 161 | } |
|
| 162 | } |
|
| 163 | ||
| @@ 34-164 (lines=131) @@ | ||
| 31 | use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable; |
|
| 32 | use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData; |
|
| 33 | ||
| 34 | class YubikeyPossessionProvenAndVerifiedEvent extends IdentityEvent implements Forgettable, PossessionProvenAndVerified |
|
| 35 | { |
|
| 36 | /** |
|
| 37 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorId |
|
| 38 | */ |
|
| 39 | public $secondFactorId; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * The Yubikey's public ID. |
|
| 43 | * |
|
| 44 | * @var \Surfnet\Stepup\Identity\Value\YubikeyPublicId |
|
| 45 | */ |
|
| 46 | public $yubikeyPublicId; |
|
| 47 | ||
| 48 | /** |
|
| 49 | * @var \Surfnet\Stepup\Identity\Value\CommonName |
|
| 50 | */ |
|
| 51 | public $commonName; |
|
| 52 | ||
| 53 | /** |
|
| 54 | * @var \Surfnet\Stepup\Identity\Value\Email |
|
| 55 | */ |
|
| 56 | public $email; |
|
| 57 | ||
| 58 | /** |
|
| 59 | * @var \Surfnet\Stepup\Identity\Value\Locale Eg. "en_GB" |
|
| 60 | */ |
|
| 61 | public $preferredLocale; |
|
| 62 | ||
| 63 | /** |
|
| 64 | * @var \Surfnet\Stepup\DateTime\DateTime |
|
| 65 | */ |
|
| 66 | public $registrationRequestedAt; |
|
| 67 | ||
| 68 | /** |
|
| 69 | * @var string |
|
| 70 | */ |
|
| 71 | public $registrationCode; |
|
| 72 | ||
| 73 | /** |
|
| 74 | * @param IdentityId $identityId |
|
| 75 | * @param Institution $institution |
|
| 76 | * @param SecondFactorId $secondFactorId |
|
| 77 | * @param YubikeyPublicId $yubikeyPublicId |
|
| 78 | * @param CommonName $commonName |
|
| 79 | * @param Email $email |
|
| 80 | * @param Locale $locale |
|
| 81 | * @param DateTime $registrationRequestedAt |
|
| 82 | * @param string $registrationCode |
|
| 83 | */ |
|
| 84 | public function __construct( |
|
| 85 | IdentityId $identityId, |
|
| 86 | Institution $institution, |
|
| 87 | SecondFactorId $secondFactorId, |
|
| 88 | YubikeyPublicId $yubikeyPublicId, |
|
| 89 | CommonName $commonName, |
|
| 90 | Email $email, |
|
| 91 | Locale $locale, |
|
| 92 | DateTime $registrationRequestedAt, |
|
| 93 | $registrationCode |
|
| 94 | ) { |
|
| 95 | parent::__construct($identityId, $institution); |
|
| 96 | ||
| 97 | $this->secondFactorId = $secondFactorId; |
|
| 98 | $this->yubikeyPublicId = $yubikeyPublicId; |
|
| 99 | $this->commonName = $commonName; |
|
| 100 | $this->email = $email; |
|
| 101 | $this->preferredLocale = $locale; |
|
| 102 | $this->registrationRequestedAt = $registrationRequestedAt; |
|
| 103 | $this->registrationCode = $registrationCode; |
|
| 104 | } |
|
| 105 | ||
| 106 | public function getAuditLogMetadata() |
|
| 107 | { |
|
| 108 | $metadata = new Metadata(); |
|
| 109 | $metadata->identityId = $this->identityId; |
|
| 110 | $metadata->identityInstitution = $this->identityInstitution; |
|
| 111 | $metadata->secondFactorId = $this->secondFactorId; |
|
| 112 | $metadata->secondFactorType = new SecondFactorType('yubikey'); |
|
| 113 | $metadata->secondFactorIdentifier = $this->yubikeyPublicId; |
|
| 114 | ||
| 115 | return $metadata; |
|
| 116 | } |
|
| 117 | ||
| 118 | public static function deserialize(array $data) |
|
| 119 | { |
|
| 120 | // BC compatibility for event replay in test-environment only (2.8.0, fixed in 2.8.1) |
|
| 121 | if (!isset($data['preferred_locale'])) { |
|
| 122 | $data['preferred_locale'] = 'en_GB'; |
|
| 123 | } |
|
| 124 | ||
| 125 | return new self( |
|
| 126 | new IdentityId($data['identity_id']), |
|
| 127 | new Institution($data['identity_institution']), |
|
| 128 | new SecondFactorId($data['second_factor_id']), |
|
| 129 | YubikeyPublicId::unknown(), |
|
| 130 | CommonName::unknown(), |
|
| 131 | Email::unknown(), |
|
| 132 | new Locale($data['preferred_locale']), |
|
| 133 | DateTime::fromString($data['registration_requested_at']), |
|
| 134 | (string) $data['registration_code'] |
|
| 135 | ); |
|
| 136 | } |
|
| 137 | ||
| 138 | public function serialize() |
|
| 139 | { |
|
| 140 | return [ |
|
| 141 | 'identity_id' => (string) $this->identityId, |
|
| 142 | 'identity_institution' => (string) $this->identityInstitution, |
|
| 143 | 'second_factor_id' => (string) $this->secondFactorId, |
|
| 144 | 'registration_requested_at' => (string) $this->registrationRequestedAt, |
|
| 145 | 'registration_code' => $this->registrationCode, |
|
| 146 | 'preferred_locale' => (string) $this->preferredLocale, |
|
| 147 | ]; |
|
| 148 | } |
|
| 149 | ||
| 150 | public function getSensitiveData() |
|
| 151 | { |
|
| 152 | return (new SensitiveData) |
|
| 153 | ->withCommonName($this->commonName) |
|
| 154 | ->withEmail($this->email) |
|
| 155 | ->withSecondFactorIdentifier($this->yubikeyPublicId, new SecondFactorType('yubikey')); |
|
| 156 | } |
|
| 157 | ||
| 158 | public function setSensitiveData(SensitiveData $sensitiveData) |
|
| 159 | { |
|
| 160 | $this->yubikeyPublicId = $sensitiveData->getSecondFactorIdentifier(); |
|
| 161 | $this->email = $sensitiveData->getEmail(); |
|
| 162 | $this->commonName = $sensitiveData->getCommonName(); |
|
| 163 | } |
|
| 164 | } |
|
| 165 | ||