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 javax.annotation.concurrent.NotThreadSafe;
020import org.jspecify.annotations.NonNull;
021import static java.util.Objects.requireNonNull;
022
023/**
024 * A fixed, cause-free failure of configured assertion keys, signing, endpoint trust, discovery identity or issuer policy.
025 * This infrastructure failure is never an invalid-user result.
026 * @author <a href="https://www.revetkn.com">Mark Allen</a>
027 * @since 1.0.0
028 */
029@NotThreadSafe
030public final class OAuthConfigurationException extends OAuthException {
031        private static final long serialVersionUID = 1L;
032        private OAuthConfigurationException(@NonNull Reason reason) { super(reason, false, null); }
033        static @NonNull OAuthConfigurationException fromReason(@NonNull Reason reason) {
034                requireNonNull(reason);
035                switch (reason) {
036                        case CLIENT_ASSERTION_KEY_UNAVAILABLE, CLIENT_ASSERTION_SIGNING_FAILED,
037                                CLIENT_ASSERTION_KEY_PAIR_MISMATCH, CLIENT_ASSERTION_ENDPOINT_MISMATCH, ISSUER_POLICY_UNAVAILABLE, ISSUER_MISMATCH -> { }
038                        default -> throw new IllegalArgumentException("The OAuth reason is not a configuration reason.");
039                }
040                return new OAuthConfigurationException(reason);
041        }
042}