Explicit credential authentication¶
Where principal initialization trusts whatever identity the host process or Forms cookie already provides, this operation instead validates a username, domain, and password that the caller supplies directly. It performs a Win32 logon against those credentials, converts the resulting token into a managed Windows principal, and — only on success — impersonates the authenticated identity so subsequent work runs in that user's security context.
| Field | Value |
|---|---|
| Operation ID | OP-002 |
| Trigger | Caller sets UserName / Domain / Password and invokes Authenticate() |
| Inputs | Principal credential fields |
| Outputs | Boolean success flag, updated thread principal, impersonation context on success |
| Primary components | clsSecurityPrincipal.Authenticate, clsSecurityPrincipal.GetToken |
| Entry point | SAIF.Framework.Security\clsSecurityPrincipal.vb |
Steps¶
- Each credential property setter (
UserName,Domain,Password) updates its stored value and immediately callsLogout()first, so a new authentication attempt never starts on top of stale state — this enforces BR-006. - If a prior impersonation existed:
Logout()undoes it before the setter returns, so the credential change takes effect on a clean principal. Authenticate()callsGetToken(UserName, Domain, Password)to obtain a Windows access token for the supplied credentials.GetToken()invokes Win32LogonUser, duplicates the token it returns, closes the original handle, and throws acould not logonerror if the logon call fails or the resulting token handle is invalid.Authenticate()wraps that call in a try/catch: any token-acquisition failure is caught, and the method returnsFalseimmediately without touching the current thread principal.- When the token is acquired successfully,
Authenticate()builds aWindowsIdentityandWindowsPrincipalfrom it, assigns them toThread.CurrentThread.CurrentPrincipal, records the identity as the principal's new base identity, impersonates it, and marks the principal authenticated — all as one atomic outcome. - If the method returns
True: the caller now holds an authenticated, impersonated principal that can flow directly into Programmatic authorization checks.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Authenticate called]) --> Reset[Credential setters clear prior state]
Reset --> Token[Acquire Win32 token]
Token --> Success{Token acquired?}
Success -->|No| EndErr([Return False])
Success -->|Yes| Principal[Create Windows principal]
Principal --> Imp[Impersonate identity]
Imp --> EndOk([Return True])
Failure and edge-case behavior¶
- Invalid credentials cause
GetToken()to throw, whichAuthenticate()catches and converts into aFalsereturn rather than propagating the exception. - There is no partial-success path: principal replacement and impersonation always happen together, and a caller only ever sees
Trueafter both steps have completed.
Related documentation¶
Sources¶
SAIF.Framework.Security\clsSecurityPrincipal.vb