2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sparky.security.portal.config;
23 import java.io.IOException;
24 import java.lang.reflect.Type;
25 import java.net.URISyntaxException;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.Collections;
29 import java.util.List;
31 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
32 import org.openecomp.portalsdk.core.restful.domain.EcompRole;
34 import com.google.gson.Gson;
35 import com.google.gson.JsonSyntaxException;
36 import com.google.gson.reflect.TypeToken;
39 * Provides roles configuration.
41 public class RolesConfig {
43 private List<EcompRole> roles;
45 private static final Gson GSON = new Gson();
46 private static final String ROLES_CONFIG_FILE = SparkyConstants.ROLES_FILE_LOCATION;
48 private RolesConfig() {
49 // Prevent instantiation
52 private static class RolesConfigHelper {
53 private static final RolesConfig INSTANCE = new RolesConfig();
55 private RolesConfigHelper() {
61 * Get a singleton instance of the configuration.
65 public static RolesConfig getInstance() {
67 RolesConfigHelper.INSTANCE.load();
68 } catch (Exception e) {
69 throw new ExceptionInInitializerError(e);
72 return RolesConfigHelper.INSTANCE;
75 public List<EcompRole> getRoles() {
79 private void load() throws JsonSyntaxException, IOException, URISyntaxException {
80 Type collectionType = new TypeToken<List<EcompRole>>() {
83 roles = Collections.unmodifiableList(GSON
84 .fromJson(new String(Files.readAllBytes(Paths.get(ROLES_CONFIG_FILE))), collectionType));