The purpose of writing this article is when i wanted to implement ACEGI authentication and authorization i did not got any solution.I tried hard with Spring forum for the solution but i got no response.In fact i was very new to this framework and finding very dificulty to understand.
I toiled hard to get the solution in fact i determined to get the solution thats why i got.
So i want all the new bie or even experienced people to get help from my post how to do ACEGI authentication and authorization so that they wont struggle like i did to get the solution.
First you have to know what is ACEGI
ACEGI is nothing but a security framework based on spring.
As far of my kowledge this framework provides security for web based and standalone application
So the requisite for this is first of all we have to do some configuration in web.xml
Which is as below.
Lets have some look for the for the tag in web.xml the first tag load a spring applicationContext file at the load up.
The second tag is basically a listener which enables any spring filter in web.xml with application Context Filter(Beans) here in our case is FilterChain Proxy
The final tag is for a basically filter which allows all the request to pass through this filter so that it can be captured by ACEGI framework.
Next step is lets create the login page for this
The code goes below
This code is little modification from original login page In this case i assume u are using some frame work like Struts or JSF/ADF for ur application if that is the case
just create a login page for ur application with frame work tages appart from this login page such that when u have filled the username and password and clicked on the Login Button it will hit the regular jsf/struts method from there u have to redirect it to this page which takes care of every thing remember one thing u dont have to any authentication in the method.It will take care by the spring context file which i will explain shortly.
Now lets write the applicationContext file and place it in the same path of web.xml
the code for the that is given below.
The above code explanation u can get from any tutorial
but i like to tell u some thing here very special abt jbdcDaoImp which really hit me hard the queryies which i have created for property 'usersByUsernameQuery'
is mandate for authenctication which u can map it to ur users table
but some think here needs to be remembered is that the username and password field in the table should be same as what i have mentioned and one more extra filed has to be included in the users table i'e enabled which is a boolean field.In the users table one thing needs to be taken care is that username should be the primary key.
Lastly u have to do one more thing is u have to create an extra table
Called authorites which is mandate
The Script of is i am giving below
Remember one thing this username in primary key in users table
Thats all u will now be able to do authenticaion with ACEGI
Happy coding
Thursday, October 11, 2007
Subscribe to:
Posts (Atom)