1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package com.att.cmd.mgmt;
\r
25 import com.att.cadi.CadiException;
\r
26 import com.att.cadi.LocatorException;
\r
27 import com.att.cadi.client.Future;
\r
28 import com.att.cadi.client.Rcli;
\r
29 import com.att.cadi.client.Retryable;
\r
30 import com.att.cmd.AAFcli;
\r
31 import com.att.cmd.BaseCmd;
\r
32 import com.att.cmd.Cmd;
\r
33 import com.att.cmd.Param;
\r
34 import com.att.inno.env.APIException;
\r
36 public class Deny extends BaseCmd<Mgmt> {
\r
37 private final static String[] options = {"add","del"};
\r
39 public Deny(Mgmt mgmt) throws APIException {
\r
40 super(mgmt, "deny");
\r
41 cmds.add(new DenySomething(this,"ip","ipv4or6[,ipv4or6]*"));
\r
42 cmds.add(new DenySomething(this,"id","identity[,identity]*"));
\r
45 public class DenySomething extends Cmd {
\r
47 private boolean isID;
\r
49 public DenySomething(Deny deny, String type, String repeatable) {
\r
51 new Param(optionsToString(options),true),
\r
52 new Param(repeatable,true));
\r
53 isID = "id".equals(type);
\r
57 protected int _exec(int _idx, String... args) throws CadiException, APIException, LocatorException {
\r
59 String action = args[idx++];
\r
60 final int option = whichOption(options, action);
\r
62 for(final String name : args[idx++].split(COMMA)) {
\r
63 final String append;
\r
64 if(isID && name.indexOf("@")<0) {
\r
65 append='@'+ env.getProperty(AAFcli.AAF_DEFAULT_REALM);
\r
69 final String path = "/mgmt/deny/"+getName() + '/'+ name + append;
\r
70 rv = all(new Retryable<Integer>() {
\r
72 public Integer code(Rcli<?> client) throws APIException, CadiException {
\r
78 fp = client.create(path, Void.class);
\r
82 fp = client.delete(path, Void.class);
\r
85 if(fp.get(AAFcli.timeout())) {
\r
86 pw().println(name + append + resp + " on " + client);
\r
89 if(rv==409)rv = fp.code();
\r