001/* 002 * Copyright 2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.revetsec.webauthn; 018 019import org.jspecify.annotations.NonNull; 020 021import javax.annotation.concurrent.Immutable; 022 023import static java.util.Objects.requireNonNull; 024 025/** Library-created sign-in or reauthentication preparation outcome. 026 * @since 1.0.0 */ 027@Immutable 028public abstract sealed class WebAuthnAuthenticationRequestResult permits 029 WebAuthnAuthenticationRequestResult.Prepared, WebAuthnAuthenticationRequestResult.Rejected, 030 WebAuthnAuthenticationRequestResult.Unavailable, WebAuthnAuthenticationRequestResult.Indeterminate, WebAuthnAuthenticationRequestResult.ReconciliationRequired { 031 private static final @NonNull Unavailable UNAVAILABLE = new Unavailable(); 032 private static final @NonNull Indeterminate INDETERMINATE = new Indeterminate(); 033 private static final @NonNull ReconciliationRequired RECONCILIATION_REQUIRED = new ReconciliationRequired(); 034 WebAuthnAuthenticationRequestResult() { } 035 static @NonNull WebAuthnAuthenticationRequestResult prepared(@NonNull WebAuthnBrowserRequest request) { 036 return new Prepared(request); 037 } 038 static @NonNull WebAuthnAuthenticationRequestResult rejected() { return new Rejected(); } 039 static @NonNull WebAuthnAuthenticationRequestResult unavailable() { return UNAVAILABLE; } 040 static @NonNull WebAuthnAuthenticationRequestResult indeterminate() { return INDETERMINATE; } 041 static @NonNull WebAuthnAuthenticationRequestResult reconciliationRequired() { return RECONCILIATION_REQUIRED; } 042 /** Redacts browser and account fields. 043 * @return a fixed description 044 * @since 1.0.0 */ 045 @Override public final @NonNull String toString() { return "WebAuthnAuthenticationRequestResult{<redacted>}"; } 046 047 /** A committed, single-use browser request. 048 * @since 1.0.0 */ 049 @Immutable public static final class Prepared extends WebAuthnAuthenticationRequestResult { 050 private final @NonNull WebAuthnBrowserRequest request; 051 private Prepared(@NonNull WebAuthnBrowserRequest request) { this.request = requireNonNull(request); } 052 /** Returns the browser request. 053 * @return request 054 * @since 1.0.0 */ 055 public @NonNull WebAuthnBrowserRequest getRequest() { return this.request; } 056 } 057 /** The approved account was not admitted for reauthentication. 058 * @since 1.0.0 */ 059 @Immutable public static final class Rejected extends WebAuthnAuthenticationRequestResult { 060 private Rejected() { } 061 /** Returns a fixed reason. 062 * @return rejection reason 063 * @since 1.0.0 */ 064 public @NonNull WebAuthnRejectionReason getReason() { return WebAuthnRejectionReason.REJECTED; } 065 } 066 /** Storage or admission was unavailable. 067 * @since 1.0.0 */ 068 @Immutable public static final class Unavailable extends WebAuthnAuthenticationRequestResult { 069 private Unavailable() { } 070 } 071 /** A write may have occurred; reconcile before retry. 072 * @since 1.0.0 */ 073 @Immutable public static final class Indeterminate extends WebAuthnAuthenticationRequestResult { 074 private Indeterminate() { } 075 } 076 /** The requested transition committed, but normal output could not be admitted. 077 * Reconcile through an authorized fresh operation before deciding what to do next. 078 * @since 1.0.0 */ 079 @Immutable public static final class ReconciliationRequired extends WebAuthnAuthenticationRequestResult { 080 private ReconciliationRequired() { } 081 } 082 083}