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.saml;
017
018import org.jspecify.annotations.NonNull;
019import javax.annotation.concurrent.Immutable;
020import java.util.List;
021import org.jspecify.annotations.Nullable;
022
023/**
024 * A verified IdP-initiated logout request. The application matches the NameID and session
025 * indexes to its own stored session references and terminates matching sessions.
026 *
027 * @since 1.0.0
028 */
029@Immutable
030public final class SamlLogoutRequest {
031    private final @NonNull String connectionId;
032    private final @NonNull String requestId;
033    private final @NonNull String spEntityId;
034    private final @NonNull String idpEntityId;
035    private final @Nullable String relayState;
036    private final @NonNull SamlNameId nameId;
037    private final @NonNull List<@NonNull String> sessionIndexes;
038
039    SamlLogoutRequest(@NonNull String connectionId, @NonNull String spEntityId,
040            @NonNull String idpEntityId, @NonNull String requestId, @Nullable String relayState,
041            @NonNull SamlNameId nameId, @NonNull List<@NonNull String> sessionIndexes) {
042        this.connectionId = connectionId;
043        this.spEntityId = spEntityId;
044        this.idpEntityId = idpEntityId;
045        this.requestId = requestId;
046        this.relayState = relayState;
047        this.nameId = nameId;
048        this.sessionIndexes = List.copyOf(sessionIndexes);
049    }
050
051    /**
052     * Returns the application-defined IdP connection namespace.
053     *
054     * @return connection ID
055     * @since 1.0.0
056     */
057    public @NonNull String getIdentityProviderConnectionId() { return connectionId; }
058    /**
059     * Returns the verified logout request ID.
060     *
061     * @return request ID
062     * @since 1.0.0
063     */
064    public @NonNull String getRequestId() { return requestId; }
065    /**
066     * Returns the full verified NameID and qualifiers.
067     *
068     * @return NameID
069     * @since 1.0.0
070     */
071    public @NonNull SamlNameId getNameId() { return nameId; }
072    /**
073     * Returns exact session indexes supplied by the IdP.
074     *
075     * @return immutable indexes
076     * @since 1.0.0
077     */
078    public @NonNull List<@NonNull String> getSessionIndexes() { return sessionIndexes; }
079    @NonNull String spEntityId() { return spEntityId; }
080    @NonNull String idpEntityId() { return idpEntityId; }
081    @Nullable String relayState() { return relayState; }
082    /**
083     * Redacts session identifiers.
084     *
085     * @return redacted description
086     * @since 1.0.0
087     */
088    @Override public @NonNull String toString() { return "SamlLogoutRequest{<redacted>}"; }
089}