2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.security.portal.config;
25 import java.io.IOException;
26 import java.lang.reflect.Type;
27 import java.net.URISyntaxException;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import java.util.Collections;
31 import java.util.List;
33 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
34 import org.openecomp.portalsdk.core.restful.domain.EcompRole;
36 import com.google.gson.Gson;
37 import com.google.gson.JsonSyntaxException;
38 import com.google.gson.reflect.TypeToken;
41 * Provides roles configuration.
43 public class RolesConfig {
45 private List<EcompRole> roles;
47 private static final Gson GSON = new Gson();
48 private static final String ROLES_CONFIG_FILE = TierSupportUiConstants.ROLES_FILE_LOCATION;
50 private RolesConfig() {
51 // Prevent instantiation
54 private static class RolesConfigHelper {
55 private static final RolesConfig INSTANCE = new RolesConfig();
57 private RolesConfigHelper() {
63 * Get a singleton instance of the configuration.
67 public static RolesConfig getInstance() {
69 RolesConfigHelper.INSTANCE.load();
70 } catch (Exception e) {
71 throw new ExceptionInInitializerError(e);
74 return RolesConfigHelper.INSTANCE;
77 public List<EcompRole> getRoles() {
81 private void load() throws JsonSyntaxException, IOException, URISyntaxException {
82 Type collectionType = new TypeToken<List<EcompRole>>() {}.getType();
84 roles = Collections.unmodifiableList(GSON
85 .fromJson(new String(Files.readAllBytes(Paths.get(ROLES_CONFIG_FILE))), collectionType));