2 * Copyright (c) 2016, 2017 Inocybe Technologies. 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.cli.dmstore;
11 import org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.commands.Option;
13 import org.opendaylight.aaa.api.IIDMStore;
14 import org.opendaylight.aaa.api.model.Role;
15 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
16 import org.opendaylight.aaa.cli.utils.CliUtils;
17 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
19 @Command(name = "add-role", scope = "aaa", description = "Add role.")
25 public class AddRole extends AaaCliAbstractCommand {
27 @Option(name = "-name", aliases = {
28 "--roleName" }, description = "The role name", required = true, multiValued = false)
29 private String roleName = "";
31 @Option(name = "-dname", aliases = {
32 "--domainName" }, description = "The domain name", required = true, multiValued = false)
33 private String domainName = "";
35 @Option(name = "-desc", aliases = {
36 "--roleDescription" }, description = "The role Description", required = true, multiValued = false)
37 private String roleDesc = "";
39 public AddRole(final IIDMStore identityStore) {
44 protected Object doExecute() throws Exception {
45 if (super.doExecute() == null) {
46 return CliUtils.LOGIN_FAILED_MESS;
48 Role role = new Role();
49 role.setDescription(roleDesc);
50 role.setName(roleName);
51 final String domainId = DataStoreUtils.getDomainId(identityStore, domainName);
52 if (domainId == null) {
53 return "Domain does not exist";
55 role.setDomainid(domainId);
56 role = identityStore.writeRole(role);
58 return "Role " + roleName + " has been created, Role Id is " + role.getRoleid();