fehnomenal / hashids-spring-boot-starter

Easily use Hashids with Spring Boot
MIT License
13 stars 4 forks source link

Permit only decoding hashids into integer, no converting from string to integer #4

Open ifduyue opened 2 years ago

ifduyue commented 2 years ago

Hello,

I was trying to use hashids-spring-boot-starter in a project in order to hide auto increment id from clients.

@GetMapping("/{id}")
@ResponseBody
public Order getOrder(@PathVariable("id") @Hashids Integer id) {
    return orderRepository.findById(id)
        .map(order -> order)
        .orElseThrow(() -> new RuntimeException("Order not found"));
}

Everything works, except that putting integer directly in the path still returns corresponding result. For example, Integer 1 was encoded into String geGprexD, both http://localhost:8080/1 and http://localhost:8080/geGprexD return the same result. How to permit only http://localhost:8080/geGprexD, and make http://localhost:8080/1 throw an exception?

fehnomenal commented 2 years ago

Hey, sorry as I moved away from Spring Boot I don't use this library anymore.

If I had the time to look into that I would research why Spring does not use the https://github.com/fehnomenal/hashids-spring-boot-starter/blob/680dff0045/src/main/java/systems/fehn/boot/starter/hashids/HashidsAnnotationFormatterFactory.java for int arguments. Please contribute if you find some results!

ifduyue commented 2 years ago

Hello,

Thanks for the reply. I am new to Java and I don't understand Java annotation code very well. But I'll try.