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