4ae027c8ba4d5dab3d7b1f7d115cbb50c51acc14
[moon.git] /
1 /*
2  * Copyright (c) 2014, 2015 Hewlett-Packard Development Company, L.P. 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.aaa.federation;
10
11 import java.util.Dictionary;
12 import org.apache.felix.dm.DependencyActivatorBase;
13 import org.apache.felix.dm.DependencyManager;
14 import org.opendaylight.aaa.api.ClaimAuth;
15 import org.opendaylight.aaa.api.IdMService;
16 import org.opendaylight.aaa.api.TokenStore;
17 import org.osgi.framework.BundleContext;
18 import org.osgi.framework.Constants;
19 import org.osgi.service.cm.ManagedService;
20
21 /**
22  * An activator for the secure token server to inject in a
23  * <code>CredentialAuth</code> implementation.
24  *
25  * @author liemmn
26  *
27  */
28 public class Activator extends DependencyActivatorBase {
29     private static final String FEDERATION_PID = "org.opendaylight.aaa.federation";
30
31     @Override
32     public void init(BundleContext context, DependencyManager manager) throws Exception {
33         manager.add(createComponent()
34                 .setImplementation(ServiceLocator.getInstance())
35                 .add(createServiceDependency().setService(TokenStore.class).setRequired(true))
36                 .add(createServiceDependency().setService(IdMService.class).setRequired(true))
37                 .add(createServiceDependency().setService(ClaimAuth.class).setRequired(false)
38                         .setCallbacks("claimAuthAdded", "claimAuthRemoved")));
39         context.registerService(ManagedService.class, FederationConfiguration.instance(),
40                 addPid(FederationConfiguration.defaults));
41     }
42
43     @Override
44     public void destroy(BundleContext context, DependencyManager manager) throws Exception {
45     }
46
47     private Dictionary<String, ?> addPid(Dictionary<String, String> dict) {
48         dict.put(Constants.SERVICE_PID, FEDERATION_PID);
49         return dict;
50     }
51 }