summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__WorkflowDesignerData.sql4
1 files changed, 2 insertions, 2 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__WorkflowDesignerData.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__WorkflowDesignerData.sql
index 3f76334bd9..137f73cf65 100644
--- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__WorkflowDesignerData.sql
+++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__WorkflowDesignerData.sql
@@ -201,5 +201,5 @@ VALUES
INSERT INTO `workflow` (`ARTIFACT_UUID`,`ARTIFACT_NAME`,`NAME`,`OPERATION_NAME`,`VERSION`,`DESCRIPTION`,`RESOURCE_TARGET`,`SOURCE`)
VALUES
('9d45cd30-1a89-4993-87c1-6dd09c1696cf','VFModule-ScaleOut','VNF Scale Out','ScaleOut',1.0,'native static workflow to support ScaleOut','vfModule','native'),
-('da6478e4-ea33-3346-ac12-ab121284a333','VnfInPlaceUpdate.bpmn','VNF In Place Software Update','inPlaceSoftwareUpdate',1.0,'native static workflow to support inPlaceSoftwareUpdate','vnf','native'),
-('fdb3ac48-70f9-4584-bd92-253bdbdec1e1','VnfConfigUpdate.bpmn','VNF Config Update','applyConfigModify',1.0,'native static workflow to support applyConfigModify','vnf','native'); \ No newline at end of file
+('da6478e4-ea33-3346-ac12-ab121284a333','VnfInPlaceUpdate.bpmn','VnfInPlaceUpdate','inPlaceSoftwareUpdate',1.0,'native static workflow to support inPlaceSoftwareUpdate','vnf','native'),
+('fdb3ac48-70f9-4584-bd92-253bdbdec1e1','VnfConfigUpdate.bpmn','VnfConfigUpdate','applyConfigModify',1.0,'native static workflow to support applyConfigModify','vnf','native');
' href='#n129'>129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
/*******************************************************************************
 * ============LICENSE_START====================================================
 * * org.onap.aaf
 * * ===========================================================================
 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
 * * ===========================================================================
 * * Licensed under the Apache License, Version 2.0 (the "License");
 * * you may not use this file except in compliance with the License.
 * * You may obtain a copy of the License at
 * * 
 *  *      http://www.apache.org/licenses/LICENSE-2.0
 * * 
 *  * Unless required by applicable law or agreed to in writing, software
 * * distributed under the License is distributed on an "AS IS" BASIS,
 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * * See the License for the specific language governing permissions and
 * * limitations under the License.
 * * ============LICENSE_END====================================================
 * *
 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 * *
 ******************************************************************************/
package org.onap.aaf.cadi.taf.dos;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.onap.aaf.cadi.Access;
import org.onap.aaf.cadi.CachedPrincipal;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.CachedPrincipal.Resp;
import org.onap.aaf.cadi.Taf.LifeForm;
import org.onap.aaf.cadi.taf.HttpTaf;
import org.onap.aaf.cadi.taf.PuntTafResp;
import org.onap.aaf.cadi.taf.TafResp;
import org.onap.aaf.cadi.taf.TafResp.RESP;

public class DenialOfServiceTaf implements HttpTaf {
	private static Map<String, Counter> deniedIP=null, deniedID=null;
	private Access access;
	private static File dosIP, dosID;
	
	/**
	 * 
	 * @param hostname
	 * @param prod
	 * @throws CadiException
	 */
	public DenialOfServiceTaf(Access access) throws CadiException {
		this.access = access;
		if(dosIP==null || dosID == null) {
			String dirStr;
			if((dirStr = access.getProperty("aaf_data_dir", null))!=null) {
				dosIP = new File(dirStr+"/dosIP");
				readIP();
				dosID = new File(dirStr+"/dosID");
				readID();
			}
		}
	}

	public TafResp validate(LifeForm reading, HttpServletRequest req, final HttpServletResponse resp) {
		// Performance, when not needed
		if(deniedIP != null) {
			String ip;
			Counter c = deniedIP.get(ip=req.getRemoteAddr());
			if(c!=null) {
				c.inc();
				return respDenyIP(access,ip);
			}
		}
		
		// Note:  Can't process Principal, because this is the first TAF, and no Principal is created.
		// Other TAFs use "isDenied()" on this Object to validate.
		return PuntTafResp.singleton();
	}

	public Resp revalidate(CachedPrincipal prin) {
		// We always return NOT MINE, because DOS Taf does not ever validate
		return Resp.NOT_MINE;
	}

	/*
	 *  for use in Other TAFs, before they attempt backend validation of 
	 */
	public static Counter isDeniedID(String identity) {
		if(deniedID!=null) {
			return deniedID.get(identity);
		}
		return null;
	}
	
	/**
	 *  
	 */
	public static Counter isDeniedIP(String ipvX) {
		if(deniedID!=null) {
			return deniedID.get(ipvX);
		}
		return null;
	}

	/**
	 * Return of "True" means IP has been added.
	 * Return of "False" means IP already added.
	 * 
	 * @param ip
	 * @return
	 */
	public static synchronized boolean denyIP(String ip) {
		boolean rv = false;
		if(deniedIP==null) {
			deniedIP = new HashMap<String,Counter>();
			deniedIP.put(ip, new Counter(ip)); // Noted duplicated for minimum time spent
			rv= true;
		} else if(deniedIP.get(ip)==null) {
			deniedIP.put(ip, new Counter(ip));
			rv = true;
		}
		if(rv) {
			writeIP();
		}
		return rv;
	}
	
