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.user;
\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.Cmd;
\r
32 import com.att.cmd.Param;
\r
33 import com.att.cssa.rserv.HttpMethods;
\r
34 import com.att.inno.env.APIException;
\r
36 import aaf.v2_0.CredRequest;
\r
38 public class Cred extends Cmd {
\r
39 private static final String CRED_PATH = "/authn/cred";
\r
40 private static final String[] options = {"add","del","reset","extend"/*,"clean"*/};
\r
41 // private Clean clean;
\r
42 public Cred(User parent) {
\r
43 super(parent,"cred",
\r
44 new Param(optionsToString(options),true),
\r
45 new Param("id",true),
\r
46 new Param("password (! D|E)",false),
\r
47 new Param("entry# (if multi)",false)
\r
49 // clean = new Clean(this);
\r
53 public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException {
\r
55 String key = args[idx++];
\r
56 final int option = whichOption(options,key);
\r
58 final CredRequest cr = new CredRequest();
\r
59 cr.setId(args[idx++]);
\r
60 if(option!=1 && option!=3) {
\r
61 if(idx>=args.length) throw new CadiException("Password Required");
\r
62 cr.setPassword(args[idx++]);
\r
65 cr.setEntry(args[idx++]);
\r
67 // Set Start/End commands
\r
69 // final int cleanIDX = _idx+1;
\r
70 Integer ret = same(new Retryable<Integer>() {
\r
72 public Integer code(Rcli<?> client) throws CadiException, APIException {
\r
73 Future<CredRequest> fp=null;
\r
79 getDF(CredRequest.class),
\r
82 verb = "Added Credential [";
\r
85 // if(aafcli.addForce())cr.setForce("TRUE");
\r
86 setQueryParamsOn(client);
\r
87 fp = client.delete(CRED_PATH,
\r
88 getDF(CredRequest.class),
\r
91 verb = "Deleted Credential [";
\r
96 getDF(CredRequest.class),
\r
99 verb = "Reset Credential [";
\r
102 fp = client.update(
\r
104 getDF(CredRequest.class),
\r
107 verb = "Extended Credential [";
\r
110 // return clean.exec(cleanIDX, args);
\r
112 if(fp.get(AAFcli.timeout())) {
\r
114 pw().print(cr.getId());
\r
116 } else if(fp.code()==202) {
\r
117 pw().println("Credential Action Accepted, but requires Approvals before actualizing");
\r
118 } else if(fp.code()==406 && option==1) {
\r
119 pw().println("You cannot delete this Credential");
\r
126 if(ret==null)ret = -1;
\r
131 public void detailedHelp(int _indent, StringBuilder sb) {
\r
132 int indent = _indent;
\r
133 detailLine(sb,indent,"Add, Delete or Reset Credential");
\r
135 detailLine(sb,indent,"id - the ID to create/delete/reset within AAF");
\r
136 detailLine(sb,indent,"password - Company Policy compliant Password (not required for Delete)");
\r
137 detailLine(sb,indent,"entry - selected option when deleting/resetting a cred with multiple entries");
\r
139 detailLine(sb,indent,"The Domain can be related to any Namespace you have access to *");
\r
140 detailLine(sb,indent,"The Domain is in reverse order of Namespace, i.e. ");
\r
141 detailLine(sb,indent+2,"NS of com.att.myapp can create user of XY1234@myapp.att.com");
\r
143 detailLine(sb,indent,"NOTE: AAF does support multiple creds with the same ID. Check with your org if you");
\r
144 detailLine(sb,indent+2,"have this implemented. (For example, this is implemented for MechIDs at AT&T)");
\r
146 detailLine(sb,indent,"Delegates can be listed by the User or by the Delegate");
\r
148 api(sb,indent,HttpMethods.POST,"authn/cred",CredRequest.class,true);
\r
149 api(sb,indent,HttpMethods.DELETE,"authn/cred",CredRequest.class,false);
\r
150 api(sb,indent,HttpMethods.PUT,"authn/cred",CredRequest.class,false);
\r