Skip to content

Commit

Permalink
Use newline-delimited responses instead of space-delimited
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed May 20, 2015
1 parent 959db75 commit d6a8e50
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/org/avalonmediasystem/security/module/AvalonSecurity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@

import java.io.IOException;
import java.util.List;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.nio.charset.Charset;

import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.lang.StringUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.NameValuePair;

Expand All @@ -36,7 +35,7 @@ public void onAppStart(IApplicationInstance appInstance) {
}
}

private String authStream(String authToken) {
private List<String> authStream(String authToken) {
URL authUrl;

try {
Expand All @@ -47,19 +46,22 @@ private String authStream(String authToken) {
}

getLogger().debug("Authorizing against " + authUrl.toString());
List<String> authorized = new java.util.ArrayList<String>();
try {
HttpURLConnection http = (HttpURLConnection)authUrl.openConnection();
http.addRequestProperty("Accept", "text/plain");
http.setRequestMethod("GET");
http.connect();
if (http.getResponseCode() != 202 ) {
return null;
} else {
if (http.getResponseCode() == 202 ) {
BufferedReader reader = new BufferedReader(new InputStreamReader(http.getInputStream()));
String authorized = reader.readLine().trim();
getLogger().debug("Authorized to stream " + authorized);
return authorized;
String authorizedStream = reader.readLine();
while (authorizedStream != null) {
authorized.add(authorizedStream);
authorizedStream = reader.readLine();
}
getLogger().debug("Authorized to stream " + authorized.toString());
}
return authorized;
} catch (IOException err) {
getLogger().error("Error connecting to " + authUrl.toString(), err);
return null;
Expand All @@ -85,7 +87,7 @@ public void onConnect(IClient client, RequestFunction function,
AMFDataObj connectObj = (AMFDataObj)params.get(2);
String appName = connectObj.get("app").toString();
String authToken = getAuthToken(appName);
String authorized = authStream(authToken).replace(" ", ";");
String authorized = StringUtils.join(authStream(authToken), ";");
getLogger().info("StreamReadAccess: " + authorized);
client.setStreamReadAccess(authorized);
}
Expand All @@ -94,14 +96,12 @@ public void onHTTPSessionCreate(IHTTPStreamerSession httpSession) {
getLogger().info("onHTTPSessionCreate: " + httpSession.getSessionId());
String query = httpSession.getQueryStr();
String authToken = getAuthToken(query);

String authResponse = authStream(authToken);
if (authResponse == null) {
List<String> authorized = authStream(authToken);
if (authorized.isEmpty()) {
httpSession.rejectSession();
return;
}

String[] authorized = authResponse.split(" ");
String streamName = httpSession.getStreamName();

for (String authorizedStream:authorized) {
Expand Down

0 comments on commit d6a8e50

Please sign in to comment.