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.Grant;
15 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
16 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
24 @Command(name = "add-grant", scope = "aaa", description = "Add Grant.")
25 public class AddGrant extends AaaCliAbstractCommand {
26 @Option(name = "-uname",
27 aliases = { "--userName" },
28 description = "The user name",
31 private String userName;
33 @Option(name = "-dname",
34 aliases = { "--domainName" },
35 description = "The domain name",
38 private String domainName;
40 @Option(name = "-rname",
41 aliases = { "--roleName" },
42 description = "The role name",
45 private String roleName;
48 public Object execute() throws Exception {
49 if (super.execute() == null) {
50 return LOGIN_FAILED_MESS;
52 final String domainId = DataStoreUtils.getDomainId(identityStore, domainName);
53 if (domainId == null) {
54 return "Domain does not exist";
56 final String roleId = DataStoreUtils.getRoleId(identityStore, roleName);
58 return "Role does not exist";
60 final String usrId = DataStoreUtils.getUserId(identityStore, userName);
62 return "User does not exist";
64 Grant grant = new Grant();
65 grant.setDomainid(domainId);
66 grant.setRoleid(roleId);
67 grant.setUserid(usrId);
68 grant = identityStore.writeGrant(grant);
70 return "Grant has been created, Grant id is " + grant.getGrantid();