1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * Copyright © 2017 Amdocs
\r
7 * * ===========================================================================
\r
8 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * * you may not use this file except in compliance with the License.
\r
10 * * You may obtain a copy of the License at
\r
12 * * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * * Unless required by applicable law or agreed to in writing, software
\r
15 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * * See the License for the specific language governing permissions and
\r
18 * * limitations under the License.
\r
19 * * ============LICENSE_END====================================================
\r
21 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 ******************************************************************************/
\r
24 package com.att.authz.env;
\r
26 import java.security.Principal;
\r
28 import javax.servlet.http.HttpServletRequest;
\r
30 import com.att.authz.org.Organization;
\r
31 import com.att.authz.org.OrganizationFactory;
\r
32 import com.att.cadi.Lur;
\r
33 import com.att.cadi.Permission;
\r
34 import com.att.inno.env.LogTarget;
\r
35 import com.att.inno.env.impl.BasicTrans;
\r
37 public class AuthzTransImpl extends BasicTrans implements AuthzTrans {
\r
38 private static final String TRUE = "true";
\r
39 private Principal user;
\r
40 private String ip,agent,meth,path;
\r
43 private Organization org;
\r
44 private String force;
\r
45 private boolean futureRequested;
\r
47 public AuthzTransImpl(AuthzEnv env) {
\r
54 * @see com.att.authz.env.AuthTrans#set(javax.servlet.http.HttpServletRequest)
\r
57 public AuthzTrans set(HttpServletRequest req) {
\r
58 user = req.getUserPrincipal();
\r
59 ip = req.getRemoteAddr();
\r
60 port = req.getRemotePort();
\r
61 agent = req.getHeader("User-Agent");
\r
62 meth = req.getMethod();
\r
63 path = req.getPathInfo();
\r
64 force = req.getParameter("force");
\r
65 futureRequested = TRUE.equalsIgnoreCase(req.getParameter("request"));
\r
71 public void setUser(Principal p) {
\r
76 * @see com.att.authz.env.AuthTrans#user()
\r
79 public String user() {
\r
80 return user==null?"n/a":user.getName();
\r
84 * @see com.att.authz.env.AuthTrans#getUserPrincipal()
\r
87 public Principal getUserPrincipal() {
\r
92 * @see com.att.authz.env.AuthTrans#ip()
\r
95 public String ip() {
\r
100 * @see com.att.authz.env.AuthTrans#port()
\r
103 public int port() {
\r
109 * @see com.att.authz.env.AuthzTrans#meth()
\r
112 public String meth() {
\r
117 * @see com.att.authz.env.AuthzTrans#path()
\r
120 public String path() {
\r
125 * @see com.att.authz.env.AuthTrans#agent()
\r
128 public String agent() {
\r
133 public AuthzEnv env() {
\r
134 return (AuthzEnv)delegate;
\r
138 public boolean forceRequested() {
\r
139 return TRUE.equalsIgnoreCase(force);
\r
142 public void forceRequested(boolean force) {
\r
143 this.force = force?TRUE:"false";
\r
147 public boolean moveRequested() {
\r
148 return "move".equalsIgnoreCase(force);
\r
152 public boolean futureRequested() {
\r
153 return futureRequested;
\r
158 public void setLur(Lur lur) {
\r
163 public boolean fish(Permission p) {
\r
165 return lur.fish(user, p);
\r
171 * @see com.att.authz.env.AuthzTrans#org()
\r
174 public Organization org() {
\r
177 if((org = OrganizationFactory.obtain(env(), user()))==null) {
\r
178 org = Organization.NULL;
\r
180 } catch (Exception e) {
\r
181 org = Organization.NULL;
\r
188 * @see com.att.authz.env.AuthzTrans#logAuditTrailOnly(com.att.inno.env.LogTarget)
\r
191 public void logAuditTrail(LogTarget lt) {
\r
192 if(lt.isLoggable()) {
\r
193 StringBuilder sb = new StringBuilder();
\r