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=========================================================
23 package org.onap.aai.auth;
27 public class AAIUser {
29 private String username;
31 private boolean isWildcard = false;
32 private Set<String> roles;
33 private Map<String, Set<String>> aaiFunctionToHttpMethod;
35 public AAIUser(String username) {
36 this(username, false);
39 public AAIUser(String username, boolean isWildcard) {
40 this.username = username;
41 this.roles = new HashSet<>();
42 this.aaiFunctionToHttpMethod = new HashMap<>();
43 this.isWildcard = isWildcard;
46 public boolean isWildcard() {
50 public String getUsername() {
54 public void addRole(String role) {
58 public boolean hasRole(String role) {
59 return this.roles.contains(role);
62 public void setUserAccess(String aaiMethod, String... httpMethods) {
63 for (String httpMethod : httpMethods) {
64 this.addUserAccess(aaiMethod, httpMethod);
68 private void addUserAccess(String aaiMethod, String httpMethod) {
69 Set<String> httpMethods = new HashSet<>();
70 if (this.aaiFunctionToHttpMethod.containsKey(aaiMethod)) {
71 httpMethods = this.aaiFunctionToHttpMethod.get(aaiMethod);
73 httpMethods.add(httpMethod);
74 this.aaiFunctionToHttpMethod.put(aaiMethod, httpMethods);
77 public boolean hasAccess(String aaiMethod, String httpMethod) {
78 return this.aaiFunctionToHttpMethod.getOrDefault(aaiMethod, Collections.emptySet()).contains(httpMethod);