2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
7 * Modification Copyright (c) 2019 IBM
8 * ===========================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END====================================================
24 package org.onap.aaf.auth.cmd.user;
26 import java.util.Collections;
27 import java.util.Comparator;
29 import org.onap.aaf.auth.cmd.AAFcli;
30 import org.onap.aaf.auth.cmd.Cmd;
31 import org.onap.aaf.auth.cmd.Param;
32 import org.onap.aaf.auth.rserv.HttpMethods;
33 import org.onap.aaf.cadi.CadiException;
34 import org.onap.aaf.cadi.LocatorException;
35 import org.onap.aaf.cadi.client.Future;
36 import org.onap.aaf.cadi.client.Rcli;
37 import org.onap.aaf.cadi.client.Retryable;
38 import org.onap.aaf.misc.env.APIException;
40 import aaf.v2_0.Users;
41 import aaf.v2_0.Users.User;
48 public class ListForCreds extends Cmd {
49 private static final String[] options = {"ns","id"};
51 private static final String HEADER = "List creds by Namespace or ID ";
52 public ListForCreds(List parent) {
54 new Param(optionsToString(options),true),
55 new Param("value",true));
59 public int _exec(int idxParam, final String ... args) throws CadiException, APIException, LocatorException {
61 final int option = whichOption(options, args[idx++]);
62 final String which = options[option];
63 final String value = args[idx++];
64 return same(new Retryable<Integer>() {
66 public Integer code(Rcli<?> client) throws CadiException, APIException {
67 Future<Users> fp = client.read(
68 "/authn/creds/"+which+'/'+value,
71 if (fp.get(AAFcli.timeout())) {
73 Collections.sort(fp.value.getUser(), new Comparator<User>() {
75 public int compare(User u1, User u2) {
76 return u1.getId().compareTo(u2.getId());
79 ((org.onap.aaf.auth.cmd.user.List)parent).report(fp.value,option==1,HEADER+which,value);
92 public void detailedHelp(int indentParam, StringBuilder sb) {
93 int indent = indentParam;
94 detailLine(sb,indent,HEADER);
96 detailLine(sb,indent,"This report lists the users associated to either Namespaces or IDs.");
97 detailLine(sb,indent,"ns (literal) - which Namespace");
98 detailLine(sb,indent,"id (literal) - identity");
100 api(sb,indent,HttpMethods.GET,"authn/creds/ns/<ns>",Users.class,true);
101 api(sb,indent,HttpMethods.GET,"authn/creds/id/<identity>",Users.class,true);