2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2018 IBM.
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 package org.onap.aai.auth;
26 public class AAIUser {
28 private String username;
30 private boolean isWildcard = false;
31 private Set<String> roles;
32 private Map<String, Set<String>> aaiFunctionToHttpMethod;
34 public AAIUser(String username) {
35 this(username, false);
38 public AAIUser(String username, boolean isWildcard) {
39 this.username = username;
40 this.roles = new HashSet<>();
41 this.aaiFunctionToHttpMethod = new HashMap<>();
42 this.isWildcard = isWildcard;
45 public boolean isWildcard() {
49 public String getUsername() {
53 public void addRole(String role) {
57 public boolean hasRole(String role) {
58 return this.roles.contains(role);
61 public void setUserAccess(String aaiMethod, String... httpMethods) {
62 for (String httpMethod : httpMethods) {
63 this.addUserAccess(aaiMethod, httpMethod);
67 private void addUserAccess(String aaiMethod, String httpMethod) {
68 Set<String> httpMethods = new HashSet<>();
69 if (this.aaiFunctionToHttpMethod.containsKey(aaiMethod)) {
70 httpMethods = this.aaiFunctionToHttpMethod.get(aaiMethod);
72 httpMethods.add(httpMethod);
73 this.aaiFunctionToHttpMethod.put(aaiMethod, httpMethods);
76 public boolean hasAccess(String aaiMethod, String httpMethod) {
77 return this.aaiFunctionToHttpMethod.getOrDefault(aaiMethod, Collections.emptySet()).contains(httpMethod);