81b16fa8f39d713cd30d124f0fcbe8c660e8fd24
[aaf/authz.git] / authz-service / src / main / java / org / onap / aaf / authz / service / api / API_UserRole.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.DELETE;\r
27 import static org.onap.aaf.cssa.rserv.HttpMethods.GET;\r
28 import static org.onap.aaf.cssa.rserv.HttpMethods.POST;\r
29 import static org.onap.aaf.cssa.rserv.HttpMethods.PUT;\r
30 \r
31 import javax.servlet.http.HttpServletRequest;\r
32 import javax.servlet.http.HttpServletResponse;\r
33 \r
34 import org.onap.aaf.authz.env.AuthzTrans;\r
35 import org.onap.aaf.authz.facade.AuthzFacade;\r
36 import org.onap.aaf.authz.layer.Result;\r
37 import org.onap.aaf.authz.service.AuthAPI;\r
38 import org.onap.aaf.authz.service.Code;\r
39 import org.onap.aaf.authz.service.mapper.Mapper.API;\r
40 \r
41 import com.att.aft.dme2.internal.jetty.http.HttpStatus;\r
42 \r
43 /**\r
44  * User Role APIs\r
45  *\r
46  */\r
47 public class API_UserRole {\r
48         /**\r
49          * Normal Init level APIs\r
50          * \r
51          * @param authzAPI\r
52          * @param facade\r
53          * @throws Exception\r
54          */\r
55         public static void init(final AuthAPI authzAPI, AuthzFacade facade) throws Exception {\r
56                 /**\r
57                  * Request User Role Access\r
58                  */\r
59                 authzAPI.route(POST,"/authz/userRole",API.USER_ROLE_REQ,new Code(facade,"Request User Role Access", true) {\r
60                         @Override\r
61                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
62                                 Result<Void> r = context.requestUserRole(trans, req, resp);\r
63                                 switch(r.status) {\r
64                                         case OK:\r
65                                                 resp.setStatus(HttpStatus.CREATED_201); \r
66                                                 break;\r
67                                         default:\r
68                                                 context.error(trans,resp,r);\r
69                                 }\r
70                         }\r
71                 });\r
72                 \r
73                 \r
74                 /**\r
75                  * Get UserRoles by Role\r
76                  */\r
77                 authzAPI.route(GET,"/authz/userRoles/role/:role",API.USER_ROLES,new Code(facade,"Get UserRoles by Role", true) {\r
78                         @Override\r
79                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
80                                 Result<Void> r = context.getUserRolesByRole(trans, resp, pathParam(req,":role"));\r
81                                 switch(r.status) {\r
82                                         case OK:\r
83                                                 resp.setStatus(HttpStatus.OK_200); \r
84                                                 break;\r
85                                         default:\r
86                                                 context.error(trans,resp,r);\r
87                                 }\r
88                         }\r
89                 });\r
90                 \r
91                 /**\r
92                  * Get UserRoles by User\r
93                  */\r
94                 authzAPI.route(GET,"/authz/userRoles/user/:user",API.USER_ROLES,new Code(facade,"Get UserRoles by User", true) {\r
95                         @Override\r
96                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
97                                 Result<Void> r = context.getUserRolesByUser(trans, resp, pathParam(req,":user"));\r
98                                 switch(r.status) {\r
99                                         case OK:\r
100                                                 resp.setStatus(HttpStatus.OK_200); \r
101                                                 break;\r
102                                         default:\r
103                                                 context.error(trans,resp,r);\r
104                                 }\r
105                         }\r
106                 });\r
107 \r
108                 \r
109                 /**\r
110                  * Update roles attached to user in path\r
111                  */\r
112                 authzAPI.route(PUT,"/authz/userRole/user",API.USER_ROLE_REQ,new Code(facade,"Update Roles for a user", true) {\r
113                         @Override\r
114                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
115                                 Result<Void> r = context.resetRolesForUser(trans, resp, req);\r
116                                 switch(r.status) {\r
117                                         case OK:\r
118                                                 resp.setStatus(HttpStatus.OK_200); \r
119                                                 break;\r
120                                         default:\r
121                                                 context.error(trans,resp,r);\r
122                                 }\r
123                         }\r
124                 });\r
125                 \r
126                 \r
127                 /**\r
128                  * Update users attached to role in path\r
129                  */\r
130                 authzAPI.route(PUT,"/authz/userRole/role",API.USER_ROLE_REQ,new Code(facade,"Update Users for a role", true) {\r
131                         @Override\r
132                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
133                                 Result<Void> r = context.resetUsersForRole(trans, resp, req);\r
134                                 switch(r.status) {\r
135                                         case OK:\r
136                                                 resp.setStatus(HttpStatus.OK_200); \r
137                                                 break;\r
138                                         default:\r
139                                                 context.error(trans,resp,r);\r
140                                 }\r
141                         }\r
142                 });\r
143                 \r
144                 /**\r
145                  * Extend Expiration Date (according to Organizational rules)\r
146                  */\r
147                 authzAPI.route(PUT, "/authz/userRole/extend/:user/:role", API.VOID, new Code(facade,"Extend Expiration", true) {\r
148                         @Override\r
149                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
150                                 Result<Void> r = context.extendUserRoleExpiration(trans,resp,pathParam(req,":user"),pathParam(req,":role"));\r
151                                 switch(r.status) {\r
152                                 case OK:\r
153                                         resp.setStatus(HttpStatus.OK_200); \r
154                                         break;\r
155                                 default:\r
156                                         context.error(trans,resp,r);\r
157                         }\r
158         \r
159                         }\r
160                         \r
161                 });\r
162                 \r
163                 \r
164                 /**\r
165                  * Create a new ID/Credential\r
166                  */\r
167                 authzAPI.route(DELETE,"/authz/userRole/:user/:role",API.VOID,new Code(facade,"Delete User Role", true) {\r
168                         @Override\r
169                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
170                                 Result<Void> r = context.deleteUserRole(trans, resp, pathParam(req,":user"),pathParam(req,":role"));\r
171                                 switch(r.status) {\r
172                                         case OK:\r
173                                                 resp.setStatus(HttpStatus.OK_200); \r
174                                                 break;\r
175                                         default:\r
176                                                 context.error(trans,resp,r);\r
177                                 }\r
178                         }\r
179                 });\r
180 \r
181         }\r
182 }\r