1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.server.core.authn; 21 22 23 import javax.naming.NamingException; 24 25 import org.apache.directory.server.core.DirectoryService; 26 import org.apache.directory.shared.ldap.name.LdapDN; 27 28 29 /** 30 * Base class for all Authenticators. 31 * 32 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 33 * @version $Rev: 664295 $, $Date: 2008-06-07 09:48:16 +0200 (Sa, 07 Jun 2008) $ 34 */ 35 public abstract class AbstractAuthenticator implements Authenticator 36 { 37 private DirectoryService directoryService; 38 39 /** authenticator type */ 40 private final String authenticatorType; 41 42 43 /** 44 * Creates a new instance. 45 * 46 * @param type the type of this authenticator (e.g. <tt>'simple'</tt>, <tt>'none'</tt>...) 47 */ 48 protected AbstractAuthenticator( String type ) 49 { 50 this.authenticatorType = type; 51 } 52 53 54 /** 55 * Returns {@link DirectoryService} for this authenticator. 56 * @return the directory service core 57 */ 58 public DirectoryService getDirectoryService() 59 { 60 return directoryService; 61 } 62 63 64 public String getAuthenticatorType() 65 { 66 return authenticatorType; 67 } 68 69 70 /** 71 * Initializes (<tt>directoryService</tt> and and calls {@link #doInit()} method. 72 * Please put your initialization code into {@link #doInit()}. 73 * @param directoryService the directory core for this authenticator 74 * @throws NamingException if there is a problem starting up the authenticator 75 */ 76 public final void init( DirectoryService directoryService ) throws Exception 77 { 78 this.directoryService = directoryService; 79 doInit(); 80 } 81 82 83 /** 84 * Implement your initialization code here. 85 */ 86 protected void doInit() 87 { 88 } 89 90 91 /** 92 * Calls {@link #doDestroy()} method, and clears default properties 93 * (<tt>factoryConfiguration</tt> and <tt>configuration</tt>). 94 * Please put your deinitialization code into {@link #doDestroy()}. 95 */ 96 public final void destroy() 97 { 98 try 99 { 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( LdapDN bindDn ) 121 { 122 } 123 }