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