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.GET;
\r
28 import javax.servlet.http.HttpServletRequest;
\r
29 import javax.servlet.http.HttpServletResponse;
\r
31 import com.att.aft.dme2.internal.jetty.http.HttpStatus;
\r
32 import com.att.authz.env.AuthzTrans;
\r
33 import com.att.authz.facade.AuthzFacade;
\r
34 import com.att.authz.layer.Result;
\r
35 import com.att.authz.service.AuthAPI;
\r
36 import com.att.authz.service.Code;
\r
37 import com.att.authz.service.mapper.Mapper.API;
\r
43 public class API_User {
\r
45 * Normal Init level APIs
\r
51 public static void init(final AuthAPI authzAPI, AuthzFacade facade) throws Exception {
\r
53 * get all Users who have Permission X
\r
55 authzAPI.route(GET,"/authz/users/perm/:type/:instance/:action",API.USERS,new Code(facade,"Get Users By Permission", true) {
\r
57 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
58 // trans.checkpoint(pathParam(req,"type") + " "
\r
59 // + pathParam(req,"instance") + " "
\r
60 // + pathParam(req,"action"));
\r
62 Result<Void> r = context.getUsersByPermission(trans, resp,
\r
63 pathParam(req, ":type"),
\r
64 pathParam(req, ":instance"),
\r
65 pathParam(req, ":action"));
\r
68 resp.setStatus(HttpStatus.OK_200);
\r
71 context.error(trans,resp,r);
\r
78 * get all Users who have Role X
\r
80 authzAPI.route(GET,"/authz/users/role/:role",API.USERS,new Code(facade,"Get Users By Role", true) {
\r
82 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
83 Result<Void> r = context.getUsersByRole(trans, resp, pathParam(req, ":role"));
\r
86 resp.setStatus(HttpStatus.OK_200);
\r
89 context.error(trans,resp,r);
\r
95 * Get User Role if exists
\r
98 authzAPI.route(GET,"/authz/userRole/:user/:role",API.USERS,new Code(facade,"Get if User is In Role", true) {
\r
100 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
101 Result<Void> r = context.getUserInRole(trans, resp, pathParam(req,":user"),pathParam(req,":role"));
\r
104 resp.setStatus(HttpStatus.OK_200);
\r
107 context.error(trans,resp,r);
\r
113 * Get User Role if exists
\r
115 authzAPI.route(GET,"/authz/users/:user/:role",API.USERS,new Code(facade,"Get if User is In Role", true) {
\r
117 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
118 Result<Void> r = context.getUserInRole(trans, resp, pathParam(req,":user"),pathParam(req,":role"));
\r
121 resp.setStatus(HttpStatus.OK_200);
\r
124 context.error(trans,resp,r);
\r