2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.cmd.user;
24 import org.onap.aaf.auth.cmd.AAFcli;
25 import org.onap.aaf.auth.cmd.Cmd;
26 import org.onap.aaf.auth.cmd.Param;
27 import org.onap.aaf.auth.rserv.HttpMethods;
28 import org.onap.aaf.cadi.CadiException;
29 import org.onap.aaf.cadi.LocatorException;
30 import org.onap.aaf.cadi.client.Future;
31 import org.onap.aaf.cadi.client.Rcli;
32 import org.onap.aaf.cadi.client.Retryable;
33 import org.onap.aaf.misc.env.APIException;
35 import aaf.v2_0.CredRequest;
37 public class ID extends Cmd {
38 public static final String ATTEMPT_FAILED_SPECIFICS_WITHELD = "Attempt Failed. Specifics witheld.";
39 private static final String CRED_PATH = "/authn/cred";
40 private static final String[] options = {"add","del"};
41 public ID(User parent) {
43 new Param(optionsToString(options),true),
49 public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException {
51 String key = args[idx++];
52 final int option = whichOption(options,key);
54 final CredRequest cr = new CredRequest();
55 cr.setId(args[idx++]);
58 cr.setEntry(args[idx]);
60 // Set Start/End commands
62 Integer ret = same(new Retryable<Integer>() {
64 public Integer code(Rcli<?> client) throws CadiException, APIException {
65 Future<CredRequest> fp=null;
71 getDF(CredRequest.class),
77 setQueryParamsOn(client);
78 fp = client.delete(CRED_PATH,
79 getDF(CredRequest.class),
82 verb = "Deleted ID [";
88 return null; // get by Sonar check.
90 if (fp.get(AAFcli.timeout())) {
92 pw().print(cr.getId());
94 } else if (fp.code()==202) {
95 pw().println("ID Action Accepted, but requires Approvals before actualizing");
96 } else if (fp.code()==409 && option==0) {
97 pw().println("FQI already exists");
98 } else if (fp.code()==406 && option==1) {
99 pw().println("FQI does not exist");
101 pw().println(ATTEMPT_FAILED_SPECIFICS_WITHELD);
106 if (ret==null)ret = -1;
111 public void detailedHelp(int _indent, StringBuilder sb) {
112 int indent = _indent;
113 detailLine(sb,indent,"Add or Delete Fully Qualified Identity: An ID attached to the Namespace");
115 detailLine(sb,indent,"fqi - the ID to create/delete within AAF");
117 detailLine(sb,indent,"This usage has NO Credential, and serves only to allow IDs to be attached");
118 detailLine(sb,indent,"to Roles before credentials such as Certificates are established.");
119 detailLine(sb,indent,"The Domain can be related to any Namespace you have access to *");
120 detailLine(sb,indent,"The Domain is in reverse order of Namespace, i.e. ");
121 detailLine(sb,indent+2,"NS of com.att.myapp can create user of XY1234@myapp.att.com");
123 api(sb,indent,HttpMethods.POST,"authn/cred",CredRequest.class,true);
124 api(sb,indent,HttpMethods.DELETE,"authn/cred",CredRequest.class,false);
125 api(sb,indent,HttpMethods.PUT,"authn/cred",CredRequest.class,false);