openvidu-server: RandomStringGenerator removed

pull/375/head
pabloFuente 2019-07-05 12:54:19 +02:00
parent fa08ee87f0
commit c8576b4358
5 changed files with 9 additions and 41 deletions

View File

@ -28,6 +28,7 @@ import java.util.stream.Collectors;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import org.apache.commons.lang3.RandomStringUtils;
import org.kurento.jsonrpc.message.Request; import org.kurento.jsonrpc.message.Request;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -48,7 +49,6 @@ import io.openvidu.server.kurento.core.KurentoTokenOptions;
import io.openvidu.server.recording.service.RecordingManager; import io.openvidu.server.recording.service.RecordingManager;
import io.openvidu.server.utils.FormatChecker; import io.openvidu.server.utils.FormatChecker;
import io.openvidu.server.utils.GeoLocation; import io.openvidu.server.utils.GeoLocation;
import io.openvidu.server.utils.RandomStringGenerator;
public abstract class SessionManager { public abstract class SessionManager {
@ -348,12 +348,12 @@ public abstract class SessionManager {
public Participant newParticipant(String sessionId, String participantPrivatetId, Token token, public Participant newParticipant(String sessionId, String participantPrivatetId, Token token,
String clientMetadata, GeoLocation location, String platform, String finalUserId) { String clientMetadata, GeoLocation location, String platform, String finalUserId) {
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) { if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
String participantPublicId = RandomStringGenerator.generateRandomChain(); String participantPublicId = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
Participant p = new Participant(finalUserId, participantPrivatetId, participantPublicId, sessionId, token, Participant p = new Participant(finalUserId, participantPrivatetId, participantPublicId, sessionId, token,
clientMetadata, location, platform, null); clientMetadata, location, platform, null);
while (this.sessionidParticipantpublicidParticipant.get(sessionId).putIfAbsent(participantPublicId, while (this.sessionidParticipantpublicidParticipant.get(sessionId).putIfAbsent(participantPublicId,
p) != null) { p) != null) {
participantPublicId = RandomStringGenerator.generateRandomChain(); participantPublicId = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
p.setParticipantPublicId(participantPublicId); p.setParticipantPublicId(participantPublicId);
} }

View File

@ -17,6 +17,7 @@
package io.openvidu.server.core; package io.openvidu.server.core;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import io.openvidu.java.client.OpenViduRole; import io.openvidu.java.client.OpenViduRole;
@ -25,7 +26,6 @@ import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.coturn.CoturnCredentialsService; import io.openvidu.server.coturn.CoturnCredentialsService;
import io.openvidu.server.coturn.TurnCredentials; import io.openvidu.server.coturn.TurnCredentials;
import io.openvidu.server.kurento.core.KurentoTokenOptions; import io.openvidu.server.kurento.core.KurentoTokenOptions;
import io.openvidu.server.utils.RandomStringGenerator;
public class TokenGeneratorDefault implements TokenGenerator { public class TokenGeneratorDefault implements TokenGenerator {
@ -40,7 +40,7 @@ public class TokenGeneratorDefault implements TokenGenerator {
KurentoTokenOptions kurentoTokenOptions) { KurentoTokenOptions kurentoTokenOptions) {
String token = OpenViduServer.wsUrl; String token = OpenViduServer.wsUrl;
token += "?sessionId=" + sessionId; token += "?sessionId=" + sessionId;
token += "&token=" + RandomStringGenerator.generateRandomChain(); token += "&token=" + RandomStringUtils.randomAlphanumeric(16).toLowerCase();
token += "&role=" + role.name(); token += "&role=" + role.name();
token += "&version=" + openviduConfig.getOpenViduServerVersion(); token += "&version=" + openviduConfig.getOpenViduServerVersion();
TurnCredentials turnCredentials = null; TurnCredentials turnCredentials = null;

View File

@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -57,7 +58,6 @@ import io.openvidu.server.core.SessionManager;
import io.openvidu.server.kurento.core.KurentoTokenOptions; import io.openvidu.server.kurento.core.KurentoTokenOptions;
import io.openvidu.server.recording.Recording; import io.openvidu.server.recording.Recording;
import io.openvidu.server.recording.service.RecordingManager; import io.openvidu.server.recording.service.RecordingManager;
import io.openvidu.server.utils.RandomStringGenerator;
/** /**
* *
@ -155,7 +155,7 @@ public class SessionRestController {
} }
sessionId = customSessionId; sessionId = customSessionId;
} else { } else {
sessionId = RandomStringGenerator.generateRandomChain(); sessionId = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
sessionManager.sessionidTokenTokenobj.putIfAbsent(sessionId, new ConcurrentHashMap<>()); sessionManager.sessionidTokenTokenobj.putIfAbsent(sessionId, new ConcurrentHashMap<>());
} }

View File

@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentMap;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.commons.lang3.RandomStringUtils;
import org.kurento.jsonrpc.DefaultJsonRpcHandler; import org.kurento.jsonrpc.DefaultJsonRpcHandler;
import org.kurento.jsonrpc.Session; import org.kurento.jsonrpc.Session;
import org.kurento.jsonrpc.Transaction; import org.kurento.jsonrpc.Transaction;
@ -52,7 +53,6 @@ import io.openvidu.server.core.SessionManager;
import io.openvidu.server.core.Token; import io.openvidu.server.core.Token;
import io.openvidu.server.utils.GeoLocation; import io.openvidu.server.utils.GeoLocation;
import io.openvidu.server.utils.GeoLocationByIp; import io.openvidu.server.utils.GeoLocationByIp;
import io.openvidu.server.utils.RandomStringGenerator;
public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> { public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
@ -231,7 +231,7 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
if (openviduConfig.isOpenViduSecret(secret)) { if (openviduConfig.isOpenViduSecret(secret)) {
sessionManager.newInsecureParticipant(participantPrivatetId); sessionManager.newInsecureParticipant(participantPrivatetId);
token = RandomStringGenerator.generateRandomChain(); token = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
if (recorder) { if (recorder) {
generateRecorderParticipant = true; generateRecorderParticipant = true;
} }

View File

@ -1,32 +0,0 @@
/*
* (C) Copyright 2017-2019 OpenVidu (https://openvidu.io/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.openvidu.server.utils;
import org.apache.commons.lang3.RandomStringUtils;
public class RandomStringGenerator {
public static String generateRandomChain() {
return RandomStringUtils.randomAlphanumeric(16).toLowerCase();
}
public static String generateRandomChain(int length) {
return RandomStringUtils.randomAlphanumeric(length).toLowerCase();
}
}