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
47 public class API_UserRole {
\r
49 * Normal Init level APIs
\r
55 public static void init(final AuthAPI authzAPI, AuthzFacade facade) throws Exception {
\r
57 * Request User Role Access
\r
59 authzAPI.route(POST,"/authz/userRole",API.USER_ROLE_REQ,new Code(facade,"Request User Role Access", true) {
\r
61 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
62 Result<Void> r = context.requestUserRole(trans, req, resp);
\r
65 resp.setStatus(HttpStatus.CREATED_201);
\r
68 context.error(trans,resp,r);
\r
75 * Get UserRoles by Role
\r
77 authzAPI.route(GET,"/authz/userRoles/role/:role",API.USER_ROLES,new Code(facade,"Get UserRoles by Role", true) {
\r
79 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
80 Result<Void> r = context.getUserRolesByRole(trans, resp, pathParam(req,":role"));
\r
83 resp.setStatus(HttpStatus.OK_200);
\r
86 context.error(trans,resp,r);
\r
92 * Get UserRoles by User
\r
94 authzAPI.route(GET,"/authz/userRoles/user/:user",API.USER_ROLES,new Code(facade,"Get UserRoles by User", true) {
\r
96 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
97 Result<Void> r = context.getUserRolesByUser(trans, resp, pathParam(req,":user"));
\r
100 resp.setStatus(HttpStatus.OK_200);
\r
103 context.error(trans,resp,r);
\r
110 * Update roles attached to user in path
\r
112 authzAPI.route(PUT,"/authz/userRole/user",API.USER_ROLE_REQ,new Code(facade,"Update Roles for a user", true) {
\r
114 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
115 Result<Void> r = context.resetRolesForUser(trans, resp, req);
\r
118 resp.setStatus(HttpStatus.OK_200);
\r
121 context.error(trans,resp,r);
\r
128 * Update users attached to role in path
\r
130 authzAPI.route(PUT,"/authz/userRole/role",API.USER_ROLE_REQ,new Code(facade,"Update Users for a role", true) {
\r
132 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
133 Result<Void> r = context.resetUsersForRole(trans, resp, req);
\r
136 resp.setStatus(HttpStatus.OK_200);
\r
139 context.error(trans,resp,r);
\r
145 * Extend Expiration Date (according to Organizational rules)
\r
147 authzAPI.route(PUT, "/authz/userRole/extend/:user/:role", API.VOID, new Code(facade,"Extend Expiration", true) {
\r
149 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
150 Result<Void> r = context.extendUserRoleExpiration(trans,resp,pathParam(req,":user"),pathParam(req,":role"));
\r
153 resp.setStatus(HttpStatus.OK_200);
\r
156 context.error(trans,resp,r);
\r
165 * Create a new ID/Credential
\r
167 authzAPI.route(DELETE,"/authz/userRole/:user/:role",API.VOID,new Code(facade,"Delete User Role", true) {
\r
169 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
170 Result<Void> r = context.deleteUserRole(trans, resp, pathParam(req,":user"),pathParam(req,":role"));
\r
173 resp.setStatus(HttpStatus.OK_200);
\r
176 context.error(trans,resp,r);
\r