2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.aaa.datastore.h2;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.Beta;
13 import org.opendaylight.aaa.api.IDMStoreException;
14 import org.opendaylight.aaa.api.IIDMStore;
15 import org.opendaylight.aaa.api.model.Domain;
16 import org.opendaylight.aaa.api.model.Domains;
17 import org.opendaylight.aaa.api.model.Grant;
18 import org.opendaylight.aaa.api.model.Grants;
19 import org.opendaylight.aaa.api.model.Role;
20 import org.opendaylight.aaa.api.model.Roles;
21 import org.opendaylight.aaa.api.model.User;
22 import org.opendaylight.aaa.api.model.Users;
23 import org.opendaylight.aaa.api.password.service.PasswordHashService;
24 import org.osgi.service.component.annotations.Activate;
25 import org.osgi.service.component.annotations.Component;
26 import org.osgi.service.component.annotations.Deactivate;
27 import org.osgi.service.component.annotations.Reference;
28 import org.osgi.service.metatype.annotations.AttributeDefinition;
29 import org.osgi.service.metatype.annotations.Designate;
30 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 @Component(immediate = true, configurationPid = "org.opendaylight.aaa.h2", property = "type=default")
36 @Designate(ocd = OSGiH2Store.Configuration.class)
37 // FIXME: merge this with H2Store when we have constructor injection
38 public final class OSGiH2Store implements IIDMStore {
39 @ObjectClassDefinition
40 public @interface Configuration {
41 @AttributeDefinition(name = "dbUserName")
42 String username() default "foo";
43 @AttributeDefinition(name = "dbPassword")
44 String password() default "bar";
47 private static final Logger LOG = LoggerFactory.getLogger(OSGiH2Store.class);
50 PasswordHashService passwordService;
52 private H2Store delegate;
55 public Domain writeDomain(final Domain domain) throws IDMStoreException {
56 return delegate().writeDomain(domain);
60 public Domain readDomain(final String domainid) throws IDMStoreException {
61 return delegate().readDomain(domainid);
65 public Domain deleteDomain(final String domainid) throws IDMStoreException {
66 return delegate().deleteDomain(domainid);
70 public Domain updateDomain(final Domain domain) throws IDMStoreException {
71 return delegate().updateDomain(domain);
75 public Domains getDomains() throws IDMStoreException {
76 return delegate().getDomains();
80 public Role writeRole(final Role role) throws IDMStoreException {
81 return delegate().writeRole(role);
85 public Role readRole(final String roleid) throws IDMStoreException {
86 return delegate().readRole(roleid);
90 public Role deleteRole(final String roleid) throws IDMStoreException {
91 return delegate().deleteRole(roleid);
95 public Role updateRole(final Role role) throws IDMStoreException {
96 return delegate().updateRole(role);
100 public Roles getRoles() throws IDMStoreException {
101 return delegate().getRoles();
105 public User writeUser(final User user) throws IDMStoreException {
106 return delegate().writeUser(user);
110 public User readUser(final String userid) throws IDMStoreException {
111 return delegate().readUser(userid);
115 public User deleteUser(final String userid) throws IDMStoreException {
116 return delegate().deleteUser(userid);
120 public User updateUser(final User user) throws IDMStoreException {
121 return delegate().updateUser(user);
125 public Users getUsers() throws IDMStoreException {
126 return delegate().getUsers();
130 public Users getUsers(final String username, final String domain) throws IDMStoreException {
131 return delegate().getUsers(username, domain);
135 public Grant writeGrant(final Grant grant) throws IDMStoreException {
136 return delegate().writeGrant(grant);
140 public Grant readGrant(final String grantid) throws IDMStoreException {
141 return delegate().readGrant(grantid);
145 public Grant readGrant(final String domainid, final String userid, final String roleid) throws IDMStoreException {
146 return delegate().readGrant(domainid, userid, roleid);
150 public Grant deleteGrant(final String grantid) throws IDMStoreException {
151 return delegate().deleteGrant(grantid);
155 public Grants getGrants(final String domainid, final String userid) throws IDMStoreException {
156 return delegate().getGrants(domainid, userid);
160 public Grants getGrants(final String userid) throws IDMStoreException {
161 return delegate().getGrants(userid);
165 void activate(final Configuration config) {
166 delegate = new H2Store(config.username(), config.password(), passwordService);
167 LOG.info("H2 IDMStore activated");
173 LOG.info("H2 IDMStore deactivated");
176 private H2Store delegate() {
177 return verifyNotNull(delegate);