r/javahelp • • 16h ago

I want to create a secure link wiht java (Spring)

Hello, I need to create a secure link to send to a user, but I am unsure how to implement this or what terminology to use for my research. Could someone provide recommendations, tools, or specific concepts I should look into?

1 Upvotes

5 comments sorted by

1

u/AutoModerator 16h ago
Moderator Announcement Read More »

1

u/bikeram 16h ago

You need to get up to speed with spring security (this could take a month without AI)

Basically everything that isn’t public is protected.

Then you can create a get endpoint /user/{userRandomUUID} where that uuid is pulled from the database referencing whatever you want.

You’ll want per user protection and admins automatically get a grant too (probably)

1

u/Plenty-Evidence3147 4h ago

what exactly does the link need to do

1

u/Far-Bullfrog161 36m ago

The usual terms to search for are "magic link", "one-time token" or "signed URL", and it works the same way as a password reset link. Generate a long random token with SecureRandom (32 bytes, Base64 URL-encoded), store only a hash of it in your database along with the user or resource it belongs to, an expiry time and a used flag, and put the raw token in the link. When the link is opened, hash the incoming token, look it up, check it has not expired or been used, then mark it used and do whatever the link is meant to do. Always send it over HTTPS, keep the lifetime short, and never put anything sensitive in the URL itself. The alternative is a stateless signed token such as a JWT or an HMAC over the payload plus expiry, which avoids a database table but makes single-use and revocation harder. In Spring you would expose this as a normal controller endpoint and permit just that path in your Spring Security config, while the token check itself decides who gets in.