001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.shiro.authc;
018
019import org.apache.activemq.shiro.subject.SubjectConnectionReference;
020import org.apache.shiro.authc.AuthenticationToken;
021
022/**
023 * A {@code AuthenticationTokenFactory} inspects a newly-added ActiveMQ connection and returns a Shiro
024 * {@link AuthenticationToken} instance representing credentials associated with the connection.  These credentials can
025 * be used to {@link org.apache.shiro.subject.Subject#login(org.apache.shiro.authc.AuthenticationToken) authenticate}
026 * the connection, allowing for later identity and authorization (access control) checks.
027 *
028 * @see AuthenticationFilter#addConnection(org.apache.activemq.broker.ConnectionContext, org.apache.activemq.command.ConnectionInfo)
029 * @since 5.10.0
030 */
031public interface AuthenticationTokenFactory {
032
033    /**
034     * Returns a Shiro {@code AuthenticationToken} instance that should be used to authenticate the connection's
035     * {@link org.apache.shiro.subject.Subject}, or {@code null} if no authentication information can be obtained.
036     * <p/>
037     * If no {@code AuthenticationToken} can be obtained, the connection's Subject will be considered anonymous and any
038     * downstream security checks that enforce authentication or authorization will fail (as would be expected).
039     *
040     * @param ref the subject's connection
041     * @return a Shiro {@code AuthenticationToken} instance that should be used to authenticate the connection's
042     *         {@link org.apache.shiro.subject.Subject}, or {@code null} if no authentication information can be obtained.
043     * @throws Exception if there is a problem acquiring/creating an expected {@code AuthenticationToken}.
044     */
045    AuthenticationToken getAuthenticationToken(SubjectConnectionReference ref) throws Exception;
046}