/**
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License. 
 *
 */
package org.apache.kerby.kerberos.kerb.server.impl;

import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.identity.CacheableIdentityService;
import org.apache.kerby.kerberos.kerb.identity.IdentityService;
import org.apache.kerby.kerberos.kerb.identity.backend.IdentityBackend;
import org.apache.kerby.kerberos.kerb.identity.backend.MemoryIdentityBackend;
import org.apache.kerby.kerberos.kerb.identity.backend.BackendConfig;
import org.apache.kerby.kerberos.kerb.server.KdcConfig;
import org.apache.kerby.kerberos.kerb.server.KdcSetting;
import org.apache.kerby.kerberos.kerb.server.KdcUtil;

/**
 * Abstract KDC server implementation.
 */
public class AbstractInternalKdcServer implements InternalKdcServer {
    private boolean started;
    private final KdcConfig kdcConfig;
    private final BackendConfig backendConfig;
    private final KdcSetting kdcSetting;
    private IdentityBackend backend;
    private IdentityService identityService;

    public AbstractInternalKdcServer(KdcSetting kdcSetting) {
        this.kdcSetting = kdcSetting;
        this.kdcConfig = kdcSetting.getKdcConfig();
        this.backendConfig = kdcSetting.getBackendConfig();
    }

    @Override
    public KdcSetting getSetting() {
        return kdcSetting;
    }

    public boolean isStarted() {
        return started;
    }

    protected String getServiceName() {
        return kdcConfig.getKdcServiceName();
    }

    protected IdentityService getIdentityService() {
        if (identityService == null) {
            if (backend instanceof MemoryIdentityBackend) { // Already in memory
                identityService = backend;
            } else {
                identityService = new CacheableIdentityService(
                        backendConfig, backend);
            }
        }
        return identityService;
    }

    @Override
    public void init() throws KrbException {
        backend = KdcUtil.getBackend(backendConfig);
    }

    @Override
    public void start() throws KrbException {
        try {
            doStart();
        } catch (Exception e) {
            throw new KrbException("Failed to start " + getServiceName() + ". " + e.getMessage());
        }

        started = true;
    }

    public boolean enableDebug() {
        return kdcConfig.enableDebug();
    }

    @Override
    public IdentityBackend getIdentityBackend() {
        return backend;
    }

    protected void doStart() throws Exception {
        backend.start();
    }

    public void stop() throws KrbException {
        try {
            doStop();
        } catch (Exception e) {
            throw new KrbException("Failed to stop " + getServiceName(), e);
        }

        started = false;
    }

    protected void doStop() throws Exception {
        backend.stop();
    }
}

@@ -929,81 +929,8 @@
 on;%0A
-import org.apache.kerby.kerberos.kerb.identity.CacheableIdentityService;%0A
 impo
@@ -1044,31 +1044,29 @@
 backend.
-Identity
 Backend
+Config
 ;%0Aimport
@@ -1114,22 +1114,16 @@
 backend.
-Memory
 Identity
@@ -1135,78 +1135,8 @@
 nd;%0A
-import org.apache.kerby.kerberos.kerb.identity.backend.BackendConfig;%0A
 impo
@@ -1612,53 +1612,8 @@
 end;
-%0A    private IdentityService identityService;
 %0A%0A  
@@ -2136,351 +2136,22 @@
     
-if (identityService == null) %7B%0A            if (backend instanceof MemoryIdentityBackend) %7B // Already in memory%0A                identityService = backend;%0A            %7D else %7B%0A                identityService = new CacheableIdentityService(%0A                        backendConfig, backend);%0A            %7D%0A        %7D%0A        return identityService
+return backend
 ;%0A  

Fix DIRKRB-694, removing CacheableIdentityService in KDC server.