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.env;
24 import java.util.Date;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
29 import org.onap.aaf.auth.org.Organization;
30 import org.onap.aaf.auth.org.OrganizationFactory;
31 import org.onap.aaf.cadi.Lur;
32 import org.onap.aaf.cadi.Permission;
33 import org.onap.aaf.cadi.principal.TaggedPrincipal;
34 import org.onap.aaf.misc.env.LogTarget;
35 import org.onap.aaf.misc.env.impl.BasicTrans;
37 public class AuthzTransImpl extends BasicTrans implements AuthzTrans {
38 private static final String N_A = "n/a";
39 private static final String BLANK = "";
40 private HttpServletRequest hreq;
41 private HttpServletResponse hresp;
42 private TaggedPrincipal user;
44 private Organization org;
48 public AuthzTransImpl(AuthzEnv env) {
56 * @see org.onap.aaf.auth.env.test.AuthTrans#set(javax.servlet.http.HttpServletRequest)
59 public AuthzTrans set(HttpServletRequest req, HttpServletResponse resp) {
62 user = (TaggedPrincipal)req.getUserPrincipal();
64 for (REQD_TYPE rt : REQD_TYPE.values()) {
67 // Handle alternate "request" for "future"
68 String request = req.getParameter("request");
70 requested(REQD_TYPE.future,(request.length()==0 || "true".equalsIgnoreCase(request)));
78 public HttpServletRequest hreq() {
83 public HttpServletResponse hresp() {
88 public void setUser(TaggedPrincipal p) {
93 * @see org.onap.aaf.auth.env.test.AuthTrans#user()
96 public String user() {
97 return user==null?N_A:user.getName();
101 * @see org.onap.aaf.auth.env.test.AuthTrans#getUserPrincipal()
104 public TaggedPrincipal getUserPrincipal() {
109 * @see org.onap.aaf.auth.env.test.AuthTrans#ip()
113 return hreq==null?N_A:hreq.getRemoteAddr();
117 * @see org.onap.aaf.auth.env.test.AuthTrans#port()
121 return hreq==null?0:hreq.getRemotePort();
126 * @see org.onap.aaf.auth.env.test.AuthzTrans#meth()
129 public String meth() {
130 return hreq==null?"":hreq.getMethod();
134 * @see org.onap.aaf.auth.env.test.AuthzTrans#path()
137 public String path() {
138 return hreq==null?"":hreq.getPathInfo();
142 * @see org.onap.aaf.auth.env.test.AuthTrans#agent()
145 public String agent() {
146 return hreq==null?BLANK:hreq.getHeader("User-Agent");
150 public AuthzEnv env() {
151 return (AuthzEnv)delegate;
155 public boolean requested(REQD_TYPE requested) {
156 return (mask&requested.bit)==requested.bit;
159 public void requested(REQD_TYPE requested, boolean b) {
163 mask&=~requested.bit;
167 private void requested(REQD_TYPE reqtype, HttpServletRequest req) {
168 String p = req.getParameter(reqtype.name());
170 requested(reqtype,p.length()==0 || "true".equalsIgnoreCase(p));
175 public void setLur(Lur lur) {
180 public Lur getLur() {
185 public boolean fish(Permission ... pond) {
187 return lur.fish(user, pond);
193 * @see org.onap.aaf.auth.env.test.AuthzTrans#org()
196 public Organization org() {
199 if ((org = OrganizationFactory.obtain(env(), user()))==null) {
200 org = Organization.NULL;
202 } catch (Exception e) {
204 org = Organization.NULL;
211 * @see org.onap.aaf.auth.env.test.AuthzTrans#logAuditTrailOnly(com.att.inno.env.LogTarget)
214 public void logAuditTrail(LogTarget lt) {
215 if (lt.isLoggable()) {
216 StringBuilder sb = new StringBuilder();
223 * @see org.onap.aaf.auth.env.test.AuthzTrans#now()
235 * @see org.onap.aaf.auth.env.AuthzTrans#setTag(java.lang.String)
238 public void setTag(String tag) {
243 public String getTag() {
248 public void clearCache() {
250 StringBuilder report = new StringBuilder();
251 lur.clear(user, report);