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 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 request
      response - HTTP response
      Returns:
      response entity with JSON challenge for client to begin proof-of-work
    • bytesToHex

      public static String bytesToHex(byte[] bytes)
      Encode bytes to hex string
      Parameters:
      bytes - bytes to encode
      Returns:
      hex string
    • calculateHash

      public static String calculateHash(String input, String algorithm) throws NoSuchAlgorithmException
      Calculate a hex string from a digest, given an input string
      Parameters:
      input - input string
      algorithm - algorithm key, eg. SHA-256
      Returns:
      Throws:
      NoSuchAlgorithmException
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface InitializingBean
      Throws:
      Exception