View Javadoc
1   /*
2    * Copyright 2013–2026 Michael Osipov
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.michaelo.tomcat.realm.mapper;
17  
18  import javax.naming.NamingException;
19  import javax.naming.directory.DirContext;
20  
21  import net.sf.michaelo.tomcat.realm.ActiveDirectoryRealm;
22  
23  import org.ietf.jgss.GSSName;
24  import org.ietf.jgss.Oid;
25  
26  /** A mapper interface (strategy pattern) for translating GSS names to Active Directory search space parameters. */
27  public interface UsernameSearchMapper {
28  
29  	/** Mapped values holder. The {@link ActiveDirectoryRealm} uses these mapped values to search for a user. */
30  	interface MappedValues {
31  
32  		String getSearchBase();
33  
34  		String getSearchAttributeName();
35  
36  		String getSearchUsername();
37  	}
38  
39  	/**
40  	 * Returns an array of name type OIDs which a mapper is able to map into AD search space.
41  	 *
42  	 * @return supported string name type OIDs
43  	 */
44  	Oid[] getSupportedStringNameTypes();
45  
46  	/**
47  	 * Determines whether a mapper is able to map a given GSS name into AD search space.
48  	 *
49  	 * @param gssName the gssName to test
50  	 * @return {@code} if this mapper is able to map a name, {@code false} otherwise
51  	 */
52  	boolean supportsGssName(GSSName gssName);
53  
54  	/**
55  	 * Maps a GSS name to AD search space parameters. A mapper implementation must assure that the user can be found in
56  	 * the given {@code context} when an approriate GSS name is presented. The implementor must be aware that the
57  	 * returned search base might need to be relativized to the root DN of the context.
58  	 *
59  	 * @param context the search context
60  	 * @param gssName the GSS name to be mapped
61  	 * @return mapped values for user retrieval
62  	 * @throws NamingException if a context-related error has occured
63  	 * @throws IllegalArgumentException if the GSS name is not supported
64  	 */
65  	MappedValues map(DirContext context, GSSName gssName) throws NamingException;
66  }