package modules;
import java.sql.*;
import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.module.*;
import com.wowza.wms.request.*;
import com.wowza.wms.application.*;
public class Authenticate extends ModuleBase
{
IApplicationInstance appInstance = null;
public void onAppStart(IApplicationInstance appInstance)
{
this.appInstance = appInstance;
}
public void publish(IClient client, RequestFunction function, AMFDataList params)
{
Boolean authenticated = false;
String userId = null;
String loginHash = null;
String dbUrl = “jdbc:mysql://host/db?user=user&password=passwd”;
String auth = client.getQueryStr().split(“&”);
userId = auth[0].substring(1);
loginHash = auth[1];
Connection conn = null;
try {
conn = DriverManager.getConnection(dbUrl);
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(“SELECT COUNT(*) as userCount FROM user WHERE userid = '”+userId+“’ and loginhash='”+loginHash+“'”);
if (rs.next() == true) {
if (rs.getInt(“userCount”) > 0) {
authenticated = true;
} else {
authenticated = false;
}
}
} catch (SQLException sqlEx) {
getLogger().error("sqlexecuteException: " + sqlEx.toString());
} finally {
// it is a good idea to release
// resources in a finally{} block
// in reverse-order of their creation
// if they are no-longer needed
if (rs != null) {
try {
rs.close();
} catch (SQLException sqlEx) {
rs = null;
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException sqlEx) {
stmt = null;
}
}
}
conn.close();
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
if (authenticated == true) {
invokePrevious(client, function, params);
} else {
getLogger().info(“Authenticate.publish[”+appInstance.getContextStr()+"]: Invalid user! " + userId + ", " + loginHash);
sendClientOnStatusError(client, “NetStream.Publish.Rejected”, "Invalid user! " + userId + ", " + loginHash);
}
}
public void releaseStream(IClient client, RequestFunction function, AMFDataList params)
{
Boolean authenticated = false;
String userId = null;
String loginHash = null;
String dbUrl = “jdbc:mysql://host/db?user=user&password=passwd”;
String auth = client.getQueryStr().split(“&”);
userId = auth[0].substring(1);
loginHash = auth[1];
Connection conn = null;
try {
conn = DriverManager.getConnection(dbUrl);
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(“SELECT COUNT(*) as userCount FROM user WHERE userid='”+userId+“’ and loginhash='”+loginHash+“'”);
if (rs.next() == true) {
if (rs.getInt(“userCount”) > 0) {
authenticated = true;
} else {
authenticated = false;
}
}
} catch (SQLException sqlEx) {
getLogger().error("sqlexecuteException: " + sqlEx.toString());
} finally {
// it is a good idea to release
// resources in a finally{} block
// in reverse-order of their creation
// if they are no-longer needed
if (rs != null) {
try {
rs.close();
} catch (SQLException sqlEx) {
rs = null;
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException sqlEx) {
stmt = null;
}
}
}
conn.close();
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
if (authenticated == true) {
invokePrevious(client, function, params);
} else {
getLogger().info(“Authenticate.publish[”+appInstance.getContextStr()+"]: Invalid user! " + userId + ", " + loginHash);
sendClientOnStatusError(client, “NetStream.Publish.Rejected”, "Invalid user! " + userId + ", " + loginHash);
}
}
}
I creatred something like this and it is working!