Merge "XSQL Karaf Command"
[controller.git] / opendaylight / netconf / netconf-usermanager / src / main / java / org / opendaylight / controller / netconf / auth / usermanager / AuthProviderActivator.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.netconf.auth.usermanager;
10
11 import java.util.Hashtable;
12 import org.opendaylight.controller.netconf.auth.AuthConstants;
13 import org.opendaylight.controller.netconf.auth.AuthProvider;
14 import org.osgi.framework.BundleActivator;
15 import org.osgi.framework.BundleContext;
16 import org.osgi.framework.ServiceRegistration;
17
18 public class AuthProviderActivator implements BundleActivator {
19
20     public static final int PREFERENCE = 0;
21     private ServiceRegistration<AuthProvider> authProviderServiceRegistration;
22
23     @Override
24     public void start(final BundleContext context) throws Exception {
25         final AuthProvider authProvider = new AuthProviderImpl(context);
26         // Set preference of this service to 0
27         final Hashtable<String, Object> properties = new Hashtable<>(1);
28         properties.put(AuthConstants.SERVICE_PREFERENCE_KEY, PREFERENCE);
29
30         authProviderServiceRegistration = context.registerService(AuthProvider.class, authProvider, properties);
31     }
32
33     @Override
34     public void stop(final BundleContext context) throws Exception {
35         if(authProviderServiceRegistration != null) {
36             authProviderServiceRegistration.unregister();
37         }
38     }
39 }