Problem statement
Complete the implementation of MinimumTenureRequirement, MinimumTenureHandler and PayrollAuthorization so that the payroll views of Larkspur Mills open only to staff who have served long enough.
Sample Data
Callers arrive with a signed token. A token that belongs to somebody on the payroll carries a hireDate claim holding that person's first day, written as yyyy-MM-dd and nothing else:
{
"sub": "e-4417",
"name": "Rosa Iversen",
"hireDate": "2010-05-04"
}
Not every token carries one. The claim can be absent, it can arrive under some other name, and it can hold something that is not a date in that form, such as 01/03/2015, 2015-3-1 or not-a-date.
The host is configured with the minimum number of whole years of service at Payroll:MinimumTenureYears. It ships as 2 and is not always 2. The application reads today's date from the TimeProvider the host registers rather than from the system clock; that clock ships reading 2019-04-10 and is not always that date either.
The payroll book is pre-seeded with three payslips, two tax documents and a two entry pay calendar.
Service
MinimumTenureRequirement
The demand the payroll policy makes: a minimum number of whole years of service, held on a public int property named Years.
MinimumTenureHandler
Decides whether a caller meets a MinimumTenureRequirement. It reaches that verdict from the caller's own claims and the application's clock, so it answers the same whether or not there is a request in front of it.
Service is counted in whole years: adding Years years to the hire date must land on or before today. The minimum is inclusive, so a caller hired exactly Years years ago meets it and one hired a day later does not.
Everything else leaves the requirement unmet, and none of it is an error. A missing hireDate claim, a value that is not a date written yyyy-MM-dd, and a hire date still to come are all refusals, reached without throwing and without letting a failure escape into the response.
PayrollAuthorization
- AddPayrollAuthorization: register exactly one MinimumTenureHandler as the decision that judges the requirement, and define a policy named TenuredStaff carrying one MinimumTenureRequirement built from the configured minimum.
- GuardPayrollGroup: put the TenuredStaff policy on the payroll group it is handed, so that it covers every view the group holds, including views mapped into the group after this method has returned.
Who a guarded view answers
- 401 to a caller whose token is missing, expired or otherwise unusable, carrying a WWW-Authenticate header that names the Bearer scheme.
- 403, and no WWW-Authenticate header, to a caller whose token is good but whose service is too short.
- 200 to a caller who meets the minimum.
A refused call never reaches a payroll view. Each view records that it ran, and a refusal leaves that tally where it was.
GET /payroll/calendar is not part of the group. It stays open to anyone signed in, however short their service, and answers 401 to a caller with no token at all.
Sample Requests & Responses
Today reads 2019-04-10 and the minimum is 2 years throughout these samples.
GET /payroll/payslips with a token carrying "hireDate": "2010-05-04"
Response code: 200
[
{ "reference": "PS-2019-01", "period": "2019-01", "gross": 4200.00, "net": 3010.75 },
{ "reference": "PS-2019-02", "period": "2019-02", "gross": 4200.00, "net": 3010.75 },
{ "reference": "PS-2019-03", "period": "2019-03", "gross": 4600.00, "net": 3268.25 }
]
GET /payroll/calendar with a token carrying "hireDate": "2018-08-01"
Response code: 200
[
{ "period": "2019-04", "paidOn": "2019-04-26" },
{ "period": "2019-05", "paidOn": "2019-05-28" }
]
