2 * Copyright (c) 2014, 2015 Hewlett-Packard Development Company, L.P. 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
9 package org.opendaylight.aaa.api;
11 import org.opendaylight.aaa.api.model.Domain;
12 import org.opendaylight.aaa.api.model.Grant;
13 import org.opendaylight.aaa.api.model.Role;
14 import org.opendaylight.aaa.api.model.User;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * StoreBuilder is triggered during feature installation by
20 * <code>AAAIDMLightModule.createInstance()</code>. StoreBuilder is responsible
21 * for initializing the H2 database with initial default user account
22 * information. By default, the following users are created:
28 * By default, the following domain is created:
33 * By default, the following grants are created:
35 * <li>admin with admin role on sdn</li>
36 * <li>admin with user role on sdn</li>
37 * <li>user with user role on sdn</li>
40 * @author peter.mellquist@hp.com
41 * @author saichler@cisco.com
43 public class StoreBuilder {
45 private static final Logger LOG = LoggerFactory.getLogger(StoreBuilder.class);
47 private final IIDMStore store;
49 public StoreBuilder(IIDMStore store) {
54 public void init() throws IDMStoreException {
55 LOG.info("creating idmlight schema in store");
57 // Check whether the default domain exists. If it exists, then do not
58 // create default data in the store.
59 // TODO Address the fact that someone may delete the sdn domain, or make
61 Domain defaultDomain = store.readDomain(IIDMStore.DEFAULT_DOMAIN);
62 if (defaultDomain != null) {
63 LOG.info("Found default domain in Store, skipping insertion of default data");
68 Domain domain = new Domain();
69 User adminUser = new User();
70 User userUser = new User();
71 Role adminRole = new Role();
72 Role userRole = new Role();
73 domain.setEnabled(true);
74 domain.setName(IIDMStore.DEFAULT_DOMAIN);
75 domain.setDescription("default odl sdn domain");
76 domain = store.writeDomain(domain);
78 // Create default users
80 adminUser.setEnabled(true);
81 adminUser.setName("admin");
82 adminUser.setDomainid(domain.getDomainid());
83 adminUser.setDescription("admin user");
84 adminUser.setEmail("");
85 adminUser.setPassword("admin");
86 adminUser = store.writeUser(adminUser);
88 userUser.setEnabled(true);
89 userUser.setName("user");
90 userUser.setDomainid(domain.getDomainid());
91 userUser.setDescription("user user");
92 userUser.setEmail("");
93 userUser.setPassword("user");
94 userUser = store.writeUser(userUser);
96 // Create default Roles ("admin" and "user")
97 adminRole.setName("admin");
98 adminRole.setDomainid(domain.getDomainid());
99 adminRole.setDescription("a role for admins");
100 adminRole = store.writeRole(adminRole);
101 userRole.setName("user");
102 userRole.setDomainid(domain.getDomainid());
103 userRole.setDescription("a role for users");
104 userRole = store.writeRole(userRole);
106 // Create default grants
107 Grant grant = new Grant();
108 grant.setDomainid(domain.getDomainid());
109 grant.setUserid(userUser.getUserid());
110 grant.setRoleid(userRole.getRoleid());
111 grant = store.writeGrant(grant);
113 grant.setDomainid(domain.getDomainid());
114 grant.setUserid(adminUser.getUserid());
115 grant.setRoleid(userRole.getRoleid());
116 grant = store.writeGrant(grant);
118 grant.setDomainid(domain.getDomainid());
119 grant.setUserid(adminUser.getUserid());
120 grant.setRoleid(adminRole.getRoleid());
121 grant = store.writeGrant(grant);