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 com.att.authz.service.api;
\r
25 import static com.att.authz.layer.Result.OK;
\r
26 import static com.att.cssa.rserv.HttpMethods.DELETE;
\r
27 import static com.att.cssa.rserv.HttpMethods.GET;
\r
28 import static com.att.cssa.rserv.HttpMethods.POST;
\r
29 import static com.att.cssa.rserv.HttpMethods.PUT;
\r
31 import java.net.URLDecoder;
\r
33 import javax.servlet.http.HttpServletRequest;
\r
34 import javax.servlet.http.HttpServletResponse;
\r
36 import com.att.aft.dme2.internal.jetty.http.HttpStatus;
\r
37 import com.att.authz.env.AuthzTrans;
\r
38 import com.att.authz.facade.AuthzFacade;
\r
39 import com.att.authz.layer.Result;
\r
40 import com.att.authz.service.AuthAPI;
\r
41 import com.att.authz.service.Code;
\r
42 import com.att.authz.service.mapper.Mapper.API;
\r
43 import com.att.cadi.config.Config;
\r
45 public class API_Perms {
\r
46 public static void timeSensitiveInit(AuthAPI authzAPI, AuthzFacade facade) throws Exception {
\r
48 * gets all permissions by user name
\r
50 authzAPI.route(GET, "/authz/perms/user/:user", API.PERMS, new Code(facade,"Get Permissions by User",true) {
\r
53 HttpServletRequest req,
\r
54 HttpServletResponse resp) throws Exception {
\r
56 Result<Void> r = context.getPermsByUser(trans, resp, pathParam(req, "user"));
\r
59 resp.setStatus(HttpStatus.OK_200);
\r
62 context.error(trans,resp,r);
\r
69 * gets all permissions by user name
\r
71 authzAPI.route(POST, "/authz/perms/user/:user", API.PERMS, new Code(facade,"Get Permissions by User, Query AAF Perms",true) {
\r
74 HttpServletRequest req,
\r
75 HttpServletResponse resp) throws Exception {
\r
77 Result<Void> r = context.getPermsByUserWithAAFQuery(trans, req, resp, pathParam(req, "user"));
\r
80 resp.setStatus(HttpStatus.OK_200);
\r
83 context.error(trans,resp,r);
\r
90 } // end timeSensitiveInit
\r
92 public static void init(AuthAPI authzAPI, AuthzFacade facade) throws Exception {
\r
94 * Create a Permission
\r
96 authzAPI.route(POST,"/authz/perm",API.PERM_REQ,new Code(facade,"Create a Permission",true) {
\r
99 HttpServletRequest req,
\r
100 HttpServletResponse resp) throws Exception {
\r
102 Result<Void> r = context.createPerm(trans, req, resp);
\r
105 resp.setStatus(HttpStatus.CREATED_201);
\r
108 context.error(trans,resp,r);
\r
114 * get details of Permission
\r
116 authzAPI.route(GET, "/authz/perms/:type/:instance/:action", API.PERMS, new Code(facade,"Get Permissions by Key",true) {
\r
117 public void handle(
\r
119 HttpServletRequest req,
\r
120 HttpServletResponse resp) throws Exception {
\r
122 Result<Void> r = context.getPermsByName(trans, resp,
\r
123 pathParam(req, "type"),
\r
124 URLDecoder.decode(pathParam(req, "instance"),Config.UTF_8),
\r
125 pathParam(req, "action"));
\r
128 resp.setStatus(HttpStatus.OK_200);
\r
131 context.error(trans,resp,r);
\r
138 * get children of Permission
\r
140 authzAPI.route(GET, "/authz/perms/:type", API.PERMS, new Code(facade,"Get Permissions by Type",true) {
\r
141 public void handle(
\r
143 HttpServletRequest req,
\r
144 HttpServletResponse resp) throws Exception {
\r
146 Result<Void> r = context.getPermsByType(trans, resp, pathParam(req, "type"));
\r
149 resp.setStatus(HttpStatus.OK_200);
\r
152 context.error(trans,resp,r);
\r
160 * gets all permissions by role name
\r
162 authzAPI.route(GET,"/authz/perms/role/:role",API.PERMS,new Code(facade,"Get Permissions by Role",true) {
\r
163 public void handle(
\r
165 HttpServletRequest req,
\r
166 HttpServletResponse resp) throws Exception {
\r
168 Result<Void> r = context.getPermsForRole(trans, resp, pathParam(req, "role"));
\r
171 resp.setStatus(HttpStatus.OK_200);
\r
174 context.error(trans,resp,r);
\r
180 * gets all permissions by Namespace
\r
182 authzAPI.route(GET,"/authz/perms/ns/:ns",API.PERMS,new Code(facade,"Get PermsByNS",true) {
\r
183 public void handle(
\r
185 HttpServletRequest req,
\r
186 HttpServletResponse resp) throws Exception {
\r
188 Result<Void> r = context.getPermsByNS(trans, resp, pathParam(req, "ns"));
\r
191 resp.setStatus(HttpStatus.OK_200);
\r
194 context.error(trans,resp,r);
\r
200 * Set a perm's description
\r
202 authzAPI.route(PUT,"/authz/perm",API.PERM_REQ,new Code(facade,"Set Description for Permission",true) {
\r
204 public void handle(
\r
206 HttpServletRequest req,
\r
207 HttpServletResponse resp) throws Exception {
\r
209 Result<Void> r = context.updatePermDescription(trans, req, resp);
\r
212 resp.setStatus(HttpStatus.OK_200);
\r
215 context.error(trans,resp,r);
\r
221 * Update a permission with a rename
\r
223 authzAPI.route(PUT,"/authz/perm/:type/:instance/:action",API.PERM_REQ,new Code(facade,"Update a Permission",true) {
\r
224 public void handle(
\r
226 HttpServletRequest req,
\r
227 HttpServletResponse resp) throws Exception {
\r
229 Result<Void> r = context.renamePerm(trans, req, resp, pathParam(req, "type"),
\r
230 pathParam(req, "instance"), pathParam(req, "action"));
\r
233 resp.setStatus(HttpStatus.OK_200);
\r
236 context.error(trans,resp,r);
\r
242 * Delete a Permission
\r
244 authzAPI.route(DELETE,"/authz/perm",API.PERM_REQ,new Code(facade,"Delete a Permission",true) {
\r
245 public void handle(
\r
247 HttpServletRequest req,
\r
248 HttpServletResponse resp) throws Exception {
\r
250 Result<Void> r = context.deletePerm(trans,req, resp);
\r
253 resp.setStatus(HttpStatus.OK_200);
\r
256 context.error(trans,resp,r);
\r
265 * Delete a Permission
\r
267 authzAPI.route(DELETE,"/authz/perm/:name/:type/:action",API.PERM_KEY,new Code(facade,"Delete a Permission",true) {
\r
268 public void handle(
\r
270 HttpServletRequest req,
\r
271 HttpServletResponse resp) throws Exception {
\r
273 Result<Void> r = context.deletePerm(trans, resp,
\r
274 pathParam(req, ":name"),
\r
275 pathParam(req, ":type"),
\r
276 pathParam(req, ":action"));
\r
279 resp.setStatus(HttpStatus.OK_200);
\r
282 context.error(trans,resp,r);
\r