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.api.action.Command;
12 import org.apache.karaf.shell.api.action.Option;
13 import org.apache.karaf.shell.api.action.lifecycle.Service;
14 import org.opendaylight.aaa.api.model.Role;
15 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
16 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
24 @Command(name = "add-role", scope = "aaa", description = "Add role.")
25 public class AddRole extends AaaCliAbstractCommand {
26 @Option(name = "-name",
27 aliases = { "--roleName" },
28 description = "The role name",
31 private String roleName;
33 @Option(name = "-dname",
34 aliases = { "--domainName" },
35 description = "The domain name",
38 private String domainName;
40 @Option(name = "-desc",
41 aliases = { "--roleDescription" },
42 description = "The role Description",
45 private String roleDesc;
48 public Object execute() throws Exception {
49 if (super.execute() == null) {
50 return LOGIN_FAILED_MESS;
52 Role role = new Role();
53 role.setDescription(roleDesc);
54 role.setName(roleName);
55 final String domainId = DataStoreUtils.getDomainId(identityStore, domainName);
56 if (domainId == null) {
57 return "Domain does not exist";
59 role.setDomainid(domainId);
60 role = identityStore.writeRole(role);
62 return "Role " + roleName + " has been created, Role Id is " + role.getRoleid();