In the previous video, we have created a database in the cloud and inside that database, we have created
a couple of tables, which is users and authorities, and we also insert the user details like the user
name is happy.
And this password along with his authorities, which is it right now?
Let's try to leverage the user details manager to connect to this database and do authentication of
the user based upon the details that we are maintaining in the database.
For that, let's go to our code.
Very first thing that you have to do inside a project is you have to add the dependencies related to
my school databases inside your.
Com.
So far that I have added these dependencies.
One is Springboard Starter, A.B.C. and MySQL, Connector, Java and Springboard Starter, that AJP
which will be using in the next coming radius.
I have also added a couple of dependencies related to a lab.
The reason is in the previous video I was showing the code inside a lab user details manager.
In order to see that class, you should have dependencies mentioned in the Pumbaa.
I missed mentioning this point in the previous video.
That's why I'm stressing here again, if we want to check inside the code of lab user details manager,
make sure you are adding these dependencies.
And also we should add dependencies related to data masculine data AJP in order to connect to your database.
Once we are added, these dependencies inside are undertaxing, will go to application DOT properties
and give you a database detailed.
Using these properties like the You Are the springboard application has to try to connect to connect
to the database.
So you should hojjati this in my school or that you should mention the hostname that we have seen in
the database, followed by the database name that we have created.
We have created it easy bank database inside our school database server.
So that's where I have mentioned that.
And at the same time, what is a username and password?
Obviously this is one of the ways to connect database.
And there are many ways if you are using a production or the application where you encrypt these details
and are adding to environmental variables to database.
But since this is focused on spring security, I'm just going then simple approach where we directly
mention all our credentials and details inside our application properties.
But this is not the commander.
If we are trying to do this in the production or the application to post this spring, what application
or database it has to connect.
Now let's go to Project Security Config.
So previously we are using in memory user details manager and in-memory user details.
Manager is only useful in the scenarios where you want to demo something on your application is fine
to how to store the user details inside.
But in memory, the disadvantage of saving the details inside the memory is whenever you make changes
to your user and you are restarting your server, the memory will act like a flash and volatile and
whatever you have, initial values will be reset to those values after the start of the application.
That's where if you don't want to affect the user, details change again and again.
Whenever the restart happens, then it's always advisable to go with the user details manage the fact
that I'm just going to come in this macur, for your reference, and now I don't have to create a user
because I already have users created in the database.
So in this scenario, I don't need all these things like creating end user setting that to use a detailed
service and passing that the user interface to the framework.
In this scenario, I just have to mention my framework.
I am going to use JDA User Details Manager as my implementation offspring security.
Go ahead and leverage that class to do authentication and authorizes.
For that we just have to create a user detailed service being and framework automatically identifies.
OK, this is a user detail service that I have to use and here we are telling we implement that user
detail service by leveraging user details manager.
So for that we also have to pass the data source.
And don't worry, this data source will be created by spring security based upon the credentials that
we have given inside the application that properties with this we are good.
Go use our database values for authentication.
But you may be wondering how this is working all Internet, if you go and see a user details manager,
our framework will call law users money, user name, whatever, entering in the way that user name
will come here and my GBC query will happen to the table.
So if you say this is the query category you use to select the user details is the idea that we can
select username password enabled from the table users.
So since we want to go with the default implementation, we adhere to these standards and use the and
created the table the same name, along with the same column names in the database.
But now we are good to go and use this.
Now let's try to start this over in debug more by going to the main application class and clicking Debuggers
Java application and this will start the application.
Now, this time I will put a breakpoint inside the method nor user by user name here so that I will
show that framework calls this matter like in the previous video where we have seen that framework is
calling for user by user name inside the memory user details manager.
The reason is at that time we have mentioned user data service that we want to configure is in memory
user details manager.
But this time we said to the framework, go ahead and use the GBC user details manager.
That is the reason framework will call this method inside the user details, Manisha.
Now we have everything set and ready.
Let's go to the browser in the browser to access the my account, which it will ask you the credentials.
Now, let me enter the previous screenshots that we used to maintain in memory.
So I'm just entering one, two, three, four, five.
So it will throw at credentialled.
Now, I will enter the correct credentials which are in the database here.
I'm saying happy.
One, two, three, four, five.
As a credential.
Not sitting on this will stop my breakpoint because now this query resulting some rows.
That's the reason we stopped at this point.
And you can see here, this will be called by the hour Davo authentication provider Retriever's.
So here it will go.
And look, what is the implementation of user detail service?
And we said that go ahead and use JBC user details manager by creating a bit of user detail service.
So that's the reason are the authentication provider will call the Jadick user details manager Materne
and will try to authenticate.
So now in this scenario is that authentication is successful.
We are showing the response provided by the my account service with this.
I'm assuming it is making sense to you guys.
If we have any questions, please post in Q&A section and in the next video, let's try to how to customize
this database, see user details, manager asport requirements.
Like I want to have my own table.
I want to have my own aluminum's as per my position requirement.
I don't want to go with what our naming conventions that is provided by JBC User Details Manager.
So all such requirements.
We will look in the next room.
Thank you.
By.