aboutsummaryrefslogtreecommitdiffstats
path: root/upstream/odl-aaa-moon/aaa/aaa-authn-mdsal-store/aaa-authn-mdsal-store-impl/src/main/java/org/opendaylight/yang/gen/v1/config/aaa/authn/mdsal/store/rev141031/AuthNStoreModule.java
blob: 0631170eace7960f7fcdcb3c9eb4b0e9025dee9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 */

package org.opendaylight.yang.gen.v1.config.aaa.authn.mdsal.store.rev141031;

import org.opendaylight.aaa.api.IIDMStore;
import org.opendaylight.aaa.api.TokenStore;
import org.opendaylight.aaa.authn.mdsal.store.AuthNStore;
import org.opendaylight.aaa.authn.mdsal.store.IDMMDSALStore;
import org.opendaylight.aaa.authn.mdsal.store.IDMStore;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

public class AuthNStoreModule
        extends
        org.opendaylight.yang.gen.v1.config.aaa.authn.mdsal.store.rev141031.AbstractAuthNStoreModule {
    private BundleContext bundleContext;

    public AuthNStoreModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
        super(identifier, dependencyResolver);
    }

    public AuthNStoreModule(
            org.opendaylight.controller.config.api.ModuleIdentifier identifier,
            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
            org.opendaylight.yang.gen.v1.config.aaa.authn.mdsal.store.rev141031.AuthNStoreModule oldModule,
            java.lang.AutoCloseable oldInstance) {
        super(identifier, dependencyResolver, oldModule, oldInstance);
    }

    @Override
    public void customValidation() {
        // add custom validation form module attributes here.
    }

    @Override
    public java.lang.AutoCloseable createInstance() {

        DataBroker dataBrokerService = getDataBrokerDependency();
        final AuthNStore authNStore = new AuthNStore(dataBrokerService, getPassword());
        final IDMMDSALStore mdsalStore = new IDMMDSALStore(dataBrokerService);
        final IDMStore idmStore = new IDMStore(mdsalStore);

        authNStore.setTimeToLive(getTimeToLive());

        // Register the MD-SAL Token store with OSGI
        final ServiceRegistration<?> serviceRegistration = bundleContext.registerService(
                TokenStore.class.getName(), authNStore, null);
        final ServiceRegistration<?> idmServiceRegistration = bundleContext.registerService(
                IIDMStore.class.getName(), idmStore, null);
        final class AutoCloseableStore implements AutoCloseable {

            @Override
            public void close() throws Exception {
                serviceRegistration.unregister();
                idmServiceRegistration.unregister();
                authNStore.close();
            }
        }

        return new AutoCloseableStore();

        // return authNStore;

        // throw new java.lang.UnsupportedOperationException();
    }

    /**
     * @param bundleContext
     */
    public void setBundleContext(BundleContext bundleContext) {
        this.bundleContext = bundleContext;
    }

    /**
     * @return the bundleContext
     */
    public BundleContext getBundleContext() {
        return bundleContext;
    }

}