-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/lavajuno/fsuvius
- Loading branch information
Showing
7 changed files
with
130 additions
and
25 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
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
20 changes: 20 additions & 0 deletions
20
src/main/java/org/jmeifert/fsuvius/error/ForbiddenAdvice.java
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,20 @@ | ||
package org.jmeifert.fsuvius.error; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
/** | ||
* ForbiddenAdvice provides responses to forbidden requests. | ||
*/ | ||
@ControllerAdvice | ||
public class ForbiddenAdvice { | ||
@ResponseBody | ||
@ExceptionHandler(ForbiddenException.class) | ||
@ResponseStatus(HttpStatus.FORBIDDEN) | ||
String forbiddenHandler(ForbiddenException e) { | ||
return e.getMessage(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/jmeifert/fsuvius/error/ForbiddenException.java
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,15 @@ | ||
package org.jmeifert.fsuvius.error; | ||
|
||
|
||
/** | ||
* A ForbiddenException is thrown when a request attempts to access or modify | ||
* resources it is not allowed to do so with. | ||
*/ | ||
public class ForbiddenException extends RuntimeException { | ||
/** | ||
* Throws a ForbiddenException. | ||
*/ | ||
public ForbiddenException() { | ||
super("Forbidden."); | ||
} | ||
} |
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,22 @@ | ||
package org.jmeifert.fsuvius.util; | ||
|
||
import org.jmeifert.fsuvius.FsuviusMap; | ||
|
||
/** | ||
* IPFilter provides functionality for checking IPs against a predefined allow-list. | ||
*/ | ||
public class IPFilter { | ||
/** | ||
* Checks an address to see if it is included in the allow-list. | ||
* @param ip The IP address to check | ||
* @return True if the address is included in the allow-list. | ||
*/ | ||
public static boolean checkAddress(String ip) { | ||
for(String k : FsuviusMap.ALLOWED_ADDR_PREFIXES) { | ||
if(ip.startsWith(k)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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