07ba51cd90708818b79f3dd47aaae37d497b19d9
[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.aaa.authz.srv;
10
11 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
12 import org.opendaylight.controller.sal.core.api.Broker;
13 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
14 import org.opendaylight.controller.sal.core.api.BrokerService;
15 import org.opendaylight.controller.sal.core.spi.ForwardingConsumerSession;
16
17 /**
18  * Created by wdec on 28/08/2014.
19  */
20 public class AuthzConsumerContextImpl extends ForwardingConsumerSession {
21
22     private final Broker.ConsumerSession realSession;
23
24     public AuthzConsumerContextImpl(Broker.ConsumerSession realSession, AuthzBrokerImpl authzBroker) {
25         this.realSession = realSession;
26     }
27
28     @Override
29     protected ConsumerSession delegate() {
30         return realSession;
31     }
32
33     @Override
34     public <T extends BrokerService> T getService(Class<T> tClass) {
35         T t;
36         // Check for class and return Authz broker only for DOMBroker
37         if (tClass == DOMDataBroker.class) {
38             t = (T) AuthzDomDataBroker.getInstance();
39         } else {
40             t = realSession.getService(tClass);
41         }
42         // AuthzDomDataBroker.getInstance().setDomDataBroker((DOMDataBroker)t);
43         return t;
44     }
45
46 }