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 com.google.errorprone.annotations.CheckReturnValue; 020import org.jspecify.annotations.NonNull; 021import org.jspecify.annotations.Nullable; 022import javax.annotation.concurrent.Immutable; 023import static java.util.Objects.requireNonNull; 024 025/** 026 * Trusted registered-client authentication policy: public authentication or confidential client_secret_basic. 027 * Construction performs no callback or I/O. The verifier must be thread safe. No secret-post authentication, 028 * private-key authentication or client-credentials issuance is implied by this policy. 029 * 030 * @author <a href="https://www.revetkn.com">Mark Allen</a> 031 * @since 1.0.0 032 */ 033@Immutable 034public final class OAuthServerClientAuthentication { 035 private static final @NonNull OAuthServerClientAuthentication PUBLIC = new OAuthServerClientAuthentication(null); 036 private final @Nullable OAuthClientSecretVerifier verifier; 037 private OAuthServerClientAuthentication(@Nullable OAuthClientSecretVerifier verifier) { this.verifier = verifier; } 038 /** 039 * Selects public-client authentication (none). 040 * @return the public-client policy 041 * @since 1.0.0 042 */ 043 @CheckReturnValue 044 public static @NonNull OAuthServerClientAuthentication publicClientInstance() { return PUBLIC; } 045 /** 046 * Selects confidential client_secret_basic verification by the application. 047 * @param verifier the application callback; never called during construction 048 * @return the confidential policy 049 * @throws NullPointerException if verifier is null 050 * @since 1.0.0 051 */ 052 @CheckReturnValue 053 public static @NonNull OAuthServerClientAuthentication fromClientSecretVerifier(@NonNull OAuthClientSecretVerifier verifier) { 054 return new OAuthServerClientAuthentication(requireNonNull(verifier)); 055 } 056 boolean isConfidential() { return this.verifier != null; } 057 @Nullable OAuthClientSecretVerifier verifier() { return this.verifier; } 058 /** 059 * Redacts the strategy and callback from diagnostics. 060 * @return a fixed description 061 * @since 1.0.0 062 */ 063 @Override public @NonNull String toString() { return "OAuthServerClientAuthentication{configuration=<redacted>}"; } 064}