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 */
020 package org.apache.directory.server.core.authn;
021
022
023 import javax.naming.NamingException;
024
025 import org.apache.directory.server.core.DirectoryService;
026 import org.apache.directory.shared.ldap.name.DN;
027
028
029 /**
030 * Base class for all Authenticators.
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 * @version $Rev: 918766 $, $Date: 2010-03-04 01:25:11 +0200 (Thu, 04 Mar 2010) $
034 */
035 public abstract class AbstractAuthenticator implements Authenticator
036 {
037 private DirectoryService directoryService;
038
039 /** authenticator type */
040 private final String authenticatorType;
041
042
043 /**
044 * Creates a new instance.
045 *
046 * @param type the type of this authenticator (e.g. <tt>'simple'</tt>, <tt>'none'</tt>...)
047 */
048 protected AbstractAuthenticator( String type )
049 {
050 this.authenticatorType = type;
051 }
052
053
054 /**
055 * Returns {@link DirectoryService} for this authenticator.
056 * @return the directory service core
057 */
058 public DirectoryService getDirectoryService()
059 {
060 return directoryService;
061 }
062
063
064 public String getAuthenticatorType()
065 {
066 return authenticatorType;
067 }
068
069
070 /**
071 * Initializes (<tt>directoryService</tt> and and calls {@link #doInit()} method.
072 * Please put your initialization code into {@link #doInit()}.
073 * @param directoryService the directory core for this authenticator
074 * @throws NamingException if there is a problem starting up the authenticator
075 */
076 public final void init( DirectoryService directoryService ) throws Exception
077 {
078 this.directoryService = directoryService;
079 doInit();
080 }
081
082
083 /**
084 * Implement your initialization code here.
085 */
086 protected void doInit()
087 {
088 }
089
090
091 /**
092 * Calls {@link #doDestroy()} method, and clears default properties
093 * (<tt>factoryConfiguration</tt> and <tt>configuration</tt>).
094 * Please put your deinitialization code into {@link #doDestroy()}.
095 */
096 public final void destroy()
097 {
098 try
099 {
100 doDestroy();
101 }
102 finally
103 {
104 this.directoryService = null;
105 }
106 }
107
108
109 /**
110 * Implement your deinitialization code here.
111 */
112 protected void doDestroy()
113 {
114 }
115
116
117 /**
118 * Does nothing leaving it so subclasses can override.
119 */
120 public void invalidateCache( DN bindDn )
121 {
122 }
123 }