Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 一名学生只接受一个IP。但无法在本地网络spring boot web应用程序上运行_Java_Spring Boot_Web Applications_Ip - Fatal编程技术网

Java 一名学生只接受一个IP。但无法在本地网络spring boot web应用程序上运行

Java 一名学生只接受一个IP。但无法在本地网络spring boot web应用程序上运行,java,spring-boot,web-applications,ip,Java,Spring Boot,Web Applications,Ip,我正在为学生建立一个MCQ模块(在线MCQ模块)。所以在这里我遇到了一个问题,关于我已经确定一个学生作为一个设备。简单地说,一个学生拥有一台考试设备。但当涉及到本地网络时,由于子网和其他原因,它无法工作 请帮我解决这个问题。我应该做些什么来避免这个问题?我已经在这里提供了我的后端 回购类 @Repository public interface StudentExamRepository extends CrudRepository<StudentExam,Long> { @Qu

我正在为学生建立一个MCQ模块(在线MCQ模块)。所以在这里我遇到了一个问题,关于我已经确定一个学生作为一个设备。简单地说,一个学生拥有一台考试设备。但当涉及到本地网络时,由于子网和其他原因,它无法工作

请帮我解决这个问题。我应该做些什么来避免这个问题?我已经在这里提供了我的后端

回购类

@Repository
public interface StudentExamRepository extends 
CrudRepository<StudentExam,Long>
{

@Query(value = "select * from student_exam where exam_link_id = ?1 and 
(student_id = ?2 or attempted_ip = ?3)", nativeQuery = true)
List<StudentExam> findByExamLinkIdStudentIdAndIp( long examId, long 
studentId, String ip );
}
@存储库
公共接口StudentExamRepository扩展
积垢的
{
@查询(value=“select*from student\u test,其中test\u link\u id=?1和
(学生id=?2或ip=?3)”,nativeQuery=true)
列出FindByexamlinkIDStudentAndIP(长examId,长examId
学生ID,字符串ip);
}
服务等级

public Boolean hasStudentAttempted( long examLinkId, long studentId, String attemptedId )
{
  return studentExamRepository.findByExamLinkIdStudentIdAndIp( examLinkId, studentId, attemptedId ).size() != 0;
}

    @RequestMapping(method = RequestMethod.GET, value = "/allowed/hasStudentAttempted")
public ResponseEntity<Boolean> hasStudentAttempted( @RequestParam long examLinkId, @RequestParam long studentId, HttpServletRequest request )
{
    return new ResponseEntity<>( studentExamService.hasStudentAttempted( examLinkId, studentId, request.getRemoteAddr() ), HttpStatus.OK );
}
public Boolean hastudentAttempted(长examLinkId、长studentId、字符串attemptedId)
{
返回studentExamRepository.findByExamLinkIdStudentIdAndIp(examLinkId,studentId,attemptedId).size()!=0;
}
@RequestMapping(method=RequestMethod.GET,value=“/allowed/hastudentAttempted”)
已尝试公共响应(@RequestParam long examLinkId、@RequestParam long studentId、HttpServletRequest)
{
返回新的响应属性(studentExamService.hastudentAttempted(examLinkId,studentId,request.getRemoteAddr()),HttpStatus.OK);
}
控制器类

@RequestMapping(method = RequestMethod.GET, value = "/allowed/hasStudentAttempted")
public ResponseEntity<Boolean> hasStudentAttempted( @RequestParam long examLinkId, @RequestParam long studentId, HttpServletRequest request )
{
    return new ResponseEntity<>( studentExamService.hasStudentAttempted( examLinkId, studentId, request.getRemoteAddr() ), HttpStatus.OK );
}
@RequestMapping(method=RequestMethod.GET,value=“/allowed/hastudentattempted”)
已尝试公共响应(@RequestParam long examLinkId、@RequestParam long studentId、HttpServletRequest)
{
返回新的响应属性(studentExamService.hastudentAttempted(examLinkId,studentId,request.getRemoteAddr()),HttpStatus.OK);
}

IP地址由DHCP服务器动态分配,笔记本电脑将根据其所在位置连接到不同的DHCP服务器,因此IP地址和学生之间没有固定的关系。DHCP服务器甚至可以在任意时间重新分配和重新使用IP地址,因此IP可能突然变成另一个学生。你的设计是有缺陷的,因为它建立在IP=Student的错误假设之上。这就是为什么人们需要登录来识别自己。这就是为什么你需要JWT令牌来唯一地识别每个用户检查这些链接以实现JWT。。