Fixes for previouscommit suggestions

pull/3/head
pabloFuente 2017-04-03 18:11:15 +02:00
parent eefef0f89e
commit 6769075de2
8 changed files with 18 additions and 66 deletions

View File

@ -36,7 +36,9 @@ public class OpenViduException extends RuntimeException {
USER_NOT_STREAMING_ERROR_CODE(105), EXISTING_USER_IN_ROOM_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;

View File

@ -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.internal.DefaultKurentoClientSessionInfo;
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.LoggerFactory;
@ -454,7 +454,7 @@ public class NotificationRoomManager {
return this.internalManager.newSessionId();
}
public String newToken(String sessionId, ParticipantRoles role){
public String newToken(String sessionId, ParticipantRole role){
return this.internalManager.newToken(sessionId, role);
}
}

View File

@ -45,7 +45,7 @@ import org.openvidu.server.core.api.pojo.UserParticipant;
import org.openvidu.server.core.endpoint.SdpType;
import org.openvidu.server.core.internal.Participant;
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.LoggerFactory;
@ -67,7 +67,7 @@ public class RoomManager {
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;
@ -938,7 +938,7 @@ public class RoomManager {
}
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(){
@ -951,7 +951,7 @@ public class RoomManager {
return sessionId;
}
public String newToken(String sessionId, ParticipantRoles role){
public String newToken(String sessionId, ParticipantRole role){
if (this.sessionIdTokenRole.get(sessionId) != null) {
String token = new BigInteger(130, new SecureRandom()).toString(32);

View File

@ -22,12 +22,13 @@ import java.util.Map;
import java.util.Set;
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.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
@ -58,16 +59,16 @@ public class RoomController {
return Integer.valueOf(getProperty("thresholdSpeaker", THRESHOLD_SPEAKER_DEFAULT));
}
@RequestMapping("/getSessionId")
@RequestMapping(value = "/getSessionId", method = RequestMethod.GET)
public ResponseEntity<String> getSessionId() {
String sessionId = roomManager.newSessionId();
return new ResponseEntity<String>(sessionId, HttpStatus.OK);
}
@RequestMapping("/getToken")
@RequestMapping(value = "/newToken", method = RequestMethod.POST)
public ResponseEntity<String> getToken(@RequestBody Map sessionIdAndRole) {
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);
}
}

View File

@ -74,7 +74,7 @@ public class JsonRpcUserControl {
}
else {
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");
}
}
@ -95,7 +95,7 @@ public class JsonRpcUserControl {
}
else {
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");
}
}

View File

@ -1,6 +1,6 @@
package org.openvidu.server.security;
public enum ParticipantRoles {
public enum ParticipantRole {
SUBSCRIBER,
PUBLISHER,
MODERATOR;

View File

@ -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));
}
}

View File

@ -35,7 +35,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
protected void configureUrlAuthorization(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/getSessionId").authenticated()
.antMatchers(HttpMethod.GET, "/getSessionId").authenticated()
.antMatchers(HttpMethod.POST, "/getToken").authenticated()
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}