-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add course submission mode
- Loading branch information
Showing
7 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
modules/fbs-core/api/src/main/resources/migrations/23_course_submission_mode.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE course ADD COLUMN submission_mode ENUM('internet', 'vpn', 'local') NOT NULL DEFAULT 'internet'; | ||
|
||
INSERT INTO migration (number) VALUES (23); | ||
|
||
COMMIT; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
modules/fbs-core/api/src/main/scala/de/thm/ii/fbs/services/security/IpService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package de.thm.ii.fbs.services.security | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Component | ||
import org.springframework.security.web.util.matcher.IpAddressMatcher | ||
|
||
@Component | ||
class IpService { | ||
@Value("${services.ip.vpnCidrs}") private var vpnIpRangeString: String = "" | ||
@Value("${services.ip.localCidrs}") private var localIpRangeString: String = "" | ||
|
||
private def vpnIpRange: Seq[String] = vpnIpRangeString.split(",").filter(str => str.nonEmpty) | ||
private def localIpRange: Seq[String] = localIpRangeString.split(",").filter(str => str.nonEmpty) | ||
|
||
private def isInCidr(cidr: String, ip: String): Boolean = { | ||
new IpAddressMatcher(cidr).matches(ip) | ||
} | ||
|
||
private def ipInCidrs(cirds: Seq[String], ip: String): Boolean = | ||
cirds.exists(cidr => isInCidr(cidr, ip)) | ||
|
||
def isIpInZone(zone: String, ip: String): Boolean = | ||
zone match { | ||
case "internet" => true | ||
case "vpn" => ipInCidrs(vpnIpRange, ip) || ipInCidrs(localIpRange, ip) | ||
case "local" => ipInCidrs(localIpRange, ip) && !ipInCidrs(vpnIpRange, ip) | ||
} | ||
} |