2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.service.api;
24 import static org.onap.aaf.auth.layer.Result.OK;
25 import static org.onap.aaf.auth.rserv.HttpMethods.DELETE;
26 import static org.onap.aaf.auth.rserv.HttpMethods.GET;
27 import static org.onap.aaf.auth.rserv.HttpMethods.POST;
28 import static org.onap.aaf.auth.rserv.HttpMethods.PUT;
30 import java.net.URLDecoder;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
35 import org.eclipse.jetty.http.HttpStatus;
36 import org.onap.aaf.auth.env.AuthzTrans;
37 import org.onap.aaf.auth.layer.Result;
38 import org.onap.aaf.auth.service.AAF_Service;
39 import org.onap.aaf.auth.service.Code;
40 import org.onap.aaf.auth.service.facade.AuthzFacade;
41 import org.onap.aaf.auth.service.mapper.Mapper.API;
42 import org.onap.aaf.cadi.config.Config;
43 import org.onap.aaf.misc.env.util.Split;
45 public class API_Perms {
46 public static void timeSensitiveInit(AAF_Service authzAPI, AuthzFacade facade) throws Exception {
48 * gets all permissions by user name
50 authzAPI.route(GET, "/authz/perms/user/:user", API.PERMS, new Code(facade,"Get Permissions by User",true) {
53 HttpServletRequest req,
54 HttpServletResponse resp) throws Exception {
56 String scopes = req.getParameter("scopes");
59 r = context.getPermsByUser(trans, resp, pathParam(req, "user"));
61 r = context.getPermsByUserScope(trans, resp, pathParam(req, "user"),Split.split(':', scopes));
65 resp.setStatus(HttpStatus.OK_200);
68 context.error(trans,resp,r);
75 * gets all permissions by user name
77 authzAPI.route(POST, "/authz/perms/user/:user", API.PERMS, new Code(facade,"Get Permissions by User, Query AAF Perms",true) {
80 HttpServletRequest req,
81 HttpServletResponse resp) throws Exception {
83 Result<Void> r = context.getPermsByUserWithAAFQuery(trans, req, resp, pathParam(req, "user"));
86 resp.setStatus(HttpStatus.OK_200);
89 context.error(trans,resp,r);
96 } // end timeSensitiveInit
98 public static void init(AAF_Service authzAPI, AuthzFacade facade) throws Exception {
100 * Create a Permission
102 authzAPI.route(POST,"/authz/perm",API.PERM_REQ,new Code(facade,"Create a Permission",true) {
105 HttpServletRequest req,
106 HttpServletResponse resp) throws Exception {
108 Result<Void> r = context.createPerm(trans, req, resp);
111 resp.setStatus(HttpStatus.CREATED_201);
114 context.error(trans,resp,r);
120 * get details of Permission
122 authzAPI.route(GET, "/authz/perms/:type/:instance/:action", API.PERMS, new Code(facade,"Get Permissions by Key",true) {
125 HttpServletRequest req,
126 HttpServletResponse resp) throws Exception {
128 Result<Void> r = context.getPermsByName(trans, resp,
129 pathParam(req, "type"),
130 URLDecoder.decode(pathParam(req, "instance"),Config.UTF_8),
131 pathParam(req, "action"));
134 resp.setStatus(HttpStatus.OK_200);
137 context.error(trans,resp,r);
144 * get children of Permission
146 authzAPI.route(GET, "/authz/perms/:type", API.PERMS, new Code(facade,"Get Permissions by Type",true) {
149 HttpServletRequest req,
150 HttpServletResponse resp) throws Exception {
152 Result<Void> r = context.getPermsByType(trans, resp, pathParam(req, "type"));
155 resp.setStatus(HttpStatus.OK_200);
158 context.error(trans,resp,r);
166 * gets all permissions by role name
168 authzAPI.route(GET,"/authz/perms/role/:role",API.PERMS,new Code(facade,"Get Permissions by Role",true) {
171 HttpServletRequest req,
172 HttpServletResponse resp) throws Exception {
174 Result<Void> r = context.getPermsForRole(trans, resp, pathParam(req, "role"));
177 resp.setStatus(HttpStatus.OK_200);
180 context.error(trans,resp,r);
186 * gets all permissions by Namespace
188 authzAPI.route(GET,"/authz/perms/ns/:ns",API.PERMS,new Code(facade,"Get PermsByNS",true) {
191 HttpServletRequest req,
192 HttpServletResponse resp) throws Exception {
194 Result<Void> r = context.getPermsByNS(trans, resp, pathParam(req, "ns"));
197 resp.setStatus(HttpStatus.OK_200);
200 context.error(trans,resp,r);
206 * Set a perm's description
208 authzAPI.route(PUT,"/authz/perm",API.PERM_REQ,new Code(facade,"Set Description for Permission",true) {
212 HttpServletRequest req,
213 HttpServletResponse resp) throws Exception {
215 Result<Void> r = context.updatePermDescription(trans, req, resp);
218 resp.setStatus(HttpStatus.OK_200);
221 context.error(trans,resp,r);
227 * Update a permission with a rename
229 authzAPI.route(PUT,"/authz/perm/:type/:instance/:action",API.PERM_REQ,new Code(facade,"Update a Permission",true) {
232 HttpServletRequest req,
233 HttpServletResponse resp) throws Exception {
235 Result<Void> r = context.renamePerm(trans, req, resp,
236 pathParam(req, "type"),
237 URLDecoder.decode(pathParam(req, "instance"),Config.UTF_8),
238 pathParam(req, "action"));
241 resp.setStatus(HttpStatus.OK_200);
244 context.error(trans,resp,r);
250 * Delete a Permission
252 authzAPI.route(DELETE,"/authz/perm",API.PERM_REQ,new Code(facade,"Delete a Permission",true) {
255 HttpServletRequest req,
256 HttpServletResponse resp) throws Exception {
258 Result<Void> r = context.deletePerm(trans,req, resp);
261 resp.setStatus(HttpStatus.OK_200);
264 context.error(trans,resp,r);
273 * Delete a Permission
275 authzAPI.route(DELETE,"/authz/perm/:name/:type/:action",API.PERM_KEY,new Code(facade,"Delete a Permission",true) {
278 HttpServletRequest req,
279 HttpServletResponse resp) throws Exception {
281 Result<Void> r = context.deletePerm(trans, resp,
282 pathParam(req, ":name"),
283 pathParam(req, ":type"),
284 pathParam(req, ":action"));
287 resp.setStatus(HttpStatus.OK_200);
290 context.error(trans,resp,r);