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.env;
\r
25 import java.security.Principal;
\r
27 import javax.servlet.http.HttpServletRequest;
\r
29 import com.att.authz.org.Organization;
\r
30 import com.att.authz.org.OrganizationFactory;
\r
31 import com.att.cadi.Lur;
\r
32 import com.att.cadi.Permission;
\r
33 import com.att.inno.env.LogTarget;
\r
34 import com.att.inno.env.impl.BasicTrans;
\r
36 public class AuthzTransImpl extends BasicTrans implements AuthzTrans {
\r
37 private static final String TRUE = "true";
\r
38 private Principal user;
\r
39 private String ip,agent,meth,path;
\r
42 private Organization org;
\r
43 private String force;
\r
44 private boolean futureRequested;
\r
46 public AuthzTransImpl(AuthzEnv env) {
\r
53 * @see com.att.authz.env.AuthTrans#set(javax.servlet.http.HttpServletRequest)
\r
56 public AuthzTrans set(HttpServletRequest req) {
\r
57 user = req.getUserPrincipal();
\r
58 ip = req.getRemoteAddr();
\r
59 port = req.getRemotePort();
\r
60 agent = req.getHeader("User-Agent");
\r
61 meth = req.getMethod();
\r
62 path = req.getPathInfo();
\r
63 force = req.getParameter("force");
\r
64 futureRequested = TRUE.equalsIgnoreCase(req.getParameter("request"));
\r
70 public void setUser(Principal p) {
\r
75 * @see com.att.authz.env.AuthTrans#user()
\r
78 public String user() {
\r
79 return user==null?"n/a":user.getName();
\r
83 * @see com.att.authz.env.AuthTrans#getUserPrincipal()
\r
86 public Principal getUserPrincipal() {
\r
91 * @see com.att.authz.env.AuthTrans#ip()
\r
94 public String ip() {
\r
99 * @see com.att.authz.env.AuthTrans#port()
\r
102 public int port() {
\r
108 * @see com.att.authz.env.AuthzTrans#meth()
\r
111 public String meth() {
\r
116 * @see com.att.authz.env.AuthzTrans#path()
\r
119 public String path() {
\r
124 * @see com.att.authz.env.AuthTrans#agent()
\r
127 public String agent() {
\r
132 public AuthzEnv env() {
\r
133 return (AuthzEnv)delegate;
\r
137 public boolean forceRequested() {
\r
138 return TRUE.equalsIgnoreCase(force);
\r
141 public void forceRequested(boolean force) {
\r
142 this.force = force?TRUE:"false";
\r
146 public boolean moveRequested() {
\r
147 return "move".equalsIgnoreCase(force);
\r
151 public boolean futureRequested() {
\r
152 return futureRequested;
\r
157 public void setLur(Lur lur) {
\r
162 public boolean fish(Permission p) {
\r
164 return lur.fish(user, p);
\r
170 * @see com.att.authz.env.AuthzTrans#org()
\r
173 public Organization org() {
\r
176 if((org = OrganizationFactory.obtain(env(), user()))==null) {
\r
177 org = Organization.NULL;
\r
179 } catch (Exception e) {
\r
180 org = Organization.NULL;
\r
187 * @see com.att.authz.env.AuthzTrans#logAuditTrailOnly(com.att.inno.env.LogTarget)
\r
190 public void logAuditTrail(LogTarget lt) {
\r
191 if(lt.isLoggable()) {
\r
192 StringBuilder sb = new StringBuilder();
\r