Skip to content

Commit

Permalink
Merge pull request #19 from alianza-dev/paraplexed/add_authorization_…
Browse files Browse the repository at this point in the history
…username

Paraplexed/add authorization username
  • Loading branch information
ymartineau committed May 3, 2016
2 parents 22b1674 + 4b69d94 commit af46198
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ target/
peers-demo/src/main/java/net/sourceforge/peers/demo/MyConfig.java
\#*#
bin/
logs/
3 changes: 3 additions & 0 deletions conf/peers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<!-- you can specify an even rtp port to use for incoming and outgoing rtp
traffic, 0 can be used to choose a random even free port -->
<rtpPort>0</rtpPort>
<!-- if you need to specify an authorization username different than
the userPart, if empty will default to what is specified in userPart -->
<authorizationUsername></authorizationUsername>
<!-- mediaMode corresponds to the way media is managed. Three values are
possible for this parameter:
- captureAndPlayback: capture sound from microphone, send
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public InetAddress getLocalInetAddress() {
@Override
public MediaMode getMediaMode() { return MediaMode.captureAndPlayback; }

@Override public String getAuthorizationUsername() { return getUserPart(); }

@Override
public void setPublicInetAddress(InetAddress inetAddress) {
publicIpAddress = inetAddress;
Expand All @@ -57,5 +59,6 @@ public void setPublicInetAddress(InetAddress inetAddress) {
@Override public void setMediaFile(String mediaFile) { }
@Override public void setRtpPort(int rtpPort) { }
@Override public void save() { }
@Override public void setAuthorizationUsername(String authorizationUsername) { }

}
2 changes: 2 additions & 0 deletions peers-lib/src/main/java/net/sourceforge/peers/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public interface Config {
public boolean isMediaDebug();
public String getMediaFile();
public int getRtpPort();
public String getAuthorizationUsername();
public void setLocalInetAddress(InetAddress inetAddress);
public void setPublicInetAddress(InetAddress inetAddress);
public void setUserPart(String userPart);
Expand All @@ -49,5 +50,6 @@ public interface Config {
public void setMediaDebug(boolean mediaDebug);
public void setMediaFile(String mediaFile);
public void setRtpPort(int rtpPort);
public void setAuthorizationUsername(String authorizationUsername);

}
9 changes: 9 additions & 0 deletions peers-lib/src/main/java/net/sourceforge/peers/JavaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class JavaConfig implements Config {
private boolean mediaDebug;
private String mediaFile;
private int rtpPort;
private String authorizationUsername;

@Override
public void save() {
Expand Down Expand Up @@ -93,6 +94,10 @@ public int getRtpPort() {
return rtpPort;
}

public String getAuthorizationUsername() {
return authorizationUsername;
}

@Override
public void setLocalInetAddress(InetAddress inetAddress) {
localInetAddress = inetAddress;
Expand Down Expand Up @@ -143,6 +148,10 @@ public void setRtpPort(int rtpPort) {
this.rtpPort = rtpPort;
}

public void setAuthorizationUsername(String authorizationUsername) {
this.authorizationUsername = authorizationUsername;
}

@Override
public String getMediaFile() {
return mediaFile;
Expand Down
17 changes: 17 additions & 0 deletions peers-lib/src/main/java/net/sourceforge/peers/XmlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class XmlConfig implements Config {
private boolean mediaDebug;
private String mediaFile;
private int rtpPort;
private String authorizationUsername;

// corresponding DOM nodes

Expand All @@ -81,6 +82,7 @@ public class XmlConfig implements Config {
private Node mediaDebugNode;
private Node mediaFileNode;
private Node rtpPortNode;
private Node authUserNode;

// non-persistent variables

Expand Down Expand Up @@ -130,6 +132,10 @@ public XmlConfig(String fileName, Logger logger) {
} else {
userPart = userPartNode.getTextContent();
}
authUserNode = getFirstChild(documentElement, "authorizationUsername");
if (! isNullOrEmpty(authUserNode)) {
authorizationUsername = authUserNode.getTextContent();
}
domainNode = getFirstChild(documentElement, "domain");
if (isNullOrEmpty(domainNode)) {
logger.error("domain not found in configuration file");
Expand Down Expand Up @@ -284,6 +290,11 @@ public int getRtpPort() {
return rtpPort;
}

@Override
public String getAuthorizationUsername() {
return authorizationUsername;
}

@Override
public void setLocalInetAddress(InetAddress inetAddress) {
this.localInetAddress = inetAddress;
Expand Down Expand Up @@ -348,6 +359,12 @@ public void setRtpPort(int rtpPort) {
rtpPortNode.setTextContent(Integer.toString(rtpPort));
}

@Override
public void setAuthorizationUsername(String authorizationUsername) {
this.authorizationUsername = authorizationUsername;
authUserNode.setTextContent(authorizationUsername);
}

@Override
public String getMediaFile() {
return mediaFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ChallengeManager implements MessageInterceptor {
private String profileUri;
private String qop;
private String cnonce;
private String authorizationUsername;

private static volatile int nonceCount = 1;
private String nonceCountHex;
Expand Down Expand Up @@ -84,6 +85,10 @@ public ChallengeManager(Config config,

private void init() {
username = config.getUserPart();
authorizationUsername = config.getAuthorizationUsername();
if (authorizationUsername == null || authorizationUsername.isEmpty()) {
authorizationUsername = username;
}
password = config.getPassword();
profileUri = RFC3261.SIP_SCHEME + RFC3261.SCHEME_SEPARATOR
+ username + RFC3261.AT + config.getDomain();
Expand Down Expand Up @@ -173,7 +178,7 @@ public void handleChallenge(SipRequest sipRequest,

private String getRequestDigest(String method) {
StringBuffer buf = new StringBuffer();
buf.append(username);
buf.append(authorizationUsername);
buf.append(RFC2617.DIGEST_SEPARATOR);
buf.append(realm);
buf.append(RFC2617.DIGEST_SEPARATOR);
Expand Down Expand Up @@ -242,7 +247,7 @@ public void postProcess(SipMessage sipMessage) {
digest = getRequestDigest(method);
StringBuffer buf = new StringBuffer();
buf.append(RFC2617.SCHEME_DIGEST).append(" ");
appendParameter(buf, RFC2617.PARAM_USERNAME, username);
appendParameter(buf, RFC2617.PARAM_USERNAME, authorizationUsername);
buf.append(RFC2617.PARAM_SEPARATOR).append(" ");
appendParameter(buf, RFC2617.PARAM_REALM, realm);
buf.append(RFC2617.PARAM_SEPARATOR).append(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public void testSave() throws SipUriSyntaxException, UnknownHostException {
MediaMode mediaMode = MediaMode.echo;
boolean mediaDebug = true;
int rtpPort = 8002;
String authorizationUsername = "authUser";

config.setLocalInetAddress(localHost);
config.setUserPart(userPart);
config.setDomain(domain);
Expand All @@ -53,6 +55,7 @@ public void testSave() throws SipUriSyntaxException, UnknownHostException {
config.setMediaMode(mediaMode);
config.setMediaDebug(mediaDebug);
config.setRtpPort(rtpPort);
config.setAuthorizationUsername(authorizationUsername);
config.save();
config = new XmlConfig(fileName, logger);
assert localHost.equals(config.getLocalInetAddress());
Expand All @@ -64,6 +67,7 @@ public void testSave() throws SipUriSyntaxException, UnknownHostException {
assert mediaMode == config.getMediaMode();
assert mediaDebug == config.isMediaDebug();
assert rtpPort == config.getRtpPort();
assert authorizationUsername.equals(config.getAuthorizationUsername());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<!-- you can specify the rtp port to use for incoming and outgoing rtp
traffic, 0 can be used to choose a random free port -->
<rtpPort>0</rtpPort>
<!-- if you need to specify an authorization username different than
the userPart, if empty will default to what is specified in userPart -->
<authorizationUsername></authorizationUsername>
<!-- mediaMode corresponds to the way media is managed. Three values are
possible for this parameter:
- captureAndPlayback: capture sound from microphone, send
Expand All @@ -58,4 +61,4 @@
contain raw data at input and output of microphone, encoder, rtp
sender, rtp receiver, and speaker. -->
<mediaDebug>false</mediaDebug>
</peers>
</peers>

0 comments on commit af46198

Please sign in to comment.