Wowza Community

User Authentication

Hi there,

Assuming that you are using code similar to charlie’s post on page 1 of this thread, add some System.out.println statements to see what is happening.

Statement stmt = null;
ResultSet rs = null;
try 
{
	stmt = conn.createStatement();
	String sql = "SELECT count(*) as userCount FROM users where username = '"+userName+"' and password = '"+password+"'";
	System.out.println("sql: "+sql);
	rs = stmt.executeQuery(sql);
	if (rs.next() == true)
	{
		System.out.println("rs.getInt("userCount"): "+rs.getInt("userCount") );
		if (rs.getInt("userCount") > 0)
		{
			System.out.println("client.acceptConnection()");
			client.acceptConnection();
		}
	}
	else 
	{
		System.out.println("Error - userCount = 0. Rejecting connection");
	}
} 

I have added the sql statement as a seperate string so it can be checked for syntax.

You can also copy and paste the sql into phpmyadmin or another sql client and check it is working as expected.

Try this a see what happens.

Roger.

Hi,

The debug error is happening after the reject so I dont think it is the problem.

Can you post an example of your java code for onConnect, onConnectReject & onConnectAccept.

I have checked out the flash code and it seems to be working ok.

Roger.

try the following. Im not sure if it will work as I am not is a position to test it.

