001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.shiro.jndi;
020
021import javax.naming.Context;
022import javax.naming.NamingException;
023
024/**
025 * Callback interface to be implemented by classes that need to perform an
026 * operation (such as a lookup) in a JNDI context. This callback approach
027 * is valuable in simplifying error handling, which is performed by the
028 * JndiTemplate class. This is a similar to JdbcTemplate's approach.
029 *
030 * <p>Note that there is hardly any need to implement this callback
031 * interface, as JndiTemplate provides all usual JNDI operations via
032 * convenience methods.
033 *
034 * <p>Note that this interface is an exact copy of the Spring Framework's identically named interface from
035 * their 2.5.4 distribution - we didn't want to re-invent the wheel, but not require a full dependency on the
036 * Spring framework, nor does Spring make available only its JNDI classes in a small jar, or we would have used that.
037 * Since Shiro is also Apache 2.0 licensed, all regular licenses and conditions and authors have remained in tact.
038 *
039 * @see JndiTemplate
040 */
041public interface JndiCallback {
042
043    /**
044     * Do something with the given JNDI context.
045     * Implementations don't need to worry about error handling
046     * or cleanup, as the JndiTemplate class will handle this.
047     *
048     * @param ctx the current JNDI context
049     * @return a result object, or <code>null</code>
050     * @throws NamingException if thrown by JNDI methods
051     */
052    Object doInContext(Context ctx) throws NamingException;
053
054}