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