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; 018 019import com.google.errorprone.annotations.CheckReturnValue; 020import org.jspecify.annotations.NonNull; 021import javax.annotation.concurrent.Immutable; 022 023/** 024 * The outcome of parsing bounded provider metadata. Parsing approves no provider trust or identity. 025 * Rejections contain a fixed reason and no received document. 026 * @author <a href="https://www.revetkn.com">Mark Allen</a> 027 * @since 1.0.0 028 */ 029@Immutable 030public abstract sealed class AuthorizationServerMetadataParseResult permits AuthorizationServerMetadataParseResult.Succeeded, AuthorizationServerMetadataParseResult.Rejected { 031 private AuthorizationServerMetadataParseResult() { } 032 static @NonNull AuthorizationServerMetadataParseResult succeeded(@NonNull AuthorizationServerMetadata metadata) { return new Succeeded(metadata); } 033 static @NonNull AuthorizationServerMetadataParseResult rejected(OAuthException.@NonNull Reason reason) { return new Rejected(reason); } 034 /** Checked metadata; the application still selects a trusted issuer. 035 * @since 1.0.0 036 */ 037 @Immutable 038 public static final class Succeeded extends AuthorizationServerMetadataParseResult { 039 private final @NonNull AuthorizationServerMetadata metadata; 040 private Succeeded(@NonNull AuthorizationServerMetadata metadata) { this.metadata = metadata; } 041 /** Returns the checked metadata. 042 * @return checked metadata 043 * @since 1.0.0 044 */ 045 @CheckReturnValue public @NonNull AuthorizationServerMetadata getMetadata() { return metadata; } 046 @Override public @NonNull String toString() { return "AuthorizationServerMetadataParseResult.Succeeded{metadata=<redacted>}"; } 047 } 048 /** A rejected metadata document with no received payload. 049 * @since 1.0.0 050 */ 051 @Immutable 052 public static final class Rejected extends AuthorizationServerMetadataParseResult { 053 private final OAuthException.@NonNull Reason reason; 054 private Rejected(OAuthException.@NonNull Reason reason) { this.reason = reason; } 055 /** Returns the fixed rejection reason. 056 * @return fixed reason 057 * @since 1.0.0 058 */ 059 @CheckReturnValue public OAuthException.@NonNull Reason getReason() { return reason; } 060 @Override public @NonNull String toString() { return "AuthorizationServerMetadataParseResult.Rejected{reason=" + reason + "}"; } 061 } 062}