Bump MRI upstreams
[aaa.git] / aaa-cli / src / main / java / org / opendaylight / aaa / cli / dmstore / RemoveGrant.java
1 /*
2  * Copyright (c) 2016, 2017 Inocybe Technologies. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.aaa.cli.dmstore;
10
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.cli.AaaCliAbstractCommand;
15 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
16
17 /**
18  * Removes a grant.
19  *
20  * @author mserngawy
21  */
22 @Service
23 @Command(name = "remove-grant", scope = "aaa", description = "Remove grant.")
24 public class RemoveGrant extends AaaCliAbstractCommand {
25     @Option(name = "-uname",
26             aliases = { "--userName" },
27             description = "The user name",
28             required = true,
29             multiValued = false)
30     private String userName;
31
32     @Option(name = "-dname",
33             aliases = { "--domainName" },
34             description = "The domain name",
35             required = true,
36             multiValued = false)
37     private String domainName;
38
39     @Option(name = "-rname",
40             aliases = { "--roleName" },
41             description = "The role name",
42             required = false,
43             multiValued = false)
44     private String roleName;
45
46     @Override
47     public Object execute() throws Exception {
48         if (super.execute() == null) {
49             return LOGIN_FAILED_MESS;
50         }
51         final String grantid = DataStoreUtils.getGrantId(identityStore, domainName, roleName, userName);
52         if (grantid == null) {
53             return "Grant does not exist";
54         }
55         if (identityStore.deleteGrant(grantid) == null) {
56             return "Failed to delete grant " + userName + " " + roleName + " " + domainName;
57         }
58         return "Grant has been deleted.";
59     }
60 }