d68726358dda4588e6284368208cf75c4878775c
[moon.git] /
1 package org.opendaylight.yang.gen.v1.config.aaa.authn.idmlight.rev151204;
2
3 import org.opendaylight.aaa.api.CredentialAuth;
4 import org.opendaylight.aaa.api.IDMStoreException;
5 import org.opendaylight.aaa.api.IIDMStore;
6 import org.opendaylight.aaa.api.IdMService;
7 import org.opendaylight.aaa.idm.IdmLightProxy;
8 import org.opendaylight.aaa.idm.StoreBuilder;
9 import org.osgi.framework.BundleContext;
10 import org.osgi.framework.ServiceReference;
11 import org.osgi.framework.ServiceRegistration;
12 import org.osgi.util.tracker.ServiceTracker;
13 import org.osgi.util.tracker.ServiceTrackerCustomizer;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class AAAIDMLightModule extends org.opendaylight.yang.gen.v1.config.aaa.authn.idmlight.rev151204.AbstractAAAIDMLightModule {
18
19     private static final Logger LOG = LoggerFactory.getLogger(AAAIDMLightModule.class);
20     private BundleContext bundleContext = null;
21     private static volatile IIDMStore store = null;
22
23     public AAAIDMLightModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
24         super(identifier, dependencyResolver);
25     }
26
27     public AAAIDMLightModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.config.aaa.authn.idmlight.rev151204.AAAIDMLightModule oldModule, java.lang.AutoCloseable oldInstance) {
28         super(identifier, dependencyResolver, oldModule, oldInstance);
29     }
30
31     @Override
32     public void customValidation() {
33         // add custom validation form module attributes here.
34     }
35
36     @Override
37     public java.lang.AutoCloseable createInstance() {
38         final IdmLightProxy proxy = new IdmLightProxy();
39         final ServiceRegistration<?> idmService = bundleContext.registerService(IdMService.class.getName(), proxy, null);
40         final ServiceRegistration<?> clientAuthService = bundleContext.registerService(CredentialAuth.class.getName(), proxy, null);
41
42         final ServiceTracker<IIDMStore, IIDMStore> storeServiceTracker = new ServiceTracker<>(bundleContext, IIDMStore.class,
43                 new ServiceTrackerCustomizer<IIDMStore, IIDMStore>() {
44                     @Override
45                     public IIDMStore addingService(ServiceReference<IIDMStore> reference) {
46                         store = reference.getBundle().getBundleContext().getService(reference);
47                         LOG.info("IIDMStore service {} was found", store.getClass());
48                         try {
49                             StoreBuilder.init(store);
50                         } catch (IDMStoreException e) {
51                             LOG.error("Failed to initialize data in store", e);
52                         }
53
54                         return store;
55                     }
56
57                     @Override
58                     public void modifiedService(ServiceReference<IIDMStore> reference, IIDMStore service) {
59                     }
60
61                     @Override
62                     public void removedService(ServiceReference<IIDMStore> reference, IIDMStore service) {
63                     }
64                 });
65
66         storeServiceTracker.open();
67
68         LOG.info("AAA IDM Light Module Initialized");
69         return new AutoCloseable() {
70             @Override
71             public void close() throws Exception {
72                 idmService.unregister();
73                 clientAuthService.unregister();
74                 storeServiceTracker.close();
75             }
76         };
77     }
78
79     public void setBundleContext(BundleContext b){
80         this.bundleContext = b;
81     }
82
83     public static final IIDMStore getStore(){
84         return store;
85     }
86
87     public static final void setStore(IIDMStore s){
88         store = s;
89     }
90 }