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 java.io.UnsupportedEncodingException;
25 import java.net.URLEncoder;
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.cadi.config.Config;
39 import org.onap.aaf.misc.env.APIException;
41 import aaf.v2_0.Users;
42 import aaf.v2_0.Users.User;
49 public class ListForPermission extends Cmd {
50 private static final String HEADER = "List Users for Permission";
51 public ListForPermission(List parent) {
53 new Param("type",true),
54 new Param("instance",true),
55 new Param("action",true));
59 public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {
60 return same(new Retryable<Integer>() {
62 public Integer code(Rcli<?> client) throws CadiException, APIException {
64 String type = args[idx++];
65 String instance = args[idx++];
66 if ("\\*".equals(instance))instance="*";
67 String action = args[idx++];
68 if ("\\*".equals(action))action="*";
70 Future<Users> fp = client.read(
71 "/authz/users/perm/" +
73 URLEncoder.encode(instance,Config.UTF_8) + '/' +
77 if (fp.get(AAFcli.timeout())) {
79 Collections.sort(fp.value.getUser(), (Comparator<User>) (u1, u2) -> u1.getId().compareTo(u2.getId()));
80 ((org.onap.aaf.auth.cmd.user.List)parent).report(fp.value,false,HEADER,type+"|"+instance+"|"+action);
81 if (fp.code()==404)return 200;
86 } catch (UnsupportedEncodingException e) {
87 throw new CadiException(e);
94 public void detailedHelp(int _indent, StringBuilder sb) {
96 detailLine(sb,indent,HEADER);
98 detailLine(sb,indent,"This report lists the users associated to Permissions. Since Users");
99 detailLine(sb,indent,"are associated to Roles, and Roles have Permissions, this report");
100 detailLine(sb,indent,"accomodates all these linkages.");
102 detailLine(sb,indent,"The URL must contain the Permission's type,instance and action, and ");
103 detailLine(sb,indent,"may include \"*\"s (type in as \\\\*).");
104 detailLine(sb,indent,"See Perm Create Documentation for definitions.");
106 api(sb,indent,HttpMethods.GET,"authz/users/perm/<type>/<instance>/<action>",Users.class,true);