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=========================================================
20 package org.onap.policy.utils;
22 import java.util.ArrayList;
23 import java.util.HashSet;
24 import java.util.List;
27 import org.onap.policy.model.Roles;
29 public final class UserUtils {
31 private UserUtils () {
35 public static class Pair<T, U> {
39 public Pair (T t, U u) {
45 public static Pair<Set<String>, List<String>> checkRoleAndScope(List<Object> userRoles) {
48 //Check if the Role and Scope Size are Null get the values from db.
49 roles = new ArrayList<>();
50 scopes = new HashSet<>();
51 for(Object role: userRoles){
52 Roles userRole = (Roles) role;
53 roles.add(userRole.getRole());
54 if(userRole.getScope() != null){
55 if(userRole.getScope().contains(",")){
56 String[] multipleScopes = userRole.getScope().split(",");
57 for(int i =0; i < multipleScopes.length; i++){
58 scopes.add(multipleScopes[i]);
61 scopes.add(userRole.getScope());
65 return new Pair<>(scopes, roles);