Skip to content

Commit b7c9806

Browse files
committed
Upgrade Authorization::assertSatIsAllowed method
Only when the Identity owned a self-asserted token (SAT), or when the identity does not have a tokey yet, allow the Identity to vet a self asesrted token.
1 parent 32a5791 commit b7c9806

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/Surfnet/StepupMiddleware/ApiBundle/Authorization/Service/AuthorizationService.php

+10
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ public function assertRegistrationOfSelfAssertedTokensIsAllowed(IdentityId $iden
7878
return $this->deny('Identity already has a vetted second factor');
7979
}
8080

81+
// Only allow self-asserted token (SAT) if the user does not have a token yet, or the first
82+
// registered token was a SAT.
83+
$options = $this->identityService->getSelfAssertedTokenRegistrationOptions(
84+
$identity,
85+
$this->secondFactorService->hasVettedByIdentity($identityId)
86+
);
87+
if ($options->possessedSelfAssertedToken === false) {
88+
return $this->deny('Identity never possessed a self-asserted token, but did/does possess one of the other types');
89+
}
90+
8191
return $this->allow();
8292
}
8393

src/Surfnet/StepupMiddleware/ApiBundle/Tests/Authorization/Service/AuthorizationServiceTest.php

+62
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public function test_it_rejects_when_identity_has_vetted_token()
129129
{
130130
$identity = new Identity();
131131
$identity->institution = new Institution('Known institution');
132+
$identity->possessedSelfAssertedToken = null;
132133

133134
$this->identityService
134135
->shouldReceive('find')
@@ -155,10 +156,42 @@ public function test_it_rejects_when_identity_has_vetted_token()
155156
$this->assertEquals('Identity already has a vetted second factor', reset($messages));
156157
}
157158

159+
public function test_it_rejects_when_identity_had_prior_non_sat_token()
160+
{
161+
$identity = new Identity();
162+
$identity->institution = new Institution('Known institution');
163+
$identity->possessedSelfAssertedToken = false;
164+
165+
$this->identityService
166+
->shouldReceive('find')
167+
->once()
168+
->andReturn($identity);
169+
170+
$options = new InstitutionConfigurationOptions();
171+
$options->selfAssertedTokensOption = new SelfAssertedTokensOption(true);
172+
$this->institutionConfigurationService
173+
->shouldReceive('findInstitutionConfigurationOptionsFor')
174+
->once()
175+
->andReturn($options);
176+
177+
$identityId = new IdentityId('known-user-id');
178+
$this->secondFactorService
179+
->shouldReceive('hasVettedByIdentity')
180+
->with($identityId)
181+
->andReturnFalse();
182+
183+
$decision = $this->service->assertRegistrationOfSelfAssertedTokensIsAllowed($identityId);
184+
$messages = $decision->getErrorMessages();
185+
186+
$this->assertEquals(403, $decision->getCode());
187+
$this->assertEquals('Identity never possessed a self-asserted token, but did/does possess one of the other types', reset($messages));
188+
}
189+
158190
public function test_it_allows_when_identity_meets_all_requirements()
159191
{
160192
$identity = new Identity();
161193
$identity->institution = new Institution('Known institution');
194+
$identity->possessedSelfAssertedToken = null;
162195

163196
$this->identityService
164197
->shouldReceive('find')
@@ -185,5 +218,34 @@ public function test_it_allows_when_identity_meets_all_requirements()
185218
$this->assertEmpty($messages);
186219
}
187220

221+
public function test_it_allows_when_identity_with_prior_sat_meets_all_requirements()
222+
{
223+
$identity = new Identity();
224+
$identity->institution = new Institution('Known institution');
225+
$identity->possessedSelfAssertedToken = true;
226+
227+
$this->identityService
228+
->shouldReceive('find')
229+
->once()
230+
->andReturn($identity);
188231

232+
$options = new InstitutionConfigurationOptions();
233+
$options->selfAssertedTokensOption = new SelfAssertedTokensOption(true);
234+
$this->institutionConfigurationService
235+
->shouldReceive('findInstitutionConfigurationOptionsFor')
236+
->once()
237+
->andReturn($options);
238+
239+
$identityId = new IdentityId('known-user-id');
240+
$this->secondFactorService
241+
->shouldReceive('hasVettedByIdentity')
242+
->with($identityId)
243+
->andReturnFalse();
244+
245+
$decision = $this->service->assertRegistrationOfSelfAssertedTokensIsAllowed($identityId);
246+
$messages = $decision->getErrorMessages();
247+
248+
$this->assertEquals(200, $decision->getCode());
249+
$this->assertEmpty($messages);
250+
}
189251
}

0 commit comments

Comments
 (0)