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 private static final String CRED_PATH = "/authn/cred";
39 private static final String[] options = {"add","del"};
40 public ID(User parent) {
42 new Param(optionsToString(options),true),
48 public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException {
50 String key = args[idx++];
51 final int option = whichOption(options,key);
53 final CredRequest cr = new CredRequest();
54 cr.setId(args[idx++]);
57 cr.setEntry(args[idx]);
59 // Set Start/End commands
61 Integer ret = same(new Retryable<Integer>() {
63 public Integer code(Rcli<?> client) throws CadiException, APIException {
64 Future<CredRequest> fp=null;
70 getDF(CredRequest.class),
76 setQueryParamsOn(client);
77 fp = client.delete(CRED_PATH,
78 getDF(CredRequest.class),
81 verb = "Deleted ID [";
87 return null; // get by Sonar check.
89 if (fp.get(AAFcli.timeout())) {
91 pw().print(cr.getId());
93 } else if (fp.code()==202) {
94 pw().println("ID Action Accepted, but requires Approvals before actualizing");
95 } else if (fp.code()==409 && option==0) {
96 pw().println("FQI already exists");
97 } else if (fp.code()==406 && option==1) {
98 pw().println("FQI does not exist");
100 pw().println(Cred.ATTEMPT_FAILED_SPECIFICS_WITHELD);
105 if (ret==null)ret = -1;
110 public void detailedHelp(int _indent, StringBuilder sb) {
111 int indent = _indent;
112 detailLine(sb,indent,"Add or Delete Fully Qualified Identity: An ID attached to the Namespace");
114 detailLine(sb,indent,"fqi - the ID to create/delete within AAF");
116 detailLine(sb,indent,"This usage has NO Credential, and serves only to allow IDs to be attached");
117 detailLine(sb,indent,"to Roles before credentials such as Certificates are established.");
118 detailLine(sb,indent,"The Domain can be related to any Namespace you have access to *");
119 detailLine(sb,indent,"The Domain is in reverse order of Namespace, i.e. ");
120 detailLine(sb,indent+2,"NS of com.att.myapp can create user of XY1234@myapp.att.com");
122 api(sb,indent,HttpMethods.POST,"authn/cred",CredRequest.class,true);
123 api(sb,indent,HttpMethods.DELETE,"authn/cred",CredRequest.class,false);
124 api(sb,indent,HttpMethods.PUT,"authn/cred",CredRequest.class,false);