How to limit publishing of live streams by IP list (ModuleOverridePublishRestrictIP)

Use the following module in a live application to limit publishing to allowed IP addresses. This IP list is set in Application.xml.

Note: This module has been removed from the Wowza Module Collection because the same functionality has been added to Wowza Streaming Engine™ software. See Source Security > Client Restrictions for more information about this functionality in Wowza Streaming Engine. The source code has been retained here for reference.
package com.wowza.wms.example.module;

import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.module.*;
import com.wowza.wms.request.*;

public class ModuleOverridePublishRestrictIP extends ModuleBase {

	public void publish(IClient client, RequestFunction function,
	        AMFDataList params) {
		getLogger().info("Overriding Publish");

		boolean reject = true;
		String[] ipList = null;

		try
		{
		ipList = client.getAppInstance().getProperties().getPropertyStr("ipList").toLowerCase().split(",");
		String clientIP = client.getIp();
		for (int i = 0; i < ipList.length; i++)
		{
			if (clientIP.equalsIgnoreCase(ipList[i].trim()))
			{
				reject = false;
			}
		}
		}
		catch(Exception ex)
		{
			reject = true;
		}
		if (reject)
		{
			sendClientOnStatusError(client, "NetStream.Publish.Denied", "The publisher's IP was rejected");
			getLogger().info("Client Rejected. IP: " + client.getIp());
		}
		else
		{
			invokePrevious(client, function, params);
		}
	}

	public void releaseStream(IClient client, RequestFunction function, AMFDataList params)
	{
		getLogger().info("Overriding streamRelease");

		boolean reject = true;
		String[] ipList = null;

		try
		{
		ipList = client.getAppInstance().getProperties().getPropertyStr("ipList").toLowerCase().split(",");
		String clientIP = client.getIp();
		for (int i = 0; i < ipList.length; i++)
		{
			if (clientIP.equalsIgnoreCase(ipList[i].trim()))
			{
				reject = false;
			}
		}
		}
		catch(Exception ex)
		{
			reject = true;
		}
		if (reject)
		{
			sendClientOnStatusError(client, "NetStream.Publish.Denied", "The publisher's IP was rejected");
			getLogger().info("Client Rejected. IP: " + client.getIp());
		}
		else
		{
			invokePrevious(client, function, params);
		}

	}

}
Add the following module to the Modules list of your Application.xml.
<Module>
	<Name>OverridePublishLimitIP</Name>
	<Description>Override publish</Description>
	<Class>com.wowza.wms.example.module.ModuleOverridePublishRestrictIP</Class>
</Module>
Add the following property to the Properties section of your Application.xml, below the Modules list.
<Property>
	<Name>ipList</Name>
	<Value>127.0.0.1</Value>
</Property>

Wowza media server software and all components, including modules, source code, and other related items offered on this page, are copyrighted (c) 2006-2015 by Wowza Media Systems, LLC, all rights reserved, and are licensed pursuant to the Wowza Media Software End User License Agreement.
 
Originally Published: 10-02-2010.
Updated: For Wowza Streaming Engine 4.2.0 on 06-23-2015.
 

If you're having problems or want to discuss this article, post in our forum.