a590b982b91250c4f279d5a4bfbccfb20ff93436
[moon.git] /
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.config.yang.config.aaa_authz.srv;
10
11 import org.opendaylight.aaa.api.AuthenticationService;
12 import org.opendaylight.aaa.authz.srv.AuthzBrokerImpl;
13 import org.opendaylight.aaa.authz.srv.AuthzServiceImpl;
14 import org.osgi.framework.BundleContext;
15 import org.osgi.framework.ServiceReference;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class AuthzSrvModule extends
20         org.opendaylight.controller.config.yang.config.aaa_authz.srv.AbstractAuthzSrvModule {
21     private static final Logger LOG = LoggerFactory.getLogger(AuthzSrvModule.class);
22     private static boolean simple_config_switch;
23     private BundleContext bundleContext;
24
25     public AuthzSrvModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
26             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
27         super(identifier, dependencyResolver);
28     }
29
30     public AuthzSrvModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
31             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
32             org.opendaylight.controller.config.yang.config.aaa_authz.srv.AuthzSrvModule oldModule,
33             java.lang.AutoCloseable oldInstance) {
34         super(identifier, dependencyResolver, oldModule, oldInstance);
35     }
36
37     @Override
38     public void customValidation() {
39         // checkNotNull(getDomBroker(), domBrokerJmxAttribute);
40     }
41
42     @Override
43     public java.lang.AutoCloseable createInstance() {
44
45         // Get new AuthZ Broker
46         final AuthzBrokerImpl authzBrokerImpl = new AuthzBrokerImpl();
47
48         // Provide real broker to the new Authz broker
49         authzBrokerImpl.setBroker(getDomBrokerDependency());
50
51         // Get AuthN service reference and register it with the authzBroker
52         ServiceReference<AuthenticationService> authServiceReference = bundleContext
53                 .getServiceReference(AuthenticationService.class);
54         AuthenticationService as = bundleContext.getService(authServiceReference);
55         authzBrokerImpl.setAuthenticationService(as);
56
57         // Set the policies list to authz serviceimpl
58         AuthzServiceImpl.setPolicies(getPolicies());
59
60         // Register AuthZ broker with the real Broker as a provider; triggers
61         // "onSessionInitiated" in AuthzBrokerImpl
62         getDomBrokerDependency().registerProvider(authzBrokerImpl);
63         // TODO ActionType is of type string, not ENUM due to improper
64         // serialization of ENUMs by config/netconf subsystem. This needs to be
65         // fixed as soon as config/netconf fixes the problem.
66         getAction();
67
68         LOG.info("AuthZ Service Initialized from Config subsystem");
69         return authzBrokerImpl;
70
71     }
72
73     public void setBundleContext(BundleContext bundleContext) {
74         this.bundleContext = bundleContext;
75     }
76 }