	private static void writeIP() {
		if(dosIP!=null && deniedIP!=null) {
			if(deniedIP.isEmpty()) {
				if(dosIP.exists()) {
					dosIP.delete();
				}
			} else {
				PrintStream fos;
				try {
					fos = new PrintStream(new FileOutputStream(dosIP,false));
					try {
						for(String ip: deniedIP.keySet()) {
							fos.println(ip);
						}
					} finally {
						fos.close();
					}
				} catch (IOException e) {
					e.printStackTrace(System.err);
				}
			}
		}
	}
	
	private static void readIP() {
		if(dosIP!=null && dosIP.exists()) {
			BufferedReader br;
			try {
				br = new BufferedReader(new FileReader(dosIP));
				if(deniedIP==null) {
					deniedIP=new HashMap<String,Counter>();
				}

				try {
					String line;
					while((line=br.readLine())!=null) {
						deniedIP.put(line, new Counter(line));
					}
				} finally {
					br.close();
				}
			} catch (IOException e) {
				e.printStackTrace(System.err);
			}
		}
	}


	/**
	 * Return of "True" means IP has was removed.
	 * Return of "False" means IP wasn't being denied.
	 * 
	 * @param ip
	 * @return
	 */
	public static synchronized boolean removeDenyIP(String ip) {
		if(deniedIP!=null && deniedIP.remove(ip)!=null) {
			writeIP();
			if(deniedIP.isEmpty()) {
				deniedIP=null;
			}
			return true;
		}
		return false;
	}

	/**
	 * Return of "True" means ID has been added.
	 * Return of "False" means ID already added.
	 * 
	 * @param ip
	 * @return
	 */
	public static synchronized boolean denyID(String id) {
		boolean rv = false;
		if(deniedID==null) {
			deniedID = new HashMap<String,Counter>();
			deniedID.put(id, new Counter(id)); // Noted duplicated for minimum time spent
			rv = true;
		} else if(deniedID.get(id)==null) {
			deniedID.put(id, new Counter(id));
			rv = true;
		}
		if(rv) {
			writeID();
		}
		return rv;

	}

	private static void writeID() {
		if(dosID!=null && deniedID!=null) {
			if(deniedID.isEmpty()) {
				if(dosID.exists()) {
					dosID.delete();
				}
			} else {
				PrintStream fos;
				try {
					fos = new PrintStream(new FileOutputStream(dosID,false));
					try {
						for(String ip: deniedID.keySet()) {
							fos.println(ip);
						}
					} finally {
						fos.close();
					}
				} catch (IOException e) {
					e.printStackTrace(System.err);
				}
			}
		}
	}

	private static void readID() {
		if(dosID!=null && dosID.exists()) {
			BufferedReader br;
			try {
				br = new BufferedReader(new FileReader(dosID));
				if(deniedID==null) {
					deniedID=new HashMap<String,Counter>();
				}
				try {
					String line;
					while((line=br.readLine())!=null) {
						deniedID.put(line, new Counter(line));
					}
				} finally {
					br.close();
				}
			} catch (IOException e) {
				e.printStackTrace(System.err);
			}
		}
	}

	/**
	 * Return of "True" means ID has was removed.
	 * Return of "False" means ID wasn't being denied.
	 * 
	 * @param ip
	 * @return
	 */
	public static synchronized boolean removeDenyID(String id) {
		if(deniedID!=null && deniedID.remove(id)!=null) { 
			writeID();
			if(deniedID.isEmpty()) {
				deniedID=null;
			}

			return true;
		}
		return false;
	}
	
	public List<String> report() {
		int initSize = 0;
		if(deniedIP!=null)initSize+=deniedIP.size();
		if(deniedID!=null)initSize+=deniedID.size();
		ArrayList<String> al = new ArrayList<String>(initSize);
		if(deniedID!=null) {
			for(Counter c : deniedID.values()) {
				al.add(c.toString());
			}
		}
		if(deniedIP!=null) {
			for(Counter c : deniedIP.values()) {
				al.add(c.toString());
			}
		}
		return al;
	}
	
	public static class Counter {
		private final String name; 
		private int count = 0;
		private Date first;
		private long last; // note, we use "last" as long, to avoid popping useless dates on Heap.
		
		public Counter(String name) {
			this.name = name;
			first = null;
			last = 0L;
			count = 0;
		}
		
		public String getName() {
			return name;
		}
		
		public int getCount() {
			return count;
		}

		public long getLast() {
			return last;
		}
		
		/*
		 * Only allow Denial of ServiceTaf to increment
		 */
		private synchronized void inc() {
			++count;
			last = System.currentTimeMillis();
			if(first==null) {
				first = new Date(last);
			}
		}
		
		public String toString() {
			if(count==0) 
				return name + " is on the denied list, but has not attempted Access"; 
			else 
				return 
					name +
					" has been denied " +
					count +
					" times since " +
					first +
					".  Last denial was " +
					new Date(last);
		}
	}

	public static TafResp respDenyID(Access access, String identity) {
		return new DenialOfServiceTafResp(access, RESP.NO_FURTHER_PROCESSING, identity + " is on the Identity Denial list");
	}
	
	public static TafResp respDenyIP(Access access, String ip) {
		return new DenialOfServiceTafResp(access, RESP.NO_FURTHER_PROCESSING, ip + " is on the IP Denial list");
	}

}