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.role;
25 import java.util.TreeMap;
27 import org.onap.aaf.auth.cmd.AAFcli;
28 import org.onap.aaf.auth.cmd.Cmd;
29 import org.onap.aaf.auth.cmd.Param;
30 import org.onap.aaf.auth.rserv.HttpMethods;
31 import org.onap.aaf.cadi.CadiException;
32 import org.onap.aaf.cadi.LocatorException;
33 import org.onap.aaf.cadi.client.Future;
34 import org.onap.aaf.cadi.client.Rcli;
35 import org.onap.aaf.cadi.client.Retryable;
36 import org.onap.aaf.cadi.util.Split;
37 import org.onap.aaf.misc.env.APIException;
40 import aaf.v2_0.Perms;
42 import aaf.v2_0.Roles;
43 import aaf.v2_0.UserRole;
44 import aaf.v2_0.UserRoles;
51 public class ListByUser extends Cmd {
52 private static final String HEADER = "List Roles for User ";
54 public ListByUser(List parent) {
57 new Param("detail", false));
61 public int _exec( int idx, final String ... args) throws CadiException, APIException, LocatorException {
62 final String user=fullID(args[idx]);
65 return same(new Retryable<Integer>() {
67 public Integer code(Rcli<?> client) throws CadiException, APIException {
72 Future<UserRoles> fur = client.read(
73 "/authz/userRoles/user/"+user,
74 getDF(UserRoles.class)
76 if (fur.get(AAFcli.timeout())) {
84 if (aafcli.isDetailed()) {
86 Future<Perms> fp = client.read(
87 "/authz/perms/user/"+user+"?ns&force",
90 if (fp.get(AAFcli.timeout())) {
91 Map<String, Role> rs = new TreeMap<>();
93 for( Perm p : perms.getPerm()) {
94 for(String sr : p.getRoles()) {
98 String[] split = Split.split('|', sr);
106 roles.getRole().add(r);
115 java.util.List<Role> lr = roles.getRole();
117 for(UserRole ur : urs.getUserRole()) {
119 r.setName(ur.getRole());
125 ((List)parent).report(roles,perms,urs,HEADER,user);
132 public void detailedHelp(int indent, StringBuilder sb) {
133 detailLine(sb,indent,HEADER);
134 api(sb,indent,HttpMethods.GET,"authz/roles/user/<user>",Roles.class,true);