Results 1 to 4 of 4

Thread: how to block duplicate authen in ModuleOnConnectAuthenticate2

  1. #1
    Join Date
    Dec 2009
    Posts
    2

    Default how to block duplicate authen in ModuleOnConnectAuthenticate2

    how to build code ModuleOnConnectAuthenticate2 for limit number to connect by user and pass or block duplicate authen to content?

    thank you

  2. #2
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    You don't have to build it. As noted in the example, you can download the pre-built Modules Collection which includes this module. Download, copy the .jar to Wowza /lib folder, configure the Application.xml as shown, then re-start Wowza.

    Richard

  3. #3
    Join Date
    Dec 2009
    Posts
    2

    Default

    Quote Originally Posted by rrlanham View Post
    You don't have to build it. As noted in the example, you can download the pre-built Modules Collection which includes this module. Download, copy the .jar to Wowza /lib folder, configure the Application.xml as shown, then re-start Wowza.

    Richard
    in normal code it can limit or block duplicate?
    package com.wowza.wms.plugin.collection.module;
    
    import java.io.*;
    import java.util.*;
    
    import com.wowza.util.*;
    import com.wowza.wms.amf.*;
    import com.wowza.wms.application.*;
    import com.wowza.wms.authentication.*;
    import com.wowza.wms.authentication.file.*;
    import com.wowza.wms.client.*;
    import com.wowza.wms.module.*;
    import com.wowza.wms.request.*;
    import com.wowza.wms.util.*;
    import com.wowza.wms.vhost.*;
    
    public class ModuleOnConnectAuthenticate2 extends ModuleBase
    { 
    	public static final String AUTHPASSWORDFILEPATH = "${com.wowza.wms.context.VHostConfigHome}/conf/connect.password";
    	private File passwordFile = null;
    	private String usernamePasswordProviderClass = null;
    
    	public void onAppStart(IApplicationInstance appInstance)
    	{
    		WMSProperties props = appInstance.getProperties();
    				
    		String passwordFileStr = props.getPropertyStr("rtmpAuthenticateFile", AUTHPASSWORDFILEPATH);
    		this.usernamePasswordProviderClass = props.getPropertyStr("usernamePasswordProviderClass", this.usernamePasswordProviderClass);
    		if (passwordFileStr != null)
    		{
    			Map<String, String> envMap = new HashMap<String, String>();
    			
    			IVHost vhost = appInstance.getVHost();
    			envMap.put("com.wowza.wms.context.VHost", vhost.getName());
    			envMap.put("com.wowza.wms.context.VHostConfigHome", vhost.getHomePath());
    			envMap.put("com.wowza.wms.context.Application", appInstance.getApplication().getName());
    			envMap.put("com.wowza.wms.context.ApplicationInstance", appInstance.getName());
    
    			passwordFileStr = SystemUtils.expandEnvironmentVariables(passwordFileStr, envMap);
    			passwordFile = new File(passwordFileStr);
    		}
    		
    		if (passwordFile != null)
    			getLogger().info("ModuleOnConnectAuthenticate: Authorization password file: "+passwordFile.getAbsolutePath());
    		if (usernamePasswordProviderClass != null)
    			getLogger().info("ModuleOnConnectAuthenticate: Authorization password class: "+usernamePasswordProviderClass);
    	}
    
    public void onConnect(IClient client, RequestFunction function, AMFDataList params)
    {
    	boolean isAuthenticated = false;
    	
    	String username = null;
    	String password = null;
    	
    	try
    	{
    		while(true)
    		{
    			getLogger().info("size: " + params.size());
    			
    			String[] auth = client.getQueryStr().split("&");
    			
    			username = auth[0];
    			password = auth[1];
    				
    				if (username == null || password == null)
    					break;
    								
    				IAuthenticateUsernamePasswordProvider filePtr = null;
    				if (usernamePasswordProviderClass != null)
    					filePtr = AuthenticationUtils.createUsernamePasswordProvider(usernamePasswordProviderClass);
    				else if (passwordFile != null)
    					filePtr = AuthenticationPasswordFiles.getInstance().getPasswordFile(passwordFile);
    				
    				if (filePtr == null)
    					break;
    
    				filePtr.setClient(client);
    
    				String userPassword = filePtr.getPassword(username);
    				if (userPassword == null)
    					break;
    
    				if (!userPassword.equals(password))
    					break;
    				
    				isAuthenticated = true;
    				break;
    			}
    		}
    		catch(Exception e)
    		{
    			getLogger().error("ModuleOnConnectAuthenticate.onConnect: "+e.toString());
    			isAuthenticated = false;
    		}
    		
    		if (!isAuthenticated)
    			client.rejectConnection("Authentication Failed["+client.getClientId()+"]: "+username);
    		else
    			client.acceptConnection();
    	}
    }

  4. #4
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    If you need to modify and re-built it, you have to use the Wowza IDE.

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

    Richard

Similar Threads

  1. Duplicate stream
    By mikekoz in forum General Forum
    Replies: 1
    Last Post: 03-03-2014, 10:51 AM
  2. stream duplicate
    By tomloko in forum General Forum
    Replies: 1
    Last Post: 03-20-2013, 06:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •