/* * JBoss, Home of Professional Open Source. * Copyright 2016 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wildfly.security.http; import static org.wildfly.security.http.ElytronMessages.log; import java.io.InputStream; import java.util.function.Consumer; /** * An attachment scope for use by an authentication mechanism. *
* Different scopes may be available to share Objects e.g. Application, Session, Connection.
*
* @author Darran Lofthouse
*/
public interface HttpScope {
/**
* Get the ID of this scope or (@code null} if IDs are not supported for this scope or the scope doesn't currently exist.
*
* @return the ID of this scope or (@code null} if IDs are not supported for this scope or the scope doesn't currently exist.
*/
default String getID() {
return null;
}
/**
* Tests whether this scope exists.
*
* @return {@code true} if this scope exists. Otherwise, {@code false}
*/
default boolean exists() {
return true;
}
/**
* Create this scope.
*
* @return {@code true} if the scope was created. Otherwise, {@code false} indicating that this scope was already created or that creation is not support.
*/
default boolean create() {
return false;
}
/**
* Tests whether this scope support attachments.
*
* @return {@code true} if this scope supports attachments, {@code false} otherwise
*/
default boolean supportsAttachments() {
return false;
}
/**
* Set the named attribute on this scope, setting to {@code null} will clear any value previously set for this key.
*
* @param key the key to use to store the attachment.
* @param value the value to store with the key or {@code null} to clear any previously stored attachment.
* @throws UnsupportedOperationException if attachments are not supported.
*/
default void setAttachment(final String key, final Object value) {
throw log.noAttachmentSupport();
}
/**
* Get the attachment previously associated with the key specified on this scope.
*
* @param key the key used to store the attachment on this scope.
* @return the value associated with the scope or {@code null} if no association exists.
* @throws UnsupportedOperationException if attachments are not supported.
*/
default Object getAttachment(final String key) {
throw log.noAttachmentSupport();
}
/**
* Get the attachment previously associated with the key specified on this scope and cast it to the type specified.
*
* This method will only return a value if the attachment exists AND can be cast to the desired type, otherwise it returns
* {@code null}.
*
* @param key the key used to store the attachment on this scope.
* @param type the desired type of the attachment.
* @return the value associated with the scope or {@code null} if no association exists or if it could not be converted to
* the requested type.
* @throws UnsupportedOperationException if attachments are not supported.
*/
default