1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\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
11 * * http://www.apache.org/licenses/LICENSE-2.0
\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
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.authz.service.api;
\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
31 import javax.servlet.http.HttpServletRequest;
\r
32 import javax.servlet.http.HttpServletResponse;
\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
41 import com.att.aft.dme2.internal.jetty.http.HttpStatus;
\r
43 public class API_Delegate {
\r
44 public static void init(AuthAPI authzAPI, AuthzFacade facade) throws Exception {
\r
48 authzAPI.route(POST, "/authz/delegate",API.DELG_REQ,new Code(facade,"Add a Delegate", true) {
\r
51 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
52 Result<Void> r = context.createDelegate(trans, req, resp);
\r
55 resp.setStatus(HttpStatus.CREATED_201);
\r
58 context.error(trans,resp,r);
\r
66 authzAPI.route(PUT, "/authz/delegate",API.DELG_REQ,new Code(facade,"Update a Delegate", true) {
\r
69 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
70 Result<Void> r = context.updateDelegate(trans, req, resp);
\r
73 resp.setStatus(HttpStatus.OK_200);
\r
76 context.error(trans,resp,r);
\r
82 * DELETE delegates for a user
\r
84 authzAPI.route(DELETE, "/authz/delegate",API.DELG_REQ,new Code(facade,"Delete delegates for a user", true) {
\r
87 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
88 Result<Void> r = context.deleteDelegate(trans, req, resp);
\r
91 resp.setStatus(HttpStatus.OK_200);
\r
94 context.error(trans,resp,r);
\r
100 * DELETE a delegate
\r
102 authzAPI.route(DELETE, "/authz/delegate/:user_name",API.VOID,new Code(facade,"Delete a Delegate", true) {
\r
105 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
106 Result<Void> r = context.deleteDelegate(trans, pathParam(req, "user_name"));
\r
109 resp.setStatus(HttpStatus.OK_200);
\r
112 context.error(trans,resp,r);
\r
118 * Read who is delegating for User
\r
120 authzAPI.route(GET, "/authz/delegates/user/:user",API.DELGS,new Code(facade,"Get Delegates by User", true) {
\r
123 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
124 Result<Void> r = context.getDelegatesByUser(trans, pathParam(req, "user"), resp);
\r
127 resp.setStatus(HttpStatus.OK_200);
\r
130 context.error(trans,resp,r);
\r
136 * Read for whom the User is delegating
\r
138 authzAPI.route(GET, "/authz/delegates/delegate/:delegate",API.DELGS,new Code(facade,"Get Delegates by Delegate", true) {
\r
141 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
142 Result<Void> r = context.getDelegatesByDelegate(trans, pathParam(req, "delegate"), resp);
\r
145 resp.setStatus(HttpStatus.OK_200);
\r
148 context.error(trans,resp,r);
\r