Wowza Community

How to Limit Stream Name Allowed PER APPLICATIONS?

Hi,

How to limit the allowed streamname for an application? I will use it for real time streaming.

For example, I want for application:

rtmp://www.domain.com/event1

only able to stream using:

stream name: event1

When the user use other stream name (such as: event2), the server will reject.

I would like to limit STREAMNAME, per APPLICATION. For example:

rtmp://www.domain.com/event1 - Only allowed to use STREAM NAME: event1

rtmp://www.domain.com/event2 - Only allowed to use STREAM NAME: event2

I tried to use “Stream Name Alias”, what is the “pattern” I need to use?

Or can I limit this simply in /conf/[application name]/Application.xml ?

Thank you in advance.

Using StreamNameAlias, you can do this by having a different play alias map for each application, then removing the “default rule” *=${Stream.Name} from each play alias map file, and add one line like this:

event1=event1

Richard

To prevent publishing streams that are not allowed by name, you can override the publish command like this:

package test;
import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.module.*;
import com.wowza.wms.request.*;
import com.wowza.wms.stream.*;
public class ModuleOverridePublishLimitStream extends ModuleBase {
	
	public void publish(IClient client, RequestFunction function,
	        AMFDataList params) {
		getLogger().info("Overriding Publish");
		
		String allowedStream = client.getProperties().getPropertyStr("allowedStream");
		
		String streamName = getParamString(params, PARAM1);
		
		if (streamName.startsWith(allowedStream))
		{
			invokePrevious(client, function, params);
		}
	}
public void releaseStream(IClient client, RequestFunction function, AMFDataList params)
	{
		String streamName = getParamString(params, PARAM1);
		
		String allowedStream = client.getProperties().getPropertyStr("allowedStream");
		if (streamName.startsWith(allowedStream))
		{
			invokePrevious(client, function, params);
		}		
	}
}

Add a Property named “allowedStream” to the Properties list at the bottom of the /conf/[app-name]/Application.xml

<Property>
	<Name>allowedStream</Name>
	<Value>event1</Value>
</Property>

Richard

Yes, use Wowza IDE. It will automatically build a .jar a file in the Wowza /lib folder.

http://www.wowza.com/media-server/developers#wowza-ide

A short, simple guide is here:

http://www.wowza.com/uploads/developers/WowzaIDE_UsersGuide.pdf

Richard

You have to match the package in the source code with the package you have created it in using the IDE, and the Class name has to be the same as the file name you used in the IDE. If you hover over the error lines the IDE will give you options to fix both.

There is a guide here:

http://www.wowza.com/uploads/developers/WowzaIDE_UsersGuide.pdf

Richard

Also, it’s not required, but the convention is lower case package path, and camel case class names with initial cap, e.g. ModuleExample

Richard

Hi Richard, thank you for your reply. The STREAM NAME restriction is now working to for the PLAY, but NOT working for the STREAM.

For example, I use “event1=event1” for “aliasmap.play.txt” and “aliasmap.stream.txt”. I have deleted “*=${Stream.Name}” inside those 2 files.

When I STREAM with event2, my Wirecast still can STREAM to stream name: event2. When I PLAY with event2, the server reject, with code “Stream alias access denied event2.”.

Why the server still accept the STREAM and reject the PLAY? Is this how it suppose to work? or do I miss something here?

Thank you again!

I read somewhere in the forum, in Application.xml, that the ORDERING or each modules & property make the difference. So, what is the best practice of the ORDERING?

For example, in MODULE, I place HOTLINK PROTECTION, RTMP AUTHENTICATE, then STREAM NAME ALIAS.

Could you please clarify about this? Thank you.

Hi Richard, thank you for your reply.

