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.oauth.server;
018
019import org.jspecify.annotations.NonNull;
020import org.jspecify.annotations.Nullable;
021import com.google.errorprone.annotations.CheckReturnValue;
022import javax.annotation.concurrent.Immutable;
023import java.util.Optional;
024import static java.util.Objects.requireNonNull;
025/**
026 * A library-created outcome. Applications cannot mint outcomes or proofs. Future variants require a rejecting
027 * switch default. Diagnostics disclose no interaction, credential, identity or claims. Infrastructure failures
028 * remain exceptions and cannot be reported as credential rejection.
029 * @since 1.0.0
030 */
031@Immutable
032public abstract sealed class OAuthRevocationResult permits OAuthRevocationResult.Succeeded, OAuthRevocationResult.Rejected {
033        OAuthRevocationResult() {}
034        static @NonNull OAuthRevocationResult fromSucceeded(@NonNull OAuthServerResponse response) { return new Succeeded(requireNonNull(response)); }
035        static @NonNull OAuthRevocationResult fromRejection(OAuthServerException.@NonNull Reason reason, @NonNull OAuthServerResponse response) {
036                requireNonNull(reason).requireKind(OAuthServerException.Kind.VALIDATION);
037                return new Rejected(reason,requireNonNull(response));
038        }
039        /** Returns a fixed redacted description.
040         * @return fixed redacted description
041         * @since 1.0.0
042         */
043        @Override public final @NonNull String toString() { return "OAuthRevocationResult{<redacted>}"; }
044        /** The library-created Succeeded outcome.
045         * @since 1.0.0
046         */
047        @Immutable public static final class Succeeded extends OAuthRevocationResult {
048                private final @NonNull OAuthServerResponse response;
049                private Succeeded(@NonNull OAuthServerResponse response) { this.response=response; }
050                /** Returns the restricted response.
051                 * @return response
052                 * @since 1.0.0
053                 */
054                @CheckReturnValue public @NonNull OAuthServerResponse getResponse() { return this.response; }
055        }
056        /** A fixed rejection with no proof, request, credential, identity, claims or exception object.
057         * @since 1.0.0
058         */
059        @Immutable public static final class Rejected extends OAuthRevocationResult {
060                private final OAuthServerException.@NonNull Reason reason;
061                private final @NonNull OAuthServerResponse response;
062                private Rejected(OAuthServerException.@NonNull Reason reason, @NonNull OAuthServerResponse response) { this.reason=reason; this.response=response; }
063                /** Returns the fixed issuer rejection reason, not an external error string.
064                 * @return fixed reason
065                 * @since 1.0.0
066                 */
067                @CheckReturnValue public OAuthServerException.@NonNull Reason getReason() { return this.reason; }
068                /** Returns the safe library-prepared local rejection response.
069                 * @return restricted response
070                 * @since 1.0.0
071                 */
072                @CheckReturnValue public @NonNull OAuthServerResponse getResponse() { return this.response; }
073        }
074}