mirror of https://github.com/OpenVidu/openvidu.git
Fixes for previouscommit suggestions
parent
eefef0f89e
commit
6769075de2
|
@ -36,7 +36,9 @@ public class OpenViduException extends RuntimeException {
|
||||||
|
|
||||||
USER_NOT_STREAMING_ERROR_CODE(105), EXISTING_USER_IN_ROOM_ERROR_CODE(
|
USER_NOT_STREAMING_ERROR_CODE(105), EXISTING_USER_IN_ROOM_ERROR_CODE(
|
||||||
104), USER_CLOSED_ERROR_CODE(
|
104), USER_CLOSED_ERROR_CODE(
|
||||||
103), USER_NOT_FOUND_ERROR_CODE(102), USER_GENERIC_ERROR_CODE(101);
|
103), USER_NOT_FOUND_ERROR_CODE(102), USER_GENERIC_ERROR_CODE(101),
|
||||||
|
|
||||||
|
USER_UNAUTHORIZED(401);
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.openvidu.server.core.api.pojo.ParticipantRequest;
|
||||||
import org.openvidu.server.core.api.pojo.UserParticipant;
|
import org.openvidu.server.core.api.pojo.UserParticipant;
|
||||||
import org.openvidu.server.core.internal.DefaultKurentoClientSessionInfo;
|
import org.openvidu.server.core.internal.DefaultKurentoClientSessionInfo;
|
||||||
import org.openvidu.server.core.internal.DefaultNotificationRoomHandler;
|
import org.openvidu.server.core.internal.DefaultNotificationRoomHandler;
|
||||||
import org.openvidu.server.security.ParticipantRoles;
|
import org.openvidu.server.security.ParticipantRole;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -454,7 +454,7 @@ public class NotificationRoomManager {
|
||||||
return this.internalManager.newSessionId();
|
return this.internalManager.newSessionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String newToken(String sessionId, ParticipantRoles role){
|
public String newToken(String sessionId, ParticipantRole role){
|
||||||
return this.internalManager.newToken(sessionId, role);
|
return this.internalManager.newToken(sessionId, role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.openvidu.server.core.api.pojo.UserParticipant;
|
||||||
import org.openvidu.server.core.endpoint.SdpType;
|
import org.openvidu.server.core.endpoint.SdpType;
|
||||||
import org.openvidu.server.core.internal.Participant;
|
import org.openvidu.server.core.internal.Participant;
|
||||||
import org.openvidu.server.core.internal.Room;
|
import org.openvidu.server.core.internal.Room;
|
||||||
import org.openvidu.server.security.ParticipantRoles;
|
import org.openvidu.server.security.ParticipantRole;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class RoomManager {
|
||||||
|
|
||||||
private final ConcurrentMap<String, Room> rooms = new ConcurrentHashMap<String, Room>();
|
private final ConcurrentMap<String, Room> rooms = new ConcurrentHashMap<String, Room>();
|
||||||
|
|
||||||
private final ConcurrentMap<String, ConcurrentHashMap<String, ParticipantRoles>> sessionIdTokenRole = new ConcurrentHashMap<>();
|
private final ConcurrentMap<String, ConcurrentHashMap<String, ParticipantRole>> sessionIdTokenRole = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
|
||||||
private volatile boolean closed = false;
|
private volatile boolean closed = false;
|
||||||
|
@ -938,7 +938,7 @@ public class RoomManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPublisherInRoom(String participantName, String roomName) {
|
public boolean isPublisherInRoom(String participantName, String roomName) {
|
||||||
return this.sessionIdTokenRole.get(roomName).get(participantName).equals(ParticipantRoles.PUBLISHER);
|
return this.sessionIdTokenRole.get(roomName).get(participantName).equals(ParticipantRole.PUBLISHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String newSessionId(){
|
public String newSessionId(){
|
||||||
|
@ -951,7 +951,7 @@ public class RoomManager {
|
||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String newToken(String sessionId, ParticipantRoles role){
|
public String newToken(String sessionId, ParticipantRole role){
|
||||||
if (this.sessionIdTokenRole.get(sessionId) != null) {
|
if (this.sessionIdTokenRole.get(sessionId) != null) {
|
||||||
String token = new BigInteger(130, new SecureRandom()).toString(32);
|
String token = new BigInteger(130, new SecureRandom()).toString(32);
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,13 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.openvidu.server.core.NotificationRoomManager;
|
import org.openvidu.server.core.NotificationRoomManager;
|
||||||
import org.openvidu.server.security.ParticipantRoles;
|
import org.openvidu.server.security.ParticipantRole;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,16 +59,16 @@ public class RoomController {
|
||||||
return Integer.valueOf(getProperty("thresholdSpeaker", THRESHOLD_SPEAKER_DEFAULT));
|
return Integer.valueOf(getProperty("thresholdSpeaker", THRESHOLD_SPEAKER_DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/getSessionId")
|
@RequestMapping(value = "/getSessionId", method = RequestMethod.GET)
|
||||||
public ResponseEntity<String> getSessionId() {
|
public ResponseEntity<String> getSessionId() {
|
||||||
String sessionId = roomManager.newSessionId();
|
String sessionId = roomManager.newSessionId();
|
||||||
return new ResponseEntity<String>(sessionId, HttpStatus.OK);
|
return new ResponseEntity<String>(sessionId, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/getToken")
|
@RequestMapping(value = "/newToken", method = RequestMethod.POST)
|
||||||
public ResponseEntity<String> getToken(@RequestBody Map sessionIdAndRole) {
|
public ResponseEntity<String> getToken(@RequestBody Map sessionIdAndRole) {
|
||||||
System.out.println("SESSIONID: " + sessionIdAndRole.get("0") + " - ROLE: " + sessionIdAndRole.get("1"));
|
System.out.println("SESSIONID: " + sessionIdAndRole.get("0") + " - ROLE: " + sessionIdAndRole.get("1"));
|
||||||
String token = roomManager.newToken((String) sessionIdAndRole.get("0"), ParticipantRoles.valueOf((String) sessionIdAndRole.get("1")));
|
String token = roomManager.newToken((String) sessionIdAndRole.get("0"), ParticipantRole.valueOf((String) sessionIdAndRole.get("1")));
|
||||||
return new ResponseEntity<String>(token, HttpStatus.OK);
|
return new ResponseEntity<String>(token, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class JsonRpcUserControl {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("Error: sessionId or token not valid");
|
System.out.println("Error: sessionId or token not valid");
|
||||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE,
|
throw new OpenViduException(Code.USER_UNAUTHORIZED,
|
||||||
"Unable to join room. The user does not have a valid token");
|
"Unable to join room. The user does not have a valid token");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public class JsonRpcUserControl {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("Error: user is not a publisher");
|
System.out.println("Error: user is not a publisher");
|
||||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE,
|
throw new OpenViduException(Code.USER_UNAUTHORIZED,
|
||||||
"Unable to join room. The user does not have a valid token");
|
"Unable to join room. The user does not have a valid token");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.openvidu.server.security;
|
package org.openvidu.server.security;
|
||||||
|
|
||||||
public enum ParticipantRoles {
|
public enum ParticipantRole {
|
||||||
SUBSCRIBER,
|
SUBSCRIBER,
|
||||||
PUBLISHER,
|
PUBLISHER,
|
||||||
MODERATOR;
|
MODERATOR;
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* (C) Copyright 2014 Kurento (http://kurento.org/)
|
|
||||||
*
|
|
||||||
* 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 org.openvidu.server.security;
|
|
||||||
|
|
||||||
import org.kurento.client.MediaPipeline;
|
|
||||||
import org.openvidu.client.OpenViduException;
|
|
||||||
import org.openvidu.client.OpenViduException.Code;
|
|
||||||
import org.openvidu.server.core.internal.Participant;
|
|
||||||
import org.openvidu.server.core.internal.Room;
|
|
||||||
|
|
||||||
public class ParticipantSecurity extends Participant{
|
|
||||||
|
|
||||||
ParticipantRoles role;
|
|
||||||
|
|
||||||
public ParticipantSecurity(String id, String name, String role, Room room, MediaPipeline pipeline, boolean dataChannels,
|
|
||||||
boolean web) {
|
|
||||||
super(id, name, room, pipeline, dataChannels, web);
|
|
||||||
|
|
||||||
this.role = ParticipantRoles.valueOf(role);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createPublishingEndpoint() {
|
|
||||||
if (this.isPublisher()){
|
|
||||||
super.createPublishingEndpoint();
|
|
||||||
} else {
|
|
||||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE,
|
|
||||||
"Unable to create publisher endpoint");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isPublisher(){
|
|
||||||
return (this.role.equals(ParticipantRoles.PUBLISHER) ||
|
|
||||||
this.role.equals(ParticipantRoles.MODERATOR));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -35,7 +35,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
protected void configureUrlAuthorization(HttpSecurity http) throws Exception {
|
protected void configureUrlAuthorization(HttpSecurity http) throws Exception {
|
||||||
http.csrf().disable()
|
http.csrf().disable()
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers(HttpMethod.POST, "/getSessionId").authenticated()
|
.antMatchers(HttpMethod.GET, "/getSessionId").authenticated()
|
||||||
.antMatchers(HttpMethod.POST, "/getToken").authenticated()
|
.antMatchers(HttpMethod.POST, "/getToken").authenticated()
|
||||||
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
|
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue