@@ -23,9 +23,9 @@ import play.api.Configuration
23
23
import play .api .libs .json .Json
24
24
import play .api .libs .json .Json ._
25
25
import play .api .mvc ._
26
- import uk .gov .hmrc .auth .core .AuthConnector
26
+ import uk .gov .hmrc .auth .core .retrieve . _
27
27
import uk .gov .hmrc .auth .core .retrieve .v2 .Retrievals .{authProviderId => v2AuthProviderId , nino => v2Nino }
28
- import uk .gov .hmrc .auth .core .retrieve .{ v2 , Name => RetrievedName , _ }
28
+ import uk .gov .hmrc .auth .core .{ AuthConnector , ConfidenceLevel }
29
29
import uk .gov .hmrc .helptosaveapi .auth .Auth
30
30
import uk .gov .hmrc .helptosaveapi .models .AccessType .{PrivilegedAccess , UserRestricted }
31
31
import uk .gov .hmrc .helptosaveapi .models ._
@@ -36,7 +36,6 @@ import uk.gov.hmrc.helptosaveapi.util.{LogMessageTransformer, Logging, toFuture}
36
36
import uk .gov .hmrc .http .HeaderCarrier
37
37
import uk .gov .hmrc .play .bootstrap .backend .controller .BackendController
38
38
39
- import java .time .LocalDate
40
39
import java .util .UUID
41
40
import scala .concurrent .{ExecutionContext , Future }
42
41
@@ -49,15 +48,15 @@ class HelpToSaveController @Inject() (
49
48
50
49
val correlationIdHeaderName : String = config.underlying.getString(" microservice.correlationIdHeaderName" )
51
50
52
- val userInfoRetrievals : Retrieval [Option [RetrievedName ] ~ Option [LocalDate ] ~ Option [ItmpName ] ~ Option [
53
- LocalDate
54
- ] ~ Option [ItmpAddress ] ~ Option [String ]] =
51
+ private val userInfoRetrievals = {
55
52
v2.Retrievals .name and
56
53
v2.Retrievals .dateOfBirth and
57
54
v2.Retrievals .itmpName and
58
55
v2.Retrievals .itmpDateOfBirth and
59
56
v2.Retrievals .itmpAddress and
60
- v2.Retrievals .email
57
+ v2.Retrievals .email and
58
+ v2.Retrievals .confidenceLevel
59
+ }
61
60
62
61
def apiErrorToResult (e : ApiError ): Result = e match {
63
62
case _ : ApiAccessError => Forbidden (Json .toJson(e))
@@ -87,16 +86,20 @@ class HelpToSaveController @Inject() (
87
86
// will definitely fail with a 500 response from auth for privileged access
88
87
authorised(userInfoRetrievals and v2Nino) { _ =>
89
88
{
90
- case ggName ~ dob ~ itmpName ~ itmpDob ~ itmpAddress ~ email ~ authNino =>
91
- val retrievedDetails = RetrievedUserDetails (
92
- authNino,
93
- itmpName.flatMap(_.givenName).orElse(ggName.flatMap(_.name)),
94
- itmpName.flatMap(_.familyName).orElse(ggName.flatMap(_.lastName)),
95
- itmpDob.orElse(dob),
96
- itmpAddress,
97
- email
98
- )
99
- helpToSaveApiService.createAccountUserRestricted(request, retrievedDetails).map(handleResult)
89
+ case ggName ~ dob ~ itmpName ~ itmpDob ~ itmpAddress ~ email ~ confidenceLevel ~ authNino =>
90
+ if (confidenceLevel == ConfidenceLevel .L200 ) {
91
+ val retrievedDetails = RetrievedUserDetails (
92
+ authNino,
93
+ itmpName.flatMap(_.givenName).orElse(ggName.flatMap(_.name)),
94
+ itmpName.flatMap(_.familyName).orElse(ggName.flatMap(_.lastName)),
95
+ itmpDob.orElse(dob),
96
+ itmpAddress,
97
+ email
98
+ )
99
+ helpToSaveApiService.createAccountUserRestricted(request, retrievedDetails).map(handleResult)
100
+ } else {
101
+ Future .successful(Unauthorized (" Insufficient confidence level" ))
102
+ }
100
103
}
101
104
}(ec)(request)
102
105
@@ -198,7 +201,6 @@ class HelpToSaveController @Inject() (
198
201
case None =>
199
202
logger.warn(" There was no nino retrieved from auth" )
200
203
Forbidden
201
-
202
204
}
203
205
}
204
206
0 commit comments