Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ifduyue opened this issue Jan 20, 2022 · 2 comments

Comments

@ifduyue
Copy link

ifduyue commented Jan 20, 2022

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
Copy link
Owner

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
Copy link
Author

ifduyue commented Feb 24, 2022

Hello,

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants