Revert "Switch to using gson for JSON serialization"
[aaa.git] / aaa-cli / src / main / java / org / opendaylight / aaa / cli / dmstore / RemoveRole.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-role", scope = "aaa", description = "Remove role.")
20
21 /**
22  * @author mserngawy
23  *
24  */
25 public class RemoveRole extends AaaCliAbstractCommand {
26
27     @Option(name = "-name", aliases = {
28             "--roleName" }, description = "The role name", required = true, multiValued = false)
29     private final String roleName = "";
30
31     public RemoveRole(final IIDMStore identityStore) {
32         super(identityStore);
33     }
34
35     @Override
36     protected Object doExecute() throws Exception {
37         if (super.doExecute() == null) {
38             return CliUtils.LOGIN_FAILED_MESS;
39         }
40         final String roleId = DataStoreUtils.getRoleId(identityStore, roleName);
41         if (roleId == null) {
42             return "Role does not exist";
43         }
44         if (identityStore.deleteRole(roleId) == null) {
45             return "Failed to delete role " + roleName;
46         }
47         IdmLightProxy.clearClaimCache();
48         return "Role " + roleName + "has been deleted.";
49     }
50 }