Java – wowza authentication using external jars
This is the source code of jar:
public class WowzaTesting { boolean authStatus = false; public boolean authenticationTest(String username,String password) { System.out.println("Authentication Process started"); // authentication code here // if authentication is done authStatus=true; else authStatus=false; if (authStatus) { return true; } else { return false; } } }
I have added to the conf file:
<Module> <Name>TestWowza</Name> <Description>Java code for testing wowza</Description> <Class>com.test.wowza.WowzaTesting</Class> </Module>
Then restart the wowza server engine
I have some questions:
>Did I miss any steps? > How do I call methods in jar files during wowza authentication?
I am currently using this command for live broadcast“
ffmpeg -i "rtsp://localhost:port/livetest" -vcodec copy -acodec copy -f rtsp "rtsp://username:password@localhost:port/live/livetest
>How can I get the user name and password from the above command to my method?
Solution
Wowza API has the authenticateusernamepasswordproviderbase class. You need to extend this class to integrate database authentication
RTSP authentication currently works in wowza by specifying the authentication method to be used in the application configuration (in the root / application / RTP / authentication / publishmethod section of the file) These publishing methods are defined in the authentication configuration To intercept this operation using a custom authentication module, you need to add a Java class as an attribute to this authentication XML file In wowza's 3rd Edition, authentication The XML file is located in the conf / directory and can be easily edited, but in version 4, this is bundled with com wowza. wms. Package in the conf package (from which you can get a copy) and copy it to your conf / folder, which will overwrite the one in the package) Therefore, wowza will use the methods defined in your class instead of the built-in methods
When wowza receives an incoming RTSP connection, it should query the user name / password from the connection and pass them to the Java class to handle authentication
The example code for integrating the database for authentication is as follows:
package com.wowza.wms.example.authenticate; import com.wowza.wms.authentication.*; import com.wowza.wms.logging.WMSLoggerFactory; import java.sql.*; public class AuthenticateUsernamePasswordProviderExample extends AuthenticateUsernamePasswordProviderBase { public String getpassword(String username) { // return password for given username String pwd = null; WMSLoggerFactory.getLogger(null).info("Authenticate getpassword username: " + username); Connection conn = null; try { conn = DriverManager.getConnection("jdbc:MysqL://localhost/wowza?user=root&password=mypassword"); Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT pwd FROM users where username = '"+username+"'"); while (rs.next()) { pwd = rs.getString("pwd"); } } catch (sqlException sqlEx) { WMSLoggerFactory.getLogger(null).error("sqlexecuteException: " + sqlEx.toString()); } finally { 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()); } return pwd; } public boolean userExists(String username) { // return true is user exists return false; } }