openvidu-server: IdentifierPrefixes enumeration

pull/391/head
pabloFuente 2020-01-29 18:19:13 +01:00
parent 1f139b8211
commit 78deea7f3b
10 changed files with 41 additions and 18 deletions

View File

@ -0,0 +1,16 @@
package io.openvidu.server.core;
/**
* @author Pablo Fuente (pablofuenteperez@gmail.com)
*/
public interface IdentifierPrefixes {
public static final String PARTICIPANT_PUBLIC_ID = "con_";
public static final String STREAM_ID = "str_";
public static final String SESSION_ID = "ses_";
public static final String TOKEN_ID = "tok_";
public static final String IPCAM_ID = "ipc_";
public static final String KMS_ID = "kms_";
public static final String CLUSTER_ID = "clu_";
}

View File

@ -146,7 +146,7 @@ public class Participant {
}
public boolean isIpcam() {
return this.platform.equals("IPCAM") && this.participantPrivatetId.startsWith("ipc_");
return this.platform.equals("IPCAM") && this.participantPrivatetId.startsWith(IdentifierPrefixes.IPCAM_ID);
}
public String getPublisherStreamId() {

View File

@ -368,14 +368,14 @@ public abstract class SessionManager {
public Participant newParticipant(String sessionId, String participantPrivatetId, Token token,
String clientMetadata, GeoLocation location, String platform, String finalUserId) {
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
String participantPublicId = "con_" + RandomStringUtils.randomAlphabetic(1).toUpperCase()
+ RandomStringUtils.randomAlphanumeric(9);
String participantPublicId = IdentifierPrefixes.PARTICIPANT_PUBLIC_ID
+ RandomStringUtils.randomAlphabetic(1).toUpperCase() + RandomStringUtils.randomAlphanumeric(9);
Participant p = new Participant(finalUserId, participantPrivatetId, participantPublicId, sessionId, token,
clientMetadata, location, platform, EndpointType.WEBRTC_ENDPOINT, null);
while (this.sessionidParticipantpublicidParticipant.get(sessionId).putIfAbsent(participantPublicId,
p) != null) {
participantPublicId = "con_" + RandomStringUtils.randomAlphabetic(1).toUpperCase()
+ RandomStringUtils.randomAlphanumeric(9);
participantPublicId = IdentifierPrefixes.PARTICIPANT_PUBLIC_ID
+ RandomStringUtils.randomAlphabetic(1).toUpperCase() + RandomStringUtils.randomAlphanumeric(9);
p.setParticipantPublicId(participantPublicId);
}

View File

@ -40,7 +40,7 @@ public class TokenGeneratorDefault implements TokenGenerator {
KurentoTokenOptions kurentoTokenOptions) {
String token = OpenViduServer.wsUrl;
token += "?sessionId=" + sessionId;
token += "&token=" + "tok_" + RandomStringUtils.randomAlphabetic(1).toUpperCase()
token += "&token=" + IdentifierPrefixes.TOKEN_ID + RandomStringUtils.randomAlphabetic(1).toUpperCase()
+ RandomStringUtils.randomAlphanumeric(15);
token += "&role=" + role.name();
token += "&version=" + openviduConfig.getOpenViduServerVersion();

View File

@ -47,6 +47,7 @@ import io.openvidu.client.internal.ProtocolElements;
import io.openvidu.java.client.OpenViduRole;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.core.EndReason;
import io.openvidu.server.core.IdentifierPrefixes;
import io.openvidu.server.core.MediaOptions;
import io.openvidu.server.core.Participant;
import io.openvidu.server.kurento.endpoint.MediaEndpoint;
@ -101,9 +102,9 @@ public class KurentoParticipant extends Participant {
public void createPublishingEndpoint(MediaOptions mediaOptions) {
String type = mediaOptions.hasVideo() ? mediaOptions.getTypeOfVideo() : "MICRO";
final String publisherStreamId = "str_" + type.substring(0, Math.min(type.length(), 3)) + "_"
+ RandomStringUtils.randomAlphabetic(1).toUpperCase() + RandomStringUtils.randomAlphanumeric(3) + "_"
+ this.getParticipantPublicId().substring(4, this.getParticipantPublicId().length());
final String publisherStreamId = IdentifierPrefixes.STREAM_ID + type.substring(0, Math.min(type.length(), 3))
+ "_" + RandomStringUtils.randomAlphabetic(1).toUpperCase() + RandomStringUtils.randomAlphanumeric(3)
+ "_" + this.getParticipantPublicId().substring(4, this.getParticipantPublicId().length());
publisher.setStreamId(publisherStreamId);
publisher.setEndpointName(publisherStreamId);
publisher.setMediaOptions(mediaOptions);

View File

@ -52,6 +52,7 @@ import io.openvidu.java.client.RecordingProperties;
import io.openvidu.java.client.SessionProperties;
import io.openvidu.server.core.EndReason;
import io.openvidu.server.core.FinalUser;
import io.openvidu.server.core.IdentifierPrefixes;
import io.openvidu.server.core.MediaOptions;
import io.openvidu.server.core.Participant;
import io.openvidu.server.core.Session;
@ -900,14 +901,13 @@ public class KurentoSessionManager extends SessionManager {
}
String rtspConnectionId = kMediaOptions.getTypeOfVideo() + "_" + protocol + "_"
+ RandomStringUtils.randomAlphanumeric(4).toUpperCase() + "_" + url.getAuthority()
+ url.getPath();
+ RandomStringUtils.randomAlphanumeric(4).toUpperCase() + "_" + url.getAuthority() + url.getPath();
rtspConnectionId = rtspConnectionId.replace("/", "_").replace("-", "").replace(".", "_");
rtspConnectionId = "ipc_" + rtspConnectionId;
rtspConnectionId = IdentifierPrefixes.IPCAM_ID + rtspConnectionId;
// Store a "fake" participant for the IpCam connection
this.newInsecureParticipant(rtspConnectionId);
String token = "tok_" + RandomStringUtils.randomAlphabetic(1).toUpperCase()
String token = IdentifierPrefixes.TOKEN_ID + RandomStringUtils.randomAlphabetic(1).toUpperCase()
+ RandomStringUtils.randomAlphanumeric(15);
Token tokenObj = null;
if (this.isTokenValidInSession(token, sessionId, rtspConnectionId, serverMetadata)) {

View File

@ -27,6 +27,8 @@ import org.apache.commons.lang3.RandomStringUtils;
import org.kurento.client.KurentoClient;
import org.kurento.commons.exception.KurentoException;
import io.openvidu.server.core.IdentifierPrefixes;
public class FixedOneKmsManager extends KmsManager {
@Override
@ -60,7 +62,7 @@ public class FixedOneKmsManager extends KmsManager {
try {
List<KmsProperties> kmsProps = new ArrayList<>();
for (String kmsUri : this.openviduConfig.getKmsUris()) {
String kmsId = "kms_" + RandomStringUtils.randomAlphabetic(1).toUpperCase()
String kmsId = IdentifierPrefixes.KMS_ID + RandomStringUtils.randomAlphabetic(1).toUpperCase()
+ RandomStringUtils.randomAlphanumeric(7);
kmsProps.add(new KmsProperties(kmsId, kmsUri));
}

View File

@ -55,6 +55,7 @@ import io.openvidu.java.client.RecordingProperties;
import io.openvidu.java.client.SessionProperties;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.core.EndReason;
import io.openvidu.server.core.IdentifierPrefixes;
import io.openvidu.server.core.Participant;
import io.openvidu.server.core.Session;
import io.openvidu.server.core.SessionManager;
@ -159,7 +160,7 @@ public class SessionRestController {
}
sessionId = customSessionId;
} else {
sessionId = "ses_" + RandomStringUtils.randomAlphabetic(1).toUpperCase()
sessionId = IdentifierPrefixes.SESSION_ID + RandomStringUtils.randomAlphabetic(1).toUpperCase()
+ RandomStringUtils.randomAlphanumeric(9);
}

View File

@ -47,6 +47,7 @@ import io.openvidu.client.OpenViduException.Code;
import io.openvidu.client.internal.ProtocolElements;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.core.EndReason;
import io.openvidu.server.core.IdentifierPrefixes;
import io.openvidu.server.core.MediaOptions;
import io.openvidu.server.core.Participant;
import io.openvidu.server.core.SessionManager;
@ -231,7 +232,7 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
if (openviduConfig.isOpenViduSecret(secret)) {
sessionManager.newInsecureParticipant(participantPrivatetId);
token = "tok_" + RandomStringUtils.randomAlphabetic(1).toUpperCase()
token = IdentifierPrefixes.TOKEN_ID + RandomStringUtils.randomAlphabetic(1).toUpperCase()
+ RandomStringUtils.randomAlphanumeric(15);
if (recorder) {
generateRecorderParticipant = true;
@ -326,7 +327,8 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
String senderPublicId = getStringParam(request, ProtocolElements.RECEIVEVIDEO_SENDER_PARAM);
// Parse sender public id from stream id
senderPublicId = "con" + senderPublicId.substring(senderPublicId.lastIndexOf("_"), senderPublicId.length());
senderPublicId = IdentifierPrefixes.PARTICIPANT_PUBLIC_ID
+ senderPublicId.substring(senderPublicId.lastIndexOf("_") + 1, senderPublicId.length());
String sdpOffer = getStringParam(request, ProtocolElements.RECEIVEVIDEO_SDPOFFER_PARAM);
sessionManager.subscribe(participant, senderPublicId, sdpOffer, request.getId());

View File

@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
import com.google.gson.JsonObject;
import io.openvidu.client.OpenViduException;
import io.openvidu.server.core.IdentifierPrefixes;
public class RpcNotificationService {
@ -151,7 +152,7 @@ public class RpcNotificationService {
}
private boolean isIpcamParticipant(String participantPrivateId) {
return participantPrivateId.startsWith("ipc_");
return participantPrivateId.startsWith(IdentifierPrefixes.IPCAM_ID);
}
}