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.rserv;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
27 import org.onap.aaf.misc.env.Trans;
30 * HTTP Code element, which responds to the essential "handle Method".
32 * Use Native HttpServletRe[quest|sponse] calls for questions like QueryParameters (getParameter, etc)
34 * Use local "pathParam" method to obtain in an optimized manner the path parameter, which must be interpreted by originating string
36 * i.e. my/path/:id/:other/*
43 public abstract class HttpCode<TRANS extends Trans, CONTEXT> {
44 protected CONTEXT context;
46 protected String [] roles;
49 // Package by design... Set by Route when linked
52 public HttpCode(CONTEXT context, String description, String ... roles) {
53 this.context = context;
56 // Evaluate for "*" once...
58 for (String srole : roles) {
59 if ("*".equals(srole)) {
64 this.roles = all?null:roles;
67 public abstract void handle(TRANS trans, HttpServletRequest req, HttpServletResponse resp) throws Exception;
69 public String desc() {
74 * Get the variable element out of the Path Parameter, as set by initial Code
80 public String pathParam(HttpServletRequest req, String key) {
81 String rv = req.getParameter(key);
83 rv = match.param(req.getPathInfo(), key);
86 if (rv.endsWith("/")) {
87 rv = rv.substring(0, rv.length()-1);
94 // Note: get Query Params from Request
97 * Check for Authorization when set.
99 * If no Roles set, then accepts all users
104 public boolean isAuthorized(HttpServletRequest req) {
107 for (String srole : roles) {
108 if (req.isUserInRole(srole)) return true;
114 public boolean no_cache() {
118 public String toString() {