Post Init Service Starter
[aaf/authz.git] / auth / auth-cass / src / main / java / org / onap / aaf / auth / dao / hl / CassExecutor.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.dao.hl;
23
24 import org.onap.aaf.auth.dao.cass.NsSplit;
25 import org.onap.aaf.auth.dao.cass.NsDAO.Data;
26 import org.onap.aaf.auth.env.AuthzTrans;
27 import org.onap.aaf.auth.layer.Result;
28 import org.onap.aaf.auth.org.Executor;
29
30 public class CassExecutor implements Executor {
31
32     private Question q;
33     private Function f;
34     private AuthzTrans trans;
35
36     public CassExecutor(AuthzTrans trans, Function f) {
37         this.trans = trans;
38         this.f = f;
39         this.q = this.f.q;
40     }
41
42     @Override
43     public boolean hasPermission(String user, String ns, String type, String instance, String action) {
44         return isGranted(user, ns, type, instance, action);
45     }
46
47     @Override
48     public boolean inRole(String name) {
49         Result<NsSplit> nss = q.deriveNsSplit(trans, name);
50         if (nss.notOK())return false;
51         return q.roleDAO().read(trans, nss.value.ns,nss.value.name).isOKhasData();
52     }
53
54     public boolean isGranted(String user, String ns, String type, String instance, String action) {
55         return q.isGranted(trans, user, ns, type, instance,action);
56     }
57
58     @Override
59     public String namespace() throws Exception {
60         Result<Data> res = q.validNSOfDomain(trans,trans.user());
61         if (res.isOK()) {
62             String user[] = trans.user().split("\\.");
63             return user[user.length-1] + '.' + user[user.length-2];
64         }
65         throw new Exception(res.status + ' ' + res.details);
66     }
67
68     @Override
69     public String id() {
70         return trans.user();
71     }
72
73 }