Похожие чаты

Thank you very much. Can i ask another question. Spring security uses

these for authentication:
-Authentication interface
-userDetails.UserDetails class
-userDetails.User class

But User and UserDetails only provides username and not more details about of logged in user.
I want to add some fields to logged in UserDetails such as ID and phone and etc.

I read a lot and see there is two way :
1. Create a UserBean Entity (corresponding to DB) and extends it from User or implements UserDetails.
And then create a service class that implements UserDetailsService and change loadByUsername method.

2. Create a custom Authentication class instead of security.core.Authentication
interface.

Which of these two way is better?

1 ответов

12 просмотров

I can't say for sure. Custom Authentication provider is for more advanced scenarios when you want to do something really extraordinary when checking auth requests. Personally, I would use the first option as it is more straightforward and ready-to-use, and I'm familiar with it. I don't know much of your requirements to say what's better. What I would do, if I were you, and have no clear understanding what to choose, what fits better to your system: try to implement first option, add all necessary custom fields to your user, follow online tutorials (there are plenty of them). It shouldn't take too much effort. And then based on the result (or right in the middle of the process) understand whether something more custom is needed. And very personal thing that I would do: I would read a good book dedicated to spring security first. That is exactly what is needed for me to fill that gap "understand the common way, but not sure what to do in special cases". I have that gap, so don't take most of my advices as a holy grail))

Похожие вопросы

Обсуждают сегодня

30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
16
Also, why can’t the community have a vote/ say when it comes to initiatives like buybacks. Isn’t the point of crypto decentralisation? Don’t we deserve input as long term supp...
👨🏽‍🦰
13
any reference of this implementation?
BitBuddha
29
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
14
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
13
Карта сайта