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 reauthentication completion; only Succeeded carries a verified identity. 026 * @since 1.0.0 */ 027@Immutable 028public abstract sealed class WebAuthnReauthenticationResult permits WebAuthnReauthenticationResult.Succeeded, 029 WebAuthnReauthenticationResult.Rejected, WebAuthnReauthenticationResult.Unavailable, 030 WebAuthnReauthenticationResult.Indeterminate, WebAuthnReauthenticationResult.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 WebAuthnReauthenticationResult() { } 035 static @NonNull WebAuthnReauthenticationResult succeeded(@NonNull WebAuthnReauthentication reauthentication) { 036 return new Succeeded(reauthentication); 037 } 038 static @NonNull WebAuthnReauthenticationResult rejected(@NonNull WebAuthnRejectionReason reason) { 039 return new Rejected(reason); 040 } 041 static @NonNull WebAuthnReauthenticationResult unavailable() { return UNAVAILABLE; } 042 static @NonNull WebAuthnReauthenticationResult indeterminate() { return INDETERMINATE; } 043 static @NonNull WebAuthnReauthenticationResult reconciliationRequired() { return RECONCILIATION_REQUIRED; } 044 /** Redacts all identity and browser data. 045 * @return a fixed description 046 * @since 1.0.0 */ 047 @Override public final @NonNull String toString() { return "WebAuthnReauthenticationResult{<redacted>}"; } 048 049 /** Confirmed stored-key reauthentication. 050 * @since 1.0.0 */ 051 @Immutable public static final class Succeeded extends WebAuthnReauthenticationResult { 052 private final @NonNull WebAuthnReauthentication reauthentication; 053 private Succeeded(@NonNull WebAuthnReauthentication reauthentication) { 054 this.reauthentication = requireNonNull(reauthentication); 055 } 056 /** Returns the verified reauthentication. 057 * @return reauthentication 058 * @since 1.0.0 */ 059 public @NonNull WebAuthnReauthentication getReauthentication() { return this.reauthentication; } 060 } 061 /** Fixed validation or policy rejection without an identity. 062 * @since 1.0.0 */ 063 @Immutable public static final class Rejected extends WebAuthnReauthenticationResult { 064 private final @NonNull WebAuthnRejectionReason reason; 065 private Rejected(@NonNull WebAuthnRejectionReason reason) { this.reason = requireNonNull(reason); } 066 /** Returns a fixed reason. 067 * @return rejection reason 068 * @since 1.0.0 */ 069 public @NonNull WebAuthnRejectionReason getReason() { return this.reason; } 070 } 071 /** Storage or admission was unavailable. 072 * @since 1.0.0 */ 073 @Immutable public static final class Unavailable extends WebAuthnReauthenticationResult { 074 private Unavailable() { } 075 } 076 /** A write may have occurred; reconcile before retry. 077 * @since 1.0.0 */ 078 @Immutable public static final class Indeterminate extends WebAuthnReauthenticationResult { 079 private Indeterminate() { } 080 } 081 /** The requested transition committed, but normal output could not be admitted. 082 * Reconcile through an authorized fresh operation before deciding what to do next. 083 * @since 1.0.0 */ 084 @Immutable public static final class ReconciliationRequired extends WebAuthnReauthenticationResult { 085 private ReconciliationRequired() { } 086 } 087 088}