CertificateSecurityService¶
Implements per-request certificate authorization decisions for CertificateService and CertificateEditor-style callers by combining the current user's IsAuthorized grants (via IUserProfileService) with certificate-specific business rules (certificate type, creator identity, creation-date age) resolved through ICertificateInformationService for policy lookups on Other-States-policy access checks. Authorization outcomes are cached per current-user-ID for the lifetime of the service instance so repeated calls for the same user avoid re-evaluating IsAuthorized.
Purpose¶
- Decides whether the current user can view Other-States-Coverage (OSC) data, and, for a specific
OtherStatesPolicy, whether an agent-restricted user is tied to that policy's agent or agency. - Decides whether the current user can add, edit, delete, renew, or resend a specific certificate, based on certificate type (standard/bid vs. Other-States), the user's maintain/renew authorization grants, and — for edit/delete — whether the current user created the certificate.
- Decides whether the current user can add standard/bid certificates versus Other-States certificates, and whether other-coverages text can be maintained.
- Enforces a time-boxed edit/delete window: certificates can only be edited or deleted within
SecurityResources.MaximumEditibleDaysof their creation date, and exposes the cutoff date used to filter editable certificates.
Context¶
- Namespace:
SAIF.Services.Policies.Certificates - Assembly/package:
SAIF.Services(packaged inside theSAIF.SAIFCode.CoreNuGet package).
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| CertificateSecurityService (constructor) | public CertificateSecurityService(IUserProfileService userProfileService, ICertificateInformationService certificateInformationService) |
Wires the user-profile service (current-user/authorization lookups) and the certificate-information service (policy lookups for Other-States-policy access checks). |
| CanCurrentUserViewOsc | public bool CanCurrentUserViewOsc() |
Returns true if the current user holds either the ViewOsc or ViewOscExt authorization resource; result is cached per user ID. |
| CanCurrentUserAccess | public bool CanCurrentUserAccess(OtherStatesPolicy policy) |
Returns false if the user cannot view OSC data at all; otherwise returns true for non-agent users, and for agent users returns true only if the user's external customer ID matches the policy's agent ID or agent agency ID. |
| CanCurrentUserAdd | public bool CanCurrentUserAdd() |
Returns whether the current user holds the standard "maintain own" certificate authorization. |
| CanCurrentUserAddOsc | public bool CanCurrentUserAddOsc() |
Returns whether the current user holds the "maintain own OSC" certificate authorization. |
| CertificateOtherCoveragesCanBeMaintained | public bool CertificateOtherCoveragesCanBeMaintained() |
Returns true if the current user holds either the MaintainOtherCoverages or MaintainOtherCoveragesExt authorization resource; result is cached per user ID. |
| CanCurrentUserRenew | public bool CanCurrentUserRenew() |
Returns whether the current user holds the standard certificate renew authorization (Renew or RenewExternal). |
| CanCurrentUserRenewOsc | public bool CanCurrentUserRenewOsc() |
Returns whether the current user holds the OSC certificate renew authorization (RenewOsc or RenewOscExternal). |
| CertificateCanBeRenewed | public bool CertificateCanBeRenewed(CertificateSecurityProperties certificate) |
Sets the certificate under evaluation and returns whether the current user can renew it, based on whether it is a standard or Other-States certificate. |
| CertificateCanBeAdded | public bool CertificateCanBeAdded(CertificateSecurityProperties certificate) |
Sets the certificate under evaluation and returns whether the current user is authorized to add a certificate of that type (standard/bid vs. Other-States). |
| CertificateCanBeEdited | public bool CertificateCanBeEdited(CertificateSecurityProperties certificate) |
Sets the certificate under evaluation and returns true only if the certificate is still within its editable time window and the current user is authorized to edit it (has "maintain all" rights, or "maintain own" rights and created the certificate). |
| CertificateCanBeDeleted | public bool CertificateCanBeDeleted(CertificateSecurityProperties certificate) |
Sets the certificate under evaluation and returns whether it can be deleted, using the same time-window and authorization rules as CertificateCanBeEdited. |
| CertificateCanBeResent | public bool CertificateCanBeResent(CertificateSecurityProperties certificate) |
Sets the certificate under evaluation and always returns true (resend is not currently gated by additional business rules beyond having reached this call). |
| GetCertificateModificationCutoff | public DateTime GetCertificateModificationCutoff() |
Returns today's date minus SecurityResources.MaximumEditibleDays, the earliest creation date a certificate can have and still be editable/deletable. |
Behavioral notes¶
- Most authorization checks (
CanCurrentUserViewOsc,CertificateOtherCoveragesCanBeMaintained, and the privateCurrentUserCanMaintain*/CurrentUserCanRenew*/CurrentUserCanAdd*properties) cache their boolean result in aKeyValuePair<string, bool>keyed by the current user's ID, re-evaluatingIsAuthorizedonly when the cached user ID no longer matches.* CertificateCanBeEditedByCurrentUser/CertificateCanBeDeletedByCurrentUserrequire either a "maintain all" authorization or both a "maintain own" authorization and the current user having created the certificate, compared case-insensitively viaString.Equalson uppercased user IDs.CertificateCanBeEditedNow/CertificateCanBeDeletedNowboth delegate toCertificateCanBeModifiedNow, which requiresCurrentCertificate.CreateDate + SecurityResources.MaximumEditibleDaysto be after today.CanCurrentUserAccessthrows no exception on a nullpolicyargument at the API boundary despite the method dereferencing it; the method carries aCA1062:Validate arguments of public methodssuppression.*- A commented-out
PolicyHasCancelAttributes/CertificateCanBeMaintainedByCancelDateRulesblock indicates a previously considered (and currently disabled) cancellation-date-based maintainability rule.*
Constraints and usage notes¶
- Both constructor parameters are null-checked via
Enforce.ArgumentNotNull. - All
CertificateCanBe*methods mutate the sharedCurrentCertificateproperty as a side effect before evaluating the result, so this service is not safe for concurrent calls against different certificates on the same instance.* - Per-user authorization caches are stored as instance fields, so a
CertificateSecurityServiceinstance should not be reused across different users without expecting stale results if the user context changes mid-lifetime.*
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.
Sources¶
Services/SAIF.Services/Policies/Certificates/CertificateSecurityService.cs