Code Duplication    Length = 112-114 lines in 3 locations

src/Surfnet/Stepup/Identity/Event/PhonePossessionProvenAndVerifiedEvent.php 1 location

@@ 33-144 (lines=112) @@
30
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
31
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
32
33
class PhonePossessionProvenAndVerifiedEvent extends IdentityEvent implements Forgettable
34
{
35
    /**
36
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorId
37
     */
38
    public $secondFactorId;
39
40
    /**
41
     * @var \Surfnet\Stepup\Identity\Value\PhoneNumber
42
     */
43
    public $phoneNumber;
44
45
    /**
46
     * @var \Surfnet\Stepup\Identity\Value\CommonName
47
     */
48
    public $commonName;
49
50
    /**
51
     * @var \Surfnet\Stepup\Identity\Value\Email
52
     */
53
    public $email;
54
55
    /**
56
     * @var \Surfnet\Stepup\DateTime\DateTime
57
     */
58
    public $registrationRequestedAt;
59
60
    /**
61
     * @var string
62
     */
63
    public $registrationCode;
64
65
    /**
66
     * @param IdentityId $identityId
67
     * @param Institution $identityInstitution
68
     * @param SecondFactorId $secondFactorId
69
     * @param PhoneNumber $phoneNumber
70
     * @param CommonName $commonName
71
     * @param Email $email
72
     * @param DateTime $registrationRequestedAt
73
     * @param string $registrationCode
74
     */
75
    public function __construct(
76
        IdentityId $identityId,
77
        Institution $identityInstitution,
78
        SecondFactorId $secondFactorId,
79
        PhoneNumber $phoneNumber,
80
        CommonName $commonName,
81
        Email $email,
82
        DateTime $registrationRequestedAt,
83
        $registrationCode
84
    ) {
85
        parent::__construct($identityId, $identityInstitution);
86
87
        $this->secondFactorId = $secondFactorId;
88
        $this->phoneNumber = $phoneNumber;
89
        $this->commonName = $commonName;
90
        $this->email = $email;
91
    }
92
93
    public function getAuditLogMetadata()
94
    {
95
        $metadata                         = new Metadata();
96
        $metadata->identityId             = $this->identityId;
97
        $metadata->identityInstitution    = $this->identityInstitution;
98
        $metadata->secondFactorId         = $this->secondFactorId;
99
        $metadata->secondFactorType       = new SecondFactorType('sms');
100
        $metadata->secondFactorIdentifier = $this->phoneNumber;
101
102
        return $metadata;
103
    }
104
105
    public static function deserialize(array $data)
106
    {
107
        return new self(
108
            new IdentityId($data['identity_id']),
109
            new Institution($data['identity_institution']),
110
            new SecondFactorId($data['second_factor_id']),
111
            PhoneNumber::unknown(),
112
            CommonName::unknown(),
113
            Email::unknown(),
114
            DateTime::fromString($data['registration_requested_at']),
115
            (string) $data['registration_code']
116
        );
117
    }
118
119
    public function serialize()
120
    {
121
        return [
122
            'identity_id'               => (string) $this->identityId,
123
            'identity_institution'      => (string) $this->identityInstitution,
124
            'second_factor_id'          => (string) $this->secondFactorId,
125
            'registration_requested_at'   => (string) $this->registrationRequestedAt,
126
            'registration_code'           => $this->registrationCode,
127
        ];
128
    }
129
130
    public function getSensitiveData()
131
    {
132
        return (new SensitiveData)
133
            ->withCommonName($this->commonName)
134
            ->withEmail($this->email)
135
            ->withSecondFactorIdentifier($this->phoneNumber, new SecondFactorType('sms'));
136
    }
137
138
    public function setSensitiveData(SensitiveData $sensitiveData)
139
    {
140
        $this->phoneNumber = $sensitiveData->getSecondFactorIdentifier();
141
        $this->email = $sensitiveData->getEmail();
142
        $this->commonName = $sensitiveData->getCommonName();
143
    }
144
}
145

src/Surfnet/Stepup/Identity/Event/U2fDevicePossessionProvenAndVerifiedEvent.php 1 location

