AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-service / src / main / java / org / onap / aaf / auth / service / api / API_User.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.service.api;
23
24 import static org.onap.aaf.auth.layer.Result.OK;
25 import static org.onap.aaf.auth.rserv.HttpMethods.GET;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.eclipse.jetty.http.HttpStatus;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.layer.Result;
33 import org.onap.aaf.auth.service.AAF_Service;
34 import org.onap.aaf.auth.service.Code;
35 import org.onap.aaf.auth.service.facade.AuthzFacade;
36 import org.onap.aaf.auth.service.mapper.Mapper.API;
37
38 /**
39  * User Role APIs
40  * @author Jonathan
41  *
42  */
43 public class API_User {
44         /**
45          * Normal Init level APIs
46          * 
47          * @param authzAPI
48          * @param facade
49          * @throws Exception
50          */
51         public static void init(final AAF_Service authzAPI, AuthzFacade facade) throws Exception {
52                 /**
53                  * get all Users who have Permission X
54                  */
55                 authzAPI.route(GET,"/authz/users/perm/:type/:instance/:action",API.USERS,new Code(facade,"Get Users By Permission", true) {
56                         @Override
57                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
58 //                              trans.checkpoint(pathParam(req,"type") + " " 
59 //                                              + pathParam(req,"instance") + " " 
60 //                                              + pathParam(req,"action"));
61 //
62                                 Result<Void> r = context.getUsersByPermission(trans, resp,
63                                                 pathParam(req, ":type"),
64                                                 pathParam(req, ":instance"),
65                                                 pathParam(req, ":action"));
66                                 switch(r.status) {
67                                         case OK:
68                                                 resp.setStatus(HttpStatus.OK_200); 
69                                                 break;
70                                         default:
71                                                 context.error(trans,resp,r);
72                                 }
73                         }
74                 });
75
76
77                 /**
78                  * get all Users who have Role X
79                  */
80                 authzAPI.route(GET,"/authz/users/role/:role",API.USERS,new Code(facade,"Get Users By Role", true) {
81                         @Override
82                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
83                                 Result<Void> r = context.getUsersByRole(trans, resp, pathParam(req, ":role"));
84                                 switch(r.status) {
85                                         case OK:
86                                                 resp.setStatus(HttpStatus.OK_200); 
87                                                 break;
88                                         default:
89                                                 context.error(trans,resp,r);
90                                 }
91                         }
92                 });
93                 
94                 /**
95                  * Get User Role if exists
96                  * @deprecated
97                  */
98                 authzAPI.route(GET,"/authz/userRole/:user/:role",API.USERS,new Code(facade,"Get if User is In Role", true) {
99                         @Override
100                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
101                                 Result<Void> r = context.getUserInRole(trans, resp, pathParam(req,":user"),pathParam(req,":role"));
102                                 switch(r.status) {
103                                         case OK:
104                                                 resp.setStatus(HttpStatus.OK_200); 
105                                                 break;
106                                         default:
107                                                 context.error(trans,resp,r);
108                                 }
109                         }
110                 });
111
112                 /**
113                  * Get User Role if exists
114                  */
115                 authzAPI.route(GET,"/authz/users/:user/:role",API.USERS,new Code(facade,"Get if User is In Role", true) {
116                         @Override
117                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
118                                 Result<Void> r = context.getUserInRole(trans, resp, pathParam(req,":user"),pathParam(req,":role"));
119                                 switch(r.status) {
120                                         case OK:
121                                                 resp.setStatus(HttpStatus.OK_200); 
122                                                 break;
123                                         default:
124                                                 context.error(trans,resp,r);
125                                 }
126                         }
127                 });
128                 
129
130
131         }
132                 
133 }