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.controller.PolicyController;
28 import org.onap.policy.model.Roles;
30 public final class UserUtils {
32 private UserUtils () {
36 public static class Pair<T, U> {
40 public Pair (T t, U u) {
46 public static Pair<Set<String>, List<String>> checkRoleAndScope(List<Object> userRoles) {
49 //Check if the Role and Scope Size are Null get the values from db.
50 // List<Object> userRoles = ;
51 roles = new ArrayList<>();
52 scopes = new HashSet<>();
53 for(Object role: userRoles){
54 Roles userRole = (Roles) role;
55 roles.add(userRole.getRole());
56 if(userRole.getScope() != null){
57 if(userRole.getScope().contains(",")){
58 String[] multipleScopes = userRole.getScope().split(",");
59 for(int i =0; i < multipleScopes.length; i++){
60 scopes.add(multipleScopes[i]);
63 scopes.add(userRole.getScope());
67 return new Pair<>(scopes, roles);