0631170eace7960f7fcdcb3c9eb4b0e9025dee9c
[moon.git] /
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  */
9
10 package org.opendaylight.yang.gen.v1.config.aaa.authn.mdsal.store.rev141031;
11
12 import org.opendaylight.aaa.api.IIDMStore;
13 import org.opendaylight.aaa.api.TokenStore;
14 import org.opendaylight.aaa.authn.mdsal.store.AuthNStore;
15 import org.opendaylight.aaa.authn.mdsal.store.IDMMDSALStore;
16 import org.opendaylight.aaa.authn.mdsal.store.IDMStore;
17 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
18 import org.osgi.framework.BundleContext;
19 import org.osgi.framework.ServiceRegistration;
20
21 public class AuthNStoreModule
22         extends
23         org.opendaylight.yang.gen.v1.config.aaa.authn.mdsal.store.rev141031.AbstractAuthNStoreModule {
24     private BundleContext bundleContext;
25
26     public AuthNStoreModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
27             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
28         super(identifier, dependencyResolver);
29     }
30
31     public AuthNStoreModule(
32             org.opendaylight.controller.config.api.ModuleIdentifier identifier,
33             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
34             org.opendaylight.yang.gen.v1.config.aaa.authn.mdsal.store.rev141031.AuthNStoreModule oldModule,
35             java.lang.AutoCloseable oldInstance) {
36         super(identifier, dependencyResolver, oldModule, oldInstance);
37     }
38
39     @Override
40     public void customValidation() {
41         // add custom validation form module attributes here.
42     }
43
44     @Override
45     public java.lang.AutoCloseable createInstance() {
46
47         DataBroker dataBrokerService = getDataBrokerDependency();
48         final AuthNStore authNStore = new AuthNStore(dataBrokerService, getPassword());
49         final IDMMDSALStore mdsalStore = new IDMMDSALStore(dataBrokerService);
50         final IDMStore idmStore = new IDMStore(mdsalStore);
51
52         authNStore.setTimeToLive(getTimeToLive());
53
54         // Register the MD-SAL Token store with OSGI
55         final ServiceRegistration<?> serviceRegistration = bundleContext.registerService(
56                 TokenStore.class.getName(), authNStore, null);
57         final ServiceRegistration<?> idmServiceRegistration = bundleContext.registerService(
58                 IIDMStore.class.getName(), idmStore, null);
59         final class AutoCloseableStore implements AutoCloseable {
60
61             @Override
62             public void close() throws Exception {
63                 serviceRegistration.unregister();
64                 idmServiceRegistration.unregister();
65                 authNStore.close();
66             }
67         }
68
69         return new AutoCloseableStore();
70
71         // return authNStore;
72
73         // throw new java.lang.UnsupportedOperationException();
74     }
75
76     /**
77      * @param bundleContext
78      */
79     public void setBundleContext(BundleContext bundleContext) {
80         this.bundleContext = bundleContext;
81     }
82
83     /**
84      * @return the bundleContext
85      */
86     public BundleContext getBundleContext() {
87         return bundleContext;
88     }
89
90 }