Code Duplication    Length = 27-27 lines in 3 locations

src/Surfnet/StepupSelfService/SelfServiceBundle/Security/Authentication/Provider/SamlProvider.php 3 locations

@@ 116-142 (lines=27) @@
113
     * @param AssertionAdapter $translatedAssertion
114
     * @return string
115
     */
116
    private function getInstitution(AssertionAdapter $translatedAssertion)
117
    {
118
        $institutions = $translatedAssertion->getAttributeValue('schacHomeOrganization');
119
120
        if (empty($institutions)) {
121
            throw new BadCredentialsException(
122
                'No schacHomeOrganization provided'
123
            );
124
        }
125
126
        if (count($institutions) > 1) {
127
            throw new BadCredentialsException(
128
                'Multiple schacHomeOrganizations provided in SAML Assertion'
129
            );
130
        }
131
132
        $institution = $institutions[0];
133
134
        if (!is_string($institution)) {
135
            $this->logger->warning('Received invalid schacHomeOrganization', ['schacHomeOrganizationType' => gettype($institution)]);
136
            throw new BadCredentialsException(
137
                'schacHomeOrganization is not a string'
138
            );
139
        }
140
141
        return $institution;
142
    }
143
144
    /**
145
     * @param AssertionAdapter $translatedAssertion
@@ 148-174 (lines=27) @@
145
     * @param AssertionAdapter $translatedAssertion
146
     * @return string
147
     */
148
    private function getEmail(AssertionAdapter $translatedAssertion)
149
    {
150
        $emails = $translatedAssertion->getAttributeValue('mail');
151
152
        if (empty($emails)) {
153
            throw new BadCredentialsException(
154
                'No schacHomeOrganization provided'
155
            );
156
        }
157
158
        if (count($emails) > 1) {
159
            throw new BadCredentialsException(
160
                'Multiple email values provided in SAML Assertion'
161
            );
162
        }
163
164
        $email = $emails[0];
165
166
        if (!is_string($email)) {
167
            $this->logger->warning('Received invalid email', ['emailType' => gettype($email)]);
168
            throw new BadCredentialsException(
169
                'email is not a string'
170
            );
171
        }
172
173
        return $email;
174
    }
175
176
    /**
177
     * @param AssertionAdapter $translatedAssertion
@@ 180-206 (lines=27) @@
177
     * @param AssertionAdapter $translatedAssertion
178
     * @return string
179
     */
180
    private function getCommonName(AssertionAdapter $translatedAssertion)
181
    {
182
        $commonNames = $translatedAssertion->getAttributeValue('commonName');
183
184
        if (empty($commonNames)) {
185
            throw new BadCredentialsException(
186
                'No commonName provided'
187
            );
188
        }
189
190
        if (count($commonNames) > 1) {
191
            throw new BadCredentialsException(
192
                'Multiple commonName values provided in SAML Assertion'
193
            );
194
        }
195
196
        $commonName = $commonNames[0];
197
198
        if (!is_string($commonName)) {
199
            $this->logger->warning('Received invalid commonName', ['commonNameType' => gettype($commonName)]);
200
            throw new BadCredentialsException(
201
                'commonName is not a string'
202
            );
203
        }
204
205
        return $commonName;
206
    }
207
}
208