Add a couple of logs to the sql bit of the code to see if the values are getting Through:

		try 
		{
			getLogger().info("userName @ sql: "+userName);
			getLogger().info("password @ sql: "+passpword);
			String sql = "SELECT count(*) as userCount FROM users where username = '"+userName+"' and password = '"+password+"'";
			getLogger().info("sql: "+sql);
			stmt = conn.createStatement(sql);
			rs = stmt.executeQuery();
			if (rs.next() == true) {
				if (rs.getInt("userCount") > 0)
				{
					client.acceptConnection();
				}
			}
		
		} catch (SQLException sqlEx) {

Some more logger info.

		try 
		{
			getLogger().info("userName @ sql: "+userName);
			getLogger().info("password @ sql: "+passpword);
			String sql = "SELECT count(*) as userCount FROM users where username = '"+userName+"' and password = '"+password+"'";
			getLogger().info("sql: "+sql);
			stmt = conn.createStatement(sql);
			rs = stmt.executeQuery();
			getLogger().info("rs: "+rs.toString());
			if (rs.next() == true) {
				getLogger().info("rs returns recordset");
				if (rs.getInt("userCount") > 0)
				{
					getLogger().info("which contains at least 1 record so connection should be accepted");
					client.acceptConnection();
				}
				else
				{
					getLogger().info("but it is empty.  Wrong username or password maybe");
				}
			}
		
		} catch (SQLException sqlEx) {
			getLogger().error("sqlexecuteException: " + sqlEx.toString());
		} 

you can never have too much information.

INFO server comment - userName @ sql: null
INFO server comment - password @ sql: null

This is the username & password from the client params. some reason they are not getting through.

{
String userName = getParamString(params, PARAM1);
String password = getParamString(params, PARAM2);
getLogger().info("params: "+params.toString());
// preload the driver class

Add another logger to the onConnect to see what the params are.

INFO session connect-pending 61.95.197.159 -
INFO server comment - params: AMFDataList:
[0] connect
[1] 1.0
[2] object
{Obj[]: app: "rtplive", flashVer: "WIN 9,0,124,0", swfUrl: "http://72.348.410.254/WOWZA/RTP/nativertp.swf", tcUrl: "rtmp://72.348.410.254/rtplive", fpad: false, capabilities: 15.0, audioCodecs: 1639.0, videoCodecs: 252.0, videoFunction: 1.0 , pageUrl: "http://72.348.410.254/WOWZA/RTP/index.html"}
[3] undefined
[4] undefined

[3] is PARAM1 (username) &

[4] is PARAM2 (password).

add some traces to the flash code to check if these values are set properly.

function connectLivePlayer()
{
if (nc == null)
{
nc = new NetConnection();
nc.connect(serverText.text,User.text,Pwd.text);
trace('User.text: '+User.text);
trace('Pwd.text: '+Pwd.text);
:
:
:

Can you create a new empty flash document and put the following into the actionscript.

var nc:NetConnection = new NetConnection();
nc.onStatus = function(info) {
	for(var i in info) trace(i+": "+info[i]);
}
var conn:String = "rtmp://server-ip/rtplive"; // change to suit
var user:String = "monty"; // I assume thes are the user & pass in the database.
var pass:String = "greatsqldb";
nc.connect(conn, user, pass);

run it with Ctrl-Enter from flash and post what shows in the output panel & the server output again

can you make sure that it is an AS2 flash document and not AS3

Im using flash 8 which the above works.

Is there any server output to go with the above?

Also, have you set up the server to only accept connection from certian IP’s

This mybe why the above doesnt work but you should still see debug code.

You may need to upload it to test.

Double check your fla document again.

I think it is strange that you define a value for User.text & PWD.text but they show as undefined.

Make sure that you have given the text fields that are on the stage an instance name so that you can refer to them in code.

Roger.

I too would like to authenticate users from a MySQL database in addition to adding an entry to a table when a video is done recording. Thanks for posting your example code. Question. How are the user credentials passed to WMS? Can they be passed from a flash object? PHP? Are there some docs I can study to get an idea of the communication between Flash and WMS?

Hello, i have used these examples to port an existing FMS system and setup server-side authetication on Wowza however i get a java.lang.reflect.InvocationTargetException error and the connection is always accepted. There is no further information that i can get out of this to help me debug. Do you have any advice on this?

thanks

Hash

Ok thanks for the info. Instead of actually sending a username and password i wanted to modify the function to receive a single session_id token.

nc.connect(serverUrl,_root.token)

and in the module

...
static public void onConnect(IClient client, RequestFunction function, AMFDataList params) 
	{
	String token = getParamString(params, PARAM1);
	//String password = getParamString(params, PARAM2);
...

The idea being that the login is done independently and a live session table is looked up to make sure that only active and authorised sessions can access the streams.

Can you see where the error might be?

thanks

Hash

Hi i’ve worked through this issue but now i have a strange problem.

Regardless of whether the sql result leads to an acceptConnection or rejectConnection (which i added as an else condition), the flash client is still able to stream. How do i ensure that the client cannot stream if the connection is not authorised?

Log as follows:

INFO session connect-pending 125.54.xxx.xxx -
INFO server comment - Reject Connection (I added this)
INFO server comment - onConnect: 86830892
INFO server comment - onConnect: false
INFO session connect 125.54.xxx.xxx -
INFO server comment - onConnectAccept: 86830892
INFO stream create - -

AutoAccept is set to false on server and application.

thanks

Hash

Hi i have tested using the method described above and it still accepts the connection. Note that i have Wowza running on port 1936 for testing.

Log as follows:

INFO application app-start _definst_ -
INFO session connect-pending 125.54.xxx.xxx -
INFO server comment - onConnect: false
INFO session connect 125.54.xxx.xxx -
INFO server comment - onConnectAccept: 581738787

and here is the code in the flash client

nc.onStatus = function(info) {
	trace("Level: "+info.level+" Code: "+info.code);
	if (info.code == "NetConnection.Connect.Success") {
		trace("--- connected to: " + this.uri);
                          //do something
	} else if (info.code == "NetConnection.Connect.Rejected") {
		//do something
	}
};

Please advise on what might be going wrong.

Thanks

Hash

Yes the code is being executed because the log indicates so. Unfortunately it failed again:

INFO session connect-pending 125.54.xxx.xxx -
INFO server comment - REJECT
INFO server comment - onConnect: false
INFO session connect 125.54.xxx.xxx -

and the Flash client info.code response is as before

Level: status Code: NetConnection.Connect.Success

Note also that we have to have FMS running on port 1935 at the moment but i can’t imagine how that could interfere.

thanks

Hash

Hi you are absolutely right, i was calling the bwcheck module after the authentication module. I reordered the module list and the connection is being rejected as expected.

Thanks for the support.

It looks like the problem is missing user table:

ERROR server comment - sqlexecuteException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Table ‘test.users’ doesn’t exist

Richard

Send user name and password to Wowza when you connect. Assuming you have text boxes named username and pwd, it would look something like this:

var nc:NetConnection;
nc.connect("rtmp://localhost/simplevideostreaming", username.text, pwd.text)

Richard