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 javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
33 import org.eclipse.jetty.http.HttpStatus;
34 import org.onap.aaf.auth.dao.cass.NsType;
35 import org.onap.aaf.auth.dao.cass.Status;
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;
44 private static final String FULL = "full";
45 private static final String TRUE = "true";
47 public static void init(AAF_Service authzAPI, AuthzFacade facade) throws Exception {
49 * puts a new Namespace in Authz DB
51 * TESTCASES: TC_NS1, TC_NSdelete1
53 authzAPI.route(POST,"/authz/ns",API.NS_REQ, new Code(facade,"Create a Namespace",true) {
57 HttpServletRequest req,
58 HttpServletResponse resp) throws Exception {
59 NsType nst = NsType.fromString(req.getParameter("type"));
60 Result<Void> r = context.requestNS(trans, req, resp,nst);
64 resp.setStatus(HttpStatus.CREATED_201);
66 case Status.ACC_Future:
67 resp.setStatus(HttpStatus.ACCEPTED_202);
70 context.error(trans,resp,r);
77 * removes a Namespace from Authz DB
79 * TESTCASES: TC_NS1, TC_NSdelete1
81 authzAPI.route(DELETE,"/authz/ns/:ns",API.VOID, new Code(facade,"Delete a Namespace",true) {
85 HttpServletRequest req,
86 HttpServletResponse resp) throws Exception {
87 Result<Void> r = context.deleteNS(trans, req, resp, pathParam(req,":ns"));
90 resp.setStatus(HttpStatus.OK_200);
93 context.error(trans,resp,r);
100 * Add an Admin in NS in Authz DB
104 authzAPI.route(POST,"/authz/ns/:ns/admin/:id",API.VOID, new Code(facade,"Add an Admin to a Namespace",true) {
108 HttpServletRequest req,
109 HttpServletResponse resp) throws Exception {
110 Result<Void> r = context.addAdminToNS(trans, resp, pathParam(req,":ns"), pathParam(req,":id"));
113 resp.setStatus(HttpStatus.CREATED_201);
115 case Status.ACC_Future:
116 resp.setStatus(HttpStatus.ACCEPTED_202);
119 context.error(trans,resp,r);
126 * Removes an Admin from Namespace in Authz DB
130 authzAPI.route(DELETE,"/authz/ns/:ns/admin/:id",API.VOID, new Code(facade,"Remove an Admin from a Namespace",true) {
134 HttpServletRequest req,
135 HttpServletResponse resp) throws Exception {
136 Result<Void> r = context.delAdminFromNS(trans, resp, pathParam(req,":ns"), pathParam(req,":id"));
139 resp.setStatus(HttpStatus.OK_200);
142 context.error(trans,resp,r);
149 * Add an Admin in NS in Authz DB
153 authzAPI.route(POST,"/authz/ns/:ns/responsible/:id",API.VOID, new Code(facade,"Add a Responsible Identity to a Namespace",true) {
157 HttpServletRequest req,
158 HttpServletResponse resp) throws Exception {
159 Result<Void> r = context.addResponsibilityForNS(trans, resp, pathParam(req,":ns"), pathParam(req,":id"));
162 resp.setStatus(HttpStatus.CREATED_201);
164 case Status.ACC_Future:
165 resp.setStatus(HttpStatus.ACCEPTED_202);
168 context.error(trans,resp,r);
178 authzAPI.route(GET,"/authz/nss/:id",API.NSS, new Code(facade,"Return Information about Namespaces", true) {
182 HttpServletRequest req,
183 HttpServletResponse resp) throws Exception {
184 Result<Void> r = context.getNSsByName(trans, resp, pathParam(req,":id"));
187 resp.setStatus(HttpStatus.OK_200);
190 context.error(trans,resp,r);
197 * Get all Namespaces where user is an admin
199 authzAPI.route(GET,"/authz/nss/admin/:user",API.NSS, new Code(facade,"Return Namespaces where User is an Admin", true) {
203 HttpServletRequest req,
204 HttpServletResponse resp) throws Exception {
205 Result<Void> r = context.getNSsByAdmin(trans, resp, pathParam(req,":user"),TRUE.equals(req.getParameter(FULL)));
208 resp.setStatus(HttpStatus.OK_200);
211 context.error(trans,resp,r);
218 * Get all Namespaces where user is a responsible party
220 authzAPI.route(GET,"/authz/nss/responsible/:user",API.NSS, new Code(facade,"Return Namespaces where User is Responsible", true) {
224 HttpServletRequest req,
225 HttpServletResponse resp) throws Exception {
226 Result<Void> r = context.getNSsByResponsible(trans, resp, pathParam(req,":user"),TRUE.equals(req.getParameter(FULL)));
229 resp.setStatus(HttpStatus.OK_200);
232 context.error(trans,resp,r);
239 * Get all Namespaces where user is an admin or owner
241 authzAPI.route(GET,"/authz/nss/either/:user",API.NSS, new Code(facade,"Return Namespaces where User Admin or Owner", true) {
245 HttpServletRequest req,
246 HttpServletResponse resp) throws Exception {
247 Result<Void> r = context.getNSsByEither(trans, resp, pathParam(req,":user"),TRUE.equals(req.getParameter(FULL)));
250 resp.setStatus(HttpStatus.OK_200);
253 context.error(trans,resp,r);
260 * Get all children Namespaces
262 authzAPI.route(GET,"/authz/nss/children/:id",API.NSS, new Code(facade,"Return Child Namespaces", true) {
266 HttpServletRequest req,
267 HttpServletResponse resp) throws Exception {
268 Result<Void> r = context.getNSsChildren(trans, resp, pathParam(req,":id"));
271 resp.setStatus(HttpStatus.OK_200);
274 context.error(trans,resp,r);
281 * Set a description of a Namespace
283 authzAPI.route(PUT,"/authz/ns",API.NS_REQ,new Code(facade,"Set a Description for a Namespace",true) {
287 HttpServletRequest req,
288 HttpServletResponse resp) throws Exception {
290 Result<Void> r = context.updateNsDescription(trans, req, resp);
293 resp.setStatus(HttpStatus.OK_200);
296 context.error(trans,resp,r);
302 * Removes an Owner from Namespace in Authz DB
306 authzAPI.route(DELETE,"/authz/ns/:ns/responsible/:id",API.VOID, new Code(facade,"Remove a Responsible Identity from Namespace",true) {
310 HttpServletRequest req,
311 HttpServletResponse resp) throws Exception {
312 Result<Void> r = context.delResponsibilityForNS(trans, resp, pathParam(req,":ns"), pathParam(req,":id"));
315 resp.setStatus(HttpStatus.OK_200);
318 context.error(trans,resp,r);
324 authzAPI.route(POST,"/authz/ns/:ns/attrib/:key/:value",API.VOID, new Code(facade,"Add an Attribute from a Namespace",true) {
326 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
327 Result<Void> r = context.createAttribForNS(trans, resp,
328 pathParam(req,":ns"),
329 pathParam(req,":key"),
330 pathParam(req,":value"));
333 resp.setStatus(HttpStatus.CREATED_201);
336 context.error(trans,resp,r);
342 authzAPI.route(GET,"/authz/ns/attrib/:key",API.KEYS, new Code(facade,"get Ns Key List From Attribute",true) {
344 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
345 Result<Void> r = context.readNsByAttrib(trans, resp, pathParam(req,":key"));
348 resp.setStatus(HttpStatus.OK_200);
351 context.error(trans,resp,r);
357 authzAPI.route(PUT,"/authz/ns/:ns/attrib/:key/:value",API.VOID, new Code(facade,"update an Attribute from a Namespace",true) {
359 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
360 Result<Void> r = context.updAttribForNS(trans, resp,
361 pathParam(req,":ns"),
362 pathParam(req,":key"),
363 pathParam(req,":value"));
366 resp.setStatus(HttpStatus.OK_200);
369 context.error(trans,resp,r);
375 authzAPI.route(DELETE,"/authz/ns/:ns/attrib/:key",API.VOID, new Code(facade,"delete an Attribute from a Namespace",true) {
377 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
378 Result<Void> r = context.delAttribForNS(trans, resp,
379 pathParam(req,":ns"),
380 pathParam(req,":key"));
383 resp.setStatus(HttpStatus.OK_200);
386 context.error(trans,resp,r);