Where should I place the code (box #1)? Should I compile it with Java/IDE and place it in /lib? Sorry I am new with Java/IDE.

Thank you again.

Hi Richard, thank you for your reply. I have installed Wowza IDE, copy and paste your code above. How to build .JAR file in /lib ? Which menu I should go to ? Below I attached the screenshot of my wowza IDE. Appreciate it. Ferdy.

Thanks for the post, but I wanted to point out that this is not perfect.

In fact, the string “if (streamName.startsWith (allowedStream))”

identifies “Start With”, then the lock is easily circumvented by using names that start the same way.

For example, using a name “foo” for the authorization will be accepted all the names that will be “foo1” “foo2”, etc. … etc. …

I resolved, I am attaching the. Jar already compiled.

https://www.dropbox.com/s/ygk7rjamqmm4625/wms-limitstreams.jar

You need to edit the file “application” the following lines.

              <Module>
				<Name>PublishLimitStream</Name>
				<Description>PublishLimitStream</Description>
				<Class>it.troydesign.wms.module.PublishLimitStream</Class>
			</Module>

<Property>
				<Name>AllowedStreams</Name>
				<Value>events</Value>
			</Property>

You can put them in the folder of the single application

You can insert the following line “events” more than one item, separating the “|” character, for example:

events|events2|events3 ecc… ecc…

I hope to be of help!

Troydesign.it

Hi all,

i’ve follow the very good istructions of this thread to write a jar module to limit Stream name allowed in application.

I have installed Wowza 4.1.0 on this java environment:

java version “1.7.0_60”

Java™ SE Runtime Environment (build 1.7.0_60-b19)

Java HotSpot™ 64-Bit Server VM (build 24.60-b09, mixed mode)

This is the java code of our module:

package com.logikamente.wms.module;
import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.module.*;
import com.wowza.wms.request.*;
/**
 * Class to Limit streams by name. 
 * Code inspired by: 
 * http://www.wowza.com/community/t/-/37298
 * @author isacco@logikamente.it
 */
public class LimitStreamByName extends ModuleBase {
	/**
	 * Publish a stream 
	 * @param client
	 * @param function
	 * @param params
	 */
	public void publish(IClient client, RequestFunction function,
	        AMFDataList params) {
		getLogger().info("Overriding Publish");
		
		// Invoke App Instance to retrieve name
		String AllowedStreams = client.getAppInstance().getProperties().getPropertyStr("AllowedStreams");
		getLogger().info("Streams allowed to publication: " + AllowedStreams);
		
		String streamName = getParamString(params, PARAM1);
		getLogger().info("Streams from client: " + streamName);
		
		// Split AllowedStreams
		String[] SplitAllowedStreams = AllowedStreams.split("\\|");
		//getLogger().info(SplitAllowedStreams);
		
		// set boolean foundIt default value to false
		boolean foundIt = false;
		
		// Check if input stream name match our allowed stream names
		for(int i =0; i < SplitAllowedStreams.length ; i++)
		{	
			if( streamName.equals(SplitAllowedStreams[i]) )
			{
				foundIt = true;
	            getLogger().info(streamName + " match.");
	            break;
			}
		}
	    
        // found it: admit stream
		if ( foundIt )
		{
			invokePrevious(client, function, params);
		}
	}
	
	/**
	 * Release a Stream
	 * @param client
	 * @param function
	 * @param params
	 */
		
	public void releaseStream(IClient client, RequestFunction function, AMFDataList params)
	[INDENT]{
		
		// Invoke App Instance to retrieve name
				String AllowedStreams = client.getAppInstance().getProperties().getPropertyStr("AllowedStreams");
				getLogger().info("Streams allowed to publication: " + AllowedStreams);
				
				String streamName = getParamString(params, PARAM1);
				getLogger().info("Streams from client: " + streamName);
				
				// Split AllowedStreams
				String[] SplitAllowedStreams = AllowedStreams.split("\\|");
				//getLogger().info(SplitAllowedStreams);
				
				// set boolean foundIt default value to false
				boolean foundIt = false;
				
				// Check if input stream name match our allowed stream names
				for(int i =0; i < SplitAllowedStreams.length ; i++)
				{	
					if( streamName.equals(SplitAllowedStreams[i]) )
					{
						foundIt = true;
			            getLogger().info(streamName + " match.");
			            break;
					}
				}
		
[/INDENT]				if ( foundIt )
				{
					invokePrevious(client, function, params);
				}
	}
}

The module is correctly write in the application.xml of application:

 <Module>
                                <Name>LimitStreamByName</Name>
                                <Description>Logikamente</Description>
                                <Class>com.logikamente.wms.module.LimitStreamByName</Class>
                        </Module>

And paramters are defined in this way:

 <Property>
                 <Name>AllowedStreams</Name>
                 <Value>webcam1|webcam2|webcam3|webcam4</Value>
</Property>

When i test the module with wowza-eclipse or in production in the [installdir]/logs/wowzastreamingengine_error.log i see this error:

ERROR   server  comment 2014-10-10      14:34:25        -       -       -       -       -       9.032   -       -       -       -       -
       -       -       -       invoke(releaseStream): java.lang.reflect.InvocationTargetException|at sun.reflect.NativeMethodAccessorImpl.in
voke0(Native Method)|at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)|at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)|at java.lang.reflect.Method.invoke(Method.java:606)|at com.wowza.wms.module.ModuleFunction.invoke(ModuleFunction.java:369)|

This cause some streams fails to reconnect after the restart of wowza server and a message “Error loading stream: ID not found on server” is shown on player.

Thanks in advance for help.

Isacco

I resolved, I am attaching the. Jar already compiled.

https://www.dropbox.com/s/ygk7rjamqmm4625/wms-limitstreams.jar

You need to edit the file “application” the following lines.

              <Module>
				<Name>PublishLimitStream</Name>
				<Description>PublishLimitStream</Description>
				<Class>it.troydesign.wms.module.PublishLimitStream</Class>
			</Module>

<Property>
				<Name>AllowedStreams</Name>
				<Value>events</Value>
			</Property>

You can put them in the folder of the single application

You can insert the following line “events” more than one item, separating the “|” character, for example:

events|events2|events3 ecc… ecc…

I hope to be of help!

Troydesign.it

Using the same code and module example code as above in WowzaStreamingEngine and getting the same error as above for both publish() and release()

hi,
Has anyone managed to get this module to work to allowing only stream name entry ?
I’m interested if someone can share jar file if it still works.
Thanks

Take a look at this module and extend from there

1 Like