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