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 */ 016package com.revetsec.servlet.javax; 017 018import com.google.errorprone.annotations.CheckReturnValue; 019import com.revetsec.scim.ScimError; 020import org.jspecify.annotations.NonNull; 021import javax.annotation.concurrent.Immutable; 022import static java.util.Objects.requireNonNull; 023 024/** A bounded raw Servlet body read; availability is distinct from protocol rejection. 025 * @since 1.0.0 026 */ 027@Immutable 028public sealed interface ServletScimBodyResult permits ServletScimBodyResult.Read, 029 ServletScimBodyResult.Rejected, ServletScimBodyResult.Unavailable { 030 /** An unchanged raw body that may contain personal data. 031 * @since 1.0.0 032 */ 033 @Immutable final class Read implements ServletScimBodyResult { 034 private final byte @NonNull [] body; 035 Read(byte @NonNull [] body) { this.body = requireNonNull(body).clone(); } 036 /** Returns a defensive copy of the original body. 037 * @return the original bytes, which may contain personal data 038 * @since 1.0.0 039 */ 040 @CheckReturnValue public byte @NonNull [] getBodyWithPersonalData() { return body.clone(); } 041 @Override public @NonNull String toString() { return "ServletScimBodyResult.Read{<redacted>}"; } 042 } 043 /** An explicit body-size rejection with no retained request bytes. 044 * @since 1.0.0 045 */ 046 @Immutable final class Rejected implements ServletScimBodyResult { 047 private final @NonNull ScimError error; 048 Rejected(@NonNull ScimError error) { this.error = requireNonNull(error); } 049 /** Returns the fixed protocol error. 050 * @return the error 051 * @since 1.0.0 052 */ 053 @CheckReturnValue public @NonNull ScimError getError() { return error; } 054 @Override public @NonNull String toString() { return "ServletScimBodyResult.Rejected{<redacted>}"; } 055 } 056 /** The input stream was unavailable; the application chooses its transport failure handling. 057 * @since 1.0.0 058 */ 059 @Immutable final class Unavailable implements ServletScimBodyResult { 060 static final @NonNull Unavailable INSTANCE = new Unavailable(); 061 private Unavailable() { } 062 @Override public @NonNull String toString() { return "ServletScimBodyResult.Unavailable"; } 063 } 064}