File tree Expand file tree Collapse file tree 3 files changed +7
-10
lines changed
Expand file tree Collapse file tree 3 files changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ public function __construct(
5555 * @param array|null $state
5656 *
5757 * @return array
58- * @throws Exception
58+ * @throws \ Exception
5959 */
6060 public function extractUserAndAttributes (?array $ state ): array
6161 {
@@ -76,12 +76,11 @@ public function extractUserAndAttributes(?array $state): array
7676 throw new \Exception ("No cas user defined for attribute $ casUsernameAttribute " );
7777 }
7878
79+ $ casAttributes = [];
7980 if ($ this ->casconfig ->getOptionalValue ('attributes ' , true )) {
8081 $ attributesToTransfer = $ this ->casconfig ->getOptionalValue ('attributes_to_transfer ' , []);
8182
8283 if (sizeof ($ attributesToTransfer ) > 0 ) {
83- $ casAttributes = [];
84-
8584 foreach ($ attributesToTransfer as $ key ) {
8685 if (\array_key_exists ($ key , $ attributes )) {
8786 $ casAttributes [$ key ] = $ attributes [$ key ];
@@ -90,8 +89,6 @@ public function extractUserAndAttributes(?array $state): array
9089 } else {
9190 $ casAttributes = $ attributes ;
9291 }
93- } else {
94- $ casAttributes = [];
9592 }
9693
9794 return [
Original file line number Diff line number Diff line change @@ -147,8 +147,8 @@ public function validate(
147147 // Get the username field
148148 $ usernameField = $ this ->casConfig ->getOptionalValue ('attrname ' , 'eduPersonPrincipalName ' );
149149
150- // Fail if the username field is not present in the attribute list
151- if (! \array_key_exists ( $ usernameField , $ serviceTicket ['attributes ' ])) {
150+ // Fail if the username is not present in the ticket
151+ if (empty ( $ serviceTicket ['userName ' ])) {
152152 Logger::error (
153153 'casserver:validate: internal server error. Missing user name attribute: '
154154 . var_export ($ usernameField , true ),
@@ -161,7 +161,7 @@ public function validate(
161161
162162 // Successful validation
163163 return new Response (
164- $ this ->cas10Protocol ->getValidateSuccessResponse ($ serviceTicket ['attributes ' ][ $ usernameField ][ 0 ]),
164+ $ this ->cas10Protocol ->getValidateSuccessResponse ($ serviceTicket ['userName ' ]),
165165 Response::HTTP_OK ,
166166 );
167167 }
Original file line number Diff line number Diff line change @@ -233,7 +233,7 @@ public function testReturnBadRequestOnTicketMissingUsernameField(): void
233233 'service ' => 'https://myservice.com/abcd ' ,
234234 ];
235235 $ this ->ticket ['validBefore ' ] = 9999999999 ;
236- $ this ->ticket ['attributes ' ] = [] ;
236+ $ this ->ticket ['userName ' ] = '' ;
237237
238238 $ request = Request::create (
239239 uri: 'http://localhost ' ,
@@ -330,6 +330,6 @@ public function testSuccessfullValidation(): void
330330 $ response = $ cas10Controller ->validate ($ request , ...$ params );
331331
332332 $ this ->assertEquals (200 , $ response ->getStatusCode ());
333- $ this ->assertEquals ("yes \n eduPersonPrincipalName @google.com \n" , $ response ->getContent ());
333+ $ this ->assertEquals ("yes \n username @google.com \n" , $ response ->getContent ());
334334 }
335335}
You can’t perform that action at this time.
0 commit comments