2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.auth;
24 public class AAIUser {
26 private String username;
28 private boolean isWildcard = false;
29 private Set<String> roles;
30 private Map<String, Set<String>> aaiFunctionToHttpMethod;
32 public AAIUser(String username) {
33 this(username, false);
36 public AAIUser(String username, boolean isWildcard) {
37 this.username = username;
38 this.roles = new HashSet<>();
39 this.aaiFunctionToHttpMethod = new HashMap<>();
40 this.isWildcard = isWildcard;
43 public boolean isWildcard() {
47 public String getUsername() {
51 public void addRole(String role) {
55 public boolean hasRole(String role) {
56 return this.roles.contains(role);
59 public void setUserAccess(String aaiMethod, String... httpMethods) {
60 for (String httpMethod : httpMethods) {
61 this.addUserAccess(aaiMethod, httpMethod);
65 private void addUserAccess(String aaiMethod, String httpMethod) {
66 Set<String> httpMethods = new HashSet<>();
67 if (this.aaiFunctionToHttpMethod.containsKey(aaiMethod)) {
68 httpMethods = this.aaiFunctionToHttpMethod.get(aaiMethod);
70 httpMethods.add(httpMethod);
71 this.aaiFunctionToHttpMethod.put(aaiMethod, httpMethods);
74 public boolean hasAccess(String aaiMethod, String httpMethod) {
75 return this.aaiFunctionToHttpMethod.getOrDefault(aaiMethod, Collections.EMPTY_SET).contains(httpMethod);