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.editattributes;
24 import java.io.IOException;
25 import java.util.List;
27 import org.onap.aai.cl.api.Logger;
28 import org.onap.aai.cl.eelf.LoggerFactory;
29 import org.onap.aai.sparky.logging.AaiUiMsgs;
30 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
33 * Validates users against a user authorization file.
35 public class UserValidator {
37 private static final Logger LOG = LoggerFactory.getInstance().getLogger(UserValidator.class);
38 private static final String USER_AUTH_FILE =
39 SparkyConstants.AUTHORIZED_USERS_FILE_LOCATION;
41 private UserAuthorizationReader userAuthorizationReader =
42 new UserAuthorizationReader(new File(USER_AUTH_FILE));
45 * Returns true if the user is authorized.
47 * @param userId a user identifier
48 * @return true if the user ID is present in the user authorization file
50 public boolean isAuthorizedUser(String userId) {
51 if (userId != null && !userId.isEmpty()) {
53 List<String> users = userAuthorizationReader.getUsers();
54 return users.contains(userId);
55 } catch (IOException exc) {
56 LOG.error(AaiUiMsgs.USER_AUTHORIZATION_FILE_UNAVAILABLE, userId);