4d112887f59ecf7da2715281d2d8e2de8591af64
[aai/aai-common.git] / aai-auth / src / main / java / org / openecomp / auth / Auth.java
1 /**
2  * ============LICENSE_START=======================================================
3  * EcompAuth
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
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
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 package org.openecomp.auth;
27
28 import org.apache.http.cookie.Cookie;
29
30 public class Auth {
31   private AuthCore authCore;
32
33   public Auth(String filename) throws Exception {
34     this.authCore = new AuthCore(filename);
35   }
36
37   public boolean auth_basic(String username, String authFunction) throws Exception {
38     return authCore.authorize(username, authFunction);
39   }
40
41   public boolean auth_cookie(Cookie cookie, String authFunction, StringBuilder username)
42     throws Exception {
43     if (cookie == null) {
44       return false;
45     }
46     return authCore.authorize(username.toString(), authFunction);
47   }
48
49   /**
50    *  Returns true if the user is allowed to access a function.
51    * @param authUser
52    *        - String value of the user.
53    * @param authAction
54    *        - String value of the function.
55    */
56   public boolean validateRequest(String authUser, String authAction) throws Exception {
57
58     if (authUser == null || authAction == null) {
59       return false;
60     }
61     return authCore.authorize(authUser, authAction);
62   }
63 }