@@ 33-144 (lines=112) @@
30
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
31
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
32
33
class U2fDevicePossessionProvenAndVerifiedEvent extends IdentityEvent implements Forgettable
34
{
35
    /**
36
     * @var \Surfnet\Stepup\Identity\Value\SecondFactorId
37
     */
38
    public $secondFactorId;
39
40
    /**
41
     * @var \Surfnet\Stepup\Identity\Value\U2fKeyHandle
42
     */
43
    public $keyHandle;
44
45
    /**
46
     * @var \Surfnet\Stepup\Identity\Value\CommonName
47
     */
48
    public $commonName;
49
50
    /**
51
     * @var \Surfnet\Stepup\Identity\Value\Email
52
     */
53
    public $email;
54
55
    /**
56
     * @var \Surfnet\Stepup\DateTime\DateTime
57
     */
58
    public $registrationRequestedAt;
59
60
    /**
61
     * @var string
62
     */
63
    public $registrationCode;
64
65
    /**
66
     * @param IdentityId $identityId
67
     * @param Institution $identityInstitution
68
     * @param SecondFactorId $secondFactorId
69
     * @param U2fKeyHandle $keyHandle
70
     * @param CommonName $commonName
71
     * @param Email $email
72
     * @param DateTime $registrationRequestedAt
73
     * @param string $registrationCode
74
     */
75
    public function __construct(
76
        IdentityId $identityId,
77
        Institution $identityInstitution,
78
        SecondFactorId $secondFactorId,
79
        U2fKeyHandle $keyHandle,
80
        CommonName $commonName,
81
        Email $email,
82
        DateTime $registrationRequestedAt,
83
        $registrationCode
84
    ) {
85
        parent::__construct($identityId, $identityInstitution);
86
87
        $this->secondFactorId = $secondFactorId;
88
        $this->keyHandle = $keyHandle;
89
        $this->commonName = $commonName;
90
        $this->email = $email;
91
    }
92
93
    public function getAuditLogMetadata()
94
    {
95
        $metadata                         = new Metadata();
96
        $metadata->identityId             = $this->identityId;
97
        $metadata->identityInstitution    = $this->identityInstitution;
98
        $metadata->secondFactorId         = $this->secondFactorId;
99
        $metadata->secondFactorType       = new SecondFactorType('sms');
100
        $metadata->secondFactorIdentifier = $this->keyHandle;
101
102
        return $metadata;
103
    }
104
105
    public static function deserialize(array $data)
106
    {
107
        return new self(
108
            new IdentityId($data['identity_id']),
109
            new Institution($data['identity_institution']),
110
            new SecondFactorId($data['second_factor_id']),
111
            U2fKeyHandle::unknown(),
112
            CommonName::unknown(),
113
            Email::unknown(),
114
            DateTime::fromString($data['registration_requested_at']),
115
            (string) $data['registration_code']
116
        );
117
    }
118
119
    public function serialize()
120
    {
121
        return [
122
            'identity_id'                 => (string) $this->identityId,
123
            'identity_institution'        => (string) $this->identityInstitution,
124
            'second_factor_id'            => (string) $this->secondFactorId,
125
            'registration_requested_at'   => (string) $this->registrationRequestedAt,
126
            'registration_code'           => $this->registrationCode,
127
        ];
128
    }
129
130
    public function getSensitiveData()
131
    {
132
        return (new SensitiveData)
133
            ->withCommonName($this->commonName)
134
            ->withEmail($this->email)
135
            ->withSecondFactorIdentifier($this->keyHandle, new SecondFactorType('u2f'));
136
    }
137
138
    public function setSensitiveData(SensitiveData $sensitiveData)
139
    {
140
        $this->keyHandle   = $sensitiveData->getSecondFactorIdentifier();
141
        $this->email       = $sensitiveData->getEmail();
142
        $this->commonName  = $sensitiveData->getCommonName();
143
    }
144
}
145

src/Surfnet/Stepup/Identity/Event/YubikeyPossessionProvenAndVerifiedEvent.php 1 location

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