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 javax.annotation.concurrent.ThreadSafe; 021import java.time.Duration; 022 023/** 024 * Continuing application authorization policy, invoked outside store transactions at approval, code exchange 025 * and refresh. Implementations must be thread safe and honor the remaining budget. Decisions must retain the 026 * checked subject and may only narrow scope/resource/refresh authority. Denial terminates authorization. 027 * Policies must explicitly deny grant types they do not recognize; never treat an unknown type as approval. 028 * Future client-credentials issuance requires a separate policy interface and namespaced client subjects. 029 * Null, nonfatal exceptions and exhausted budgets are unavailable service failures. A returned decision that 030 * changes the checked subject or widens resource/scope/refresh authority is an application configuration fault. 031 * 032 * @author <a href="https://www.revetkn.com">Mark Allen</a> 033 * @since 1.0.0 034 */ 035@ThreadSafe 036@FunctionalInterface 037public interface OAuthGrantPolicy { 038 /** 039 * Rechecks application permission against issuer-checked grant facts. 040 * @param context checked grant facts, with no raw authorization code or refresh credential 041 * @param remainingTime the cooperative remaining operation budget 042 * @return the application decision 043 * @since 1.0.0 044 */ 045 @NonNull OAuthAuthorizationDecision authorizeGrant(@NonNull OAuthGrantContext context, @NonNull Duration remainingTime); 046}