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     */
019    package org.apache.shiro.realm.ldap;
020    
021    import javax.naming.NamingException;
022    import javax.naming.ldap.LdapContext;
023    
024    /**
025     * Interface that encapsulates the creation of <tt>LdapContext</tt> objects that are used by subclasses
026     * of {@link AbstractLdapRealm} to query for <tt>AuthenticationInfo</tt> security data (roles, permissions, etc) of particular
027     * Subjects (users).
028     *
029     * @author Jeremy Haile
030     * @since 0.2
031     */
032    public interface LdapContextFactory {
033    
034        /**
035         * Creates (or retrieves from a pool) a <tt>LdapContext</tt> connection bound using the system account, or anonymously
036         * if no system account is configured.
037         *
038         * @return a <tt>LdapContext</tt> bound by the system account, or bound anonymously if no system account
039         *         is configured.
040         * @throws javax.naming.NamingException if there is an error creating the context.
041         */
042        LdapContext getSystemLdapContext() throws NamingException;
043    
044        /**
045         * Creates (or retrieves from a pool) a <tt>LdapContext</tt> connection bound using the username and password
046         * specified.
047         *
048         * @param username the username to use when creating the connection.
049         * @param password the password to use when creating the connection.
050         * @return a <tt>LdapContext</tt> bound using the given username and password.
051         * @throws javax.naming.NamingException if there is an error creating the context.
052         */
053        LdapContext getLdapContext(String username, String password) throws NamingException;
054    
055    }