AT&T 2.0.19 Code drop, stage 4
[aaf/authz.git] / authz-service / src / main / java / org / onap / aaf / authz / service / api / API_User.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.authz.service.api;\r
24 \r
25 import static org.onap.aaf.authz.layer.Result.OK;\r
26 import static org.onap.aaf.cssa.rserv.HttpMethods.GET;\r
27 \r
28 import javax.servlet.http.HttpServletRequest;\r
29 import javax.servlet.http.HttpServletResponse;\r
30 \r
31 import org.onap.aaf.authz.env.AuthzTrans;\r
32 import org.onap.aaf.authz.facade.AuthzFacade;\r
33 import org.onap.aaf.authz.layer.Result;\r
34 import org.onap.aaf.authz.service.AuthAPI;\r
35 import org.onap.aaf.authz.service.Code;\r
36 import org.onap.aaf.authz.service.mapper.Mapper.API;\r
37 \r
38 import com.att.aft.dme2.internal.jetty.http.HttpStatus;\r
39 \r
40 /**\r
41  * User Role APIs\r
42  *\r
43  */\r
44 public class API_User {\r
45         /**\r
46          * Normal Init level APIs\r
47          * \r
48          * @param authzAPI\r
49          * @param facade\r
50          * @throws Exception\r
51          */\r
52         public static void init(final AuthAPI authzAPI, AuthzFacade facade) throws Exception {\r
53                 /**\r
54                  * get all Users who have Permission X\r
55                  */\r
56                 authzAPI.route(GET,"/authz/users/perm/:type/:instance/:action",API.USERS,new Code(facade,"Get Users By Permission", true) {\r
57                         @Override\r
58                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
59 //                              trans.checkpoint(pathParam(req,"type") + " " \r
60 //                                              + pathParam(req,"instance") + " " \r
61 //                                              + pathParam(req,"action"));\r
62 //\r
63                                 Result<Void> r = context.getUsersByPermission(trans, resp,\r
64                                                 pathParam(req, ":type"),\r
65                                                 pathParam(req, ":instance"),\r
66                                                 pathParam(req, ":action"));\r
67                                 switch(r.status) {\r
68                                         case OK:\r
69                                                 resp.setStatus(HttpStatus.OK_200); \r
70                                                 break;\r
71                                         default:\r
72                                                 context.error(trans,resp,r);\r
73                                 }\r
74                         }\r
75                 });\r
76 \r
77 \r
78                 /**\r
79                  * get all Users who have Role X\r
80                  */\r
81                 authzAPI.route(GET,"/authz/users/role/:role",API.USERS,new Code(facade,"Get Users By Role", true) {\r
82                         @Override\r
83                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
84                                 Result<Void> r = context.getUsersByRole(trans, resp, pathParam(req, ":role"));\r
85                                 switch(r.status) {\r
86                                         case OK:\r
87                                                 resp.setStatus(HttpStatus.OK_200); \r
88                                                 break;\r
89                                         default:\r
90                                                 context.error(trans,resp,r);\r
91                                 }\r
92                         }\r
93                 });\r
94                 \r
95                 /**\r
96                  * Get User Role if exists\r
97                  * @deprecated\r
98                  */\r
99                 authzAPI.route(GET,"/authz/userRole/:user/:role",API.USERS,new Code(facade,"Get if User is In Role", true) {\r
100                         @Override\r
101                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
102                                 Result<Void> r = context.getUserInRole(trans, resp, pathParam(req,":user"),pathParam(req,":role"));\r
103                                 switch(r.status) {\r
104                                         case OK:\r
105                                                 resp.setStatus(HttpStatus.OK_200); \r
106                                                 break;\r
107                                         default:\r
108                                                 context.error(trans,resp,r);\r
109                                 }\r
110                         }\r
111                 });\r
112 \r
113                 /**\r
114                  * Get User Role if exists\r
115                  */\r
116                 authzAPI.route(GET,"/authz/users/:user/:role",API.USERS,new Code(facade,"Get if User is In Role", true) {\r
117                         @Override\r
118                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
119                                 Result<Void> r = context.getUserInRole(trans, resp, pathParam(req,":user"),pathParam(req,":role"));\r
120                                 switch(r.status) {\r
121                                         case OK:\r
122                                                 resp.setStatus(HttpStatus.OK_200); \r
123                                                 break;\r
124                                         default:\r
125                                                 context.error(trans,resp,r);\r
126                                 }\r
127                         }\r
128                 });\r
129                 \r
130 \r
131 \r
132         }\r
133                 \r
134 }\r