Package org.dspace.app.rest
Class AltchaCaptchaRestController
java.lang.Object
org.dspace.app.rest.AltchaCaptchaRestController
- All Implemented Interfaces:
InitializingBean
@RequestMapping("/api/captcha")
@RestController
public class AltchaCaptchaRestController
extends Object
implements InitializingBean
ALTCHA (Proof of Work, cookie-less) controller to handle challenge requests.
A salt, challenge hash will be sent and the client will have to calculate the number and send it back
to implementing controllers (e.g. request-a-copy) for validation.
The proof-of-work makes spam uneconomic, without requiring annoying puzzle tests or 3rd party services.
- Author:
- Kim Shepherd
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic StringbytesToHex(byte[] bytes) Encode bytes to hex stringstatic StringcalculateHash(String input, String algorithm) Calculate a hex string from a digest, given an input stringgetAltchaChallenge(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Calculate a challenge for ALTCHA captcha See https://altcha.org/docs/server-integration for implementation details and examples
-
Constructor Details
-
AltchaCaptchaRestController
public AltchaCaptchaRestController()
-
-
Method Details
-
getAltchaChallenge
@GetMapping("/challenge") @PreAuthorize("permitAll()") public ResponseEntity getAltchaChallenge(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Calculate a challenge for ALTCHA captcha See https://altcha.org/docs/server-integration for implementation details and examples- Parameters:
request- HTTP requestresponse- HTTP response- Returns:
- response entity with JSON challenge for client to begin proof-of-work
-
bytesToHex
Encode bytes to hex string- Parameters:
bytes- bytes to encode- Returns:
- hex string
-
calculateHash
Calculate a hex string from a digest, given an input string- Parameters:
input- input stringalgorithm- algorithm key, eg. SHA-256- Returns:
- Throws:
NoSuchAlgorithmException
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
Exception
-