import org.opendaylight.aaa.api.model.User;
import org.opendaylight.aaa.api.model.Users;
import org.opendaylight.aaa.api.password.service.PasswordHashService;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@Component(immediate = true, configurationPid = "org.opendaylight.aaa.h2", property = "type=default")
+@Designate(ocd = H2Store.Configuration.class)
public class H2Store implements IIDMStore {
+ @ObjectClassDefinition
+ public @interface Configuration {
+ @AttributeDefinition(name = "dbUserName")
+ String username() default "foo";
+ @AttributeDefinition(name = "dbPassword")
+ String password() default "bar";
+ }
private static final Logger LOG = LoggerFactory.getLogger(H2Store.class);
private final RoleStore roleStore;
private final GrantStore grantStore;
+ @Activate
+ public H2Store(@Reference final PasswordHashService passwordService, final Configuration config) {
+ this(config.username(), config.password(), passwordService);
+ LOG.info("H2 IDMStore activated");
+ }
+
public H2Store(final String dbUsername, final String dbPassword, final PasswordHashService passwordService) {
this(new IdmLightSimpleConnectionProvider(
new IdmLightConfigBuilder().dbUser(dbUsername).dbPwd(dbPassword).build()), passwordService);
}
- public H2Store(ConnectionProvider connectionFactory, final PasswordHashService passwordService) {
- this.domainStore = new DomainStore(connectionFactory);
- this.userStore = new UserStore(connectionFactory, passwordService);
- this.roleStore = new RoleStore(connectionFactory);
- this.grantStore = new GrantStore(connectionFactory);
+ public H2Store(final ConnectionProvider connectionFactory, final PasswordHashService passwordService) {
+ domainStore = new DomainStore(connectionFactory);
+ userStore = new UserStore(connectionFactory, passwordService);
+ roleStore = new RoleStore(connectionFactory);
+ grantStore = new GrantStore(connectionFactory);
+ }
+
+ @Deactivate
+ void deactivate() {
+ LOG.info("H2 IDMStore deactivated");
}
@Override
- public Domain writeDomain(Domain domain) throws IDMStoreException {
+ public Domain writeDomain(final Domain domain) throws IDMStoreException {
try {
return domainStore.createDomain(domain);
} catch (StoreException e) {
}
@Override
- public Domain readDomain(String domainid) throws IDMStoreException {
+ public Domain readDomain(final String domainid) throws IDMStoreException {
try {
return domainStore.getDomain(domainid);
} catch (StoreException e) {
}
@Override
- public Domain deleteDomain(String domainid) throws IDMStoreException {
+ public Domain deleteDomain(final String domainid) throws IDMStoreException {
try {
return domainStore.deleteDomain(domainid);
} catch (StoreException e) {
}
@Override
- public Domain updateDomain(Domain domain) throws IDMStoreException {
+ public Domain updateDomain(final Domain domain) throws IDMStoreException {
try {
return domainStore.putDomain(domain);
} catch (StoreException e) {
}
@Override
- public Role writeRole(Role role) throws IDMStoreException {
+ public Role writeRole(final Role role) throws IDMStoreException {
try {
return roleStore.createRole(role);
} catch (StoreException e) {
}
@Override
- public Role readRole(String roleid) throws IDMStoreException {
+ public Role readRole(final String roleid) throws IDMStoreException {
try {
return roleStore.getRole(roleid);
} catch (StoreException e) {
}
@Override
- public Role deleteRole(String roleid) throws IDMStoreException {
+ public Role deleteRole(final String roleid) throws IDMStoreException {
try {
return roleStore.deleteRole(roleid);
} catch (StoreException e) {
}
@Override
- public Role updateRole(Role role) throws IDMStoreException {
+ public Role updateRole(final Role role) throws IDMStoreException {
try {
return roleStore.putRole(role);
} catch (StoreException e) {
}
@Override
- public User writeUser(User user) throws IDMStoreException {
+ public User writeUser(final User user) throws IDMStoreException {
try {
return userStore.createUser(user);
} catch (StoreException e) {
}
@Override
- public User readUser(String userid) throws IDMStoreException {
+ public User readUser(final String userid) throws IDMStoreException {
try {
return userStore.getUser(userid);
} catch (StoreException e) {
}
@Override
- public User deleteUser(String userid) throws IDMStoreException {
+ public User deleteUser(final String userid) throws IDMStoreException {
try {
return userStore.deleteUser(userid);
} catch (StoreException e) {
}
@Override
- public User updateUser(User user) throws IDMStoreException {
+ public User updateUser(final User user) throws IDMStoreException {
try {
return userStore.putUser(user);
} catch (StoreException e) {
}
@Override
- public Users getUsers(String username, String domain) throws IDMStoreException {
+ public Users getUsers(final String username, final String domain) throws IDMStoreException {
try {
return userStore.getUsers(username, domain);
} catch (StoreException e) {
}
@Override
- public Grant writeGrant(Grant grant) throws IDMStoreException {
+ public Grant writeGrant(final Grant grant) throws IDMStoreException {
try {
return grantStore.createGrant(grant);
} catch (StoreException e) {
}
@Override
- public Grant readGrant(String grantid) throws IDMStoreException {
+ public Grant readGrant(final String grantid) throws IDMStoreException {
try {
return grantStore.getGrant(grantid);
} catch (StoreException e) {
}
@Override
- public Grant readGrant(String domainid, String userid, String roleid) throws IDMStoreException {
+ public Grant readGrant(final String domainid, final String userid, final String roleid) throws IDMStoreException {
return readGrant(IDMStoreUtil.createGrantid(userid, domainid, roleid));
}
@Override
- public Grant deleteGrant(String grantid) throws IDMStoreException {
+ public Grant deleteGrant(final String grantid) throws IDMStoreException {
try {
return grantStore.deleteGrant(grantid);
} catch (StoreException e) {
}
@Override
- public Grants getGrants(String domainid, String userid) throws IDMStoreException {
+ public Grants getGrants(final String domainid, final String userid) throws IDMStoreException {
try {
return grantStore.getGrants(domainid, userid);
} catch (StoreException e) {
}
@Override
- public Grants getGrants(String userid) throws IDMStoreException {
+ public Grants getGrants(final String userid) throws IDMStoreException {
try {
return grantStore.getGrants(userid);
} catch (StoreException e) {
}
}
- public Domain createDomain(String domainName, boolean enable) throws StoreException {
+ public Domain createDomain(final String domainName, final boolean enable) throws StoreException {
Domain domain = new Domain();
domain.setName(domainName);
domain.setEnabled(enable);
return domainStore.createDomain(domain);
}
- public User createUser(String name, String password, String domain, String description,
- String email, boolean enabled, String salt) throws StoreException {
+ public User createUser(final String name, final String password, final String domain, final String description,
+ final String email, final boolean enabled, final String salt) throws StoreException {
User user = new User();
user.setName(name);
user.setDomainid(domain);
return userStore.createUser(user);
}
- public Role createRole(String name, String domain, String description)
+ public Role createRole(final String name, final String domain, final String description)
throws StoreException {
Role role = new Role();
role.setDescription(description);
return roleStore.createRole(role);
}
- public Grant createGrant(String domain, String user, String role) throws StoreException {
+ public Grant createGrant(final String domain, final String user, final String role) throws StoreException {
Grant grant = new Grant();
grant.setDomainid(domain);
grant.setRoleid(role);
+++ /dev/null
-/*
- * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.aaa.datastore.h2;
-
-import static com.google.common.base.Verify.verifyNotNull;
-
-import com.google.common.annotations.Beta;
-import org.opendaylight.aaa.api.IDMStoreException;
-import org.opendaylight.aaa.api.IIDMStore;
-import org.opendaylight.aaa.api.model.Domain;
-import org.opendaylight.aaa.api.model.Domains;
-import org.opendaylight.aaa.api.model.Grant;
-import org.opendaylight.aaa.api.model.Grants;
-import org.opendaylight.aaa.api.model.Role;
-import org.opendaylight.aaa.api.model.Roles;
-import org.opendaylight.aaa.api.model.User;
-import org.opendaylight.aaa.api.model.Users;
-import org.opendaylight.aaa.api.password.service.PasswordHashService;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.metatype.annotations.AttributeDefinition;
-import org.osgi.service.metatype.annotations.Designate;
-import org.osgi.service.metatype.annotations.ObjectClassDefinition;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Beta
-@Component(immediate = true, configurationPid = "org.opendaylight.aaa.h2", property = "type=default")
-@Designate(ocd = OSGiH2Store.Configuration.class)
-// FIXME: merge this with H2Store when we have constructor injection
-public final class OSGiH2Store implements IIDMStore {
- @ObjectClassDefinition
- public @interface Configuration {
- @AttributeDefinition(name = "dbUserName")
- String username() default "foo";
- @AttributeDefinition(name = "dbPassword")
- String password() default "bar";
- }
-
- private static final Logger LOG = LoggerFactory.getLogger(OSGiH2Store.class);
-
- @Reference
- PasswordHashService passwordService;
-
- private H2Store delegate;
-
- @Override
- public Domain writeDomain(final Domain domain) throws IDMStoreException {
- return delegate().writeDomain(domain);
- }
-
- @Override
- public Domain readDomain(final String domainid) throws IDMStoreException {
- return delegate().readDomain(domainid);
- }
-
- @Override
- public Domain deleteDomain(final String domainid) throws IDMStoreException {
- return delegate().deleteDomain(domainid);
- }
-
- @Override
- public Domain updateDomain(final Domain domain) throws IDMStoreException {
- return delegate().updateDomain(domain);
- }
-
- @Override
- public Domains getDomains() throws IDMStoreException {
- return delegate().getDomains();
- }
-
- @Override
- public Role writeRole(final Role role) throws IDMStoreException {
- return delegate().writeRole(role);
- }
-
- @Override
- public Role readRole(final String roleid) throws IDMStoreException {
- return delegate().readRole(roleid);
- }
-
- @Override
- public Role deleteRole(final String roleid) throws IDMStoreException {
- return delegate().deleteRole(roleid);
- }
-
- @Override
- public Role updateRole(final Role role) throws IDMStoreException {
- return delegate().updateRole(role);
- }
-
- @Override
- public Roles getRoles() throws IDMStoreException {
- return delegate().getRoles();
- }
-
- @Override
- public User writeUser(final User user) throws IDMStoreException {
- return delegate().writeUser(user);
- }
-
- @Override
- public User readUser(final String userid) throws IDMStoreException {
- return delegate().readUser(userid);
- }
-
- @Override
- public User deleteUser(final String userid) throws IDMStoreException {
- return delegate().deleteUser(userid);
- }
-
- @Override
- public User updateUser(final User user) throws IDMStoreException {
- return delegate().updateUser(user);
- }
-
- @Override
- public Users getUsers() throws IDMStoreException {
- return delegate().getUsers();
- }
-
- @Override
- public Users getUsers(final String username, final String domain) throws IDMStoreException {
- return delegate().getUsers(username, domain);
- }
-
- @Override
- public Grant writeGrant(final Grant grant) throws IDMStoreException {
- return delegate().writeGrant(grant);
- }
-
- @Override
- public Grant readGrant(final String grantid) throws IDMStoreException {
- return delegate().readGrant(grantid);
- }
-
- @Override
- public Grant readGrant(final String domainid, final String userid, final String roleid) throws IDMStoreException {
- return delegate().readGrant(domainid, userid, roleid);
- }
-
- @Override
- public Grant deleteGrant(final String grantid) throws IDMStoreException {
- return delegate().deleteGrant(grantid);
- }
-
- @Override
- public Grants getGrants(final String domainid, final String userid) throws IDMStoreException {
- return delegate().getGrants(domainid, userid);
- }
-
- @Override
- public Grants getGrants(final String userid) throws IDMStoreException {
- return delegate().getGrants(userid);
- }
-
- @Activate
- void activate(final Configuration config) {
- delegate = new H2Store(config.username(), config.password(), passwordService);
- LOG.info("H2 IDMStore activated");
- }
-
- @Deactivate
- void deactivate() {
- delegate = null;
- LOG.info("H2 IDMStore deactivated");
- }
-
- private H2Store delegate() {
- return verifyNotNull(delegate);
- }
-}