Revert "Switch to using gson for JSON serialization"
[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.commands.Command;
12 import org.apache.karaf.shell.commands.Option;
13 import org.opendaylight.aaa.api.IIDMStore;
14 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
15 import org.opendaylight.aaa.cli.utils.CliUtils;
16 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
17 import org.opendaylight.aaa.impl.shiro.idm.IdmLightProxy;
18
19 @Command(name = "remove-grant", scope = "aaa", description = "Remove grant.")
20
21 /**
22  * @author mserngawy
23  *
24  */
25 public class RemoveGrant extends AaaCliAbstractCommand {
26
27     @Option(name = "-uname", aliases = {
28             "--userName" }, description = "The user name", required = true, multiValued = false)
29     private String userName = "";
30
31     @Option(name = "-dname", aliases = {
32             "--domainName" }, description = "The domain name", required = true, multiValued = false)
33     private String domainName = "";
34
35     @Option(name = "-rname", aliases = {
36             "--roleName" }, description = "The role name", required = false, multiValued = false)
37     private String roleName = "";
38
39     public RemoveGrant(final IIDMStore identityStore) {
40         super(identityStore);
41     }
42
43     @Override
44     protected Object doExecute() throws Exception {
45         if (super.doExecute() == null) {
46             return CliUtils.LOGIN_FAILED_MESS;
47         }
48         final String grantid = DataStoreUtils.getGrantId(identityStore, domainName, roleName, userName);
49         if (grantid == null) {
50             return "Grant does not exist";
51         }
52         if (identityStore.deleteGrant(grantid) == null) {
53             return "Failed to delete grant " + userName + " " + roleName + " " + domainName;
54         }
55         IdmLightProxy.clearClaimCache();
56         return "Grant has been deleted.";
57     }
58 }