Monday, October 8, 2012

Spring MVC, Security + Hibernate + DWR - Page 4



Spring MVC, Security + Hibernate + DWR, Let's PLay

OK, let's secure it ;)

The Spring security filter and Spring configuration:

in you web.xml edit the line to add a new file called spring-security.xml
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/dwr-context.xml,/WEB-INF/hibernate-context.xml,/WEB-INF/spring-security.xml</param-value>
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>
            org.springframework.web.filter.DelegatingFilterProxy
    </filter-class>
</filter>
<filter-mapping>
	<filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Filter Order

as we are now having two filters (springSecurityFilterChain and OpenSessionInViewFilter) we need to set the filter order as, 1-security 2-Hibernate.
make sure you filter order look like this
<filter-mapping>
	<filter-name>springSecurityFilterChain</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
	<filter-name>hibernateFilter</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>

spring-security.xml

this file will configure spring security, we will use form authentication, the users will be configured using this file too.
<beans:beans xmlns="http://www.springframework.org/schema/security"
	xmlns:beans="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/security
	http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
 
	<http auto-config="true">
		<intercept-url pattern="/*" access="ROLE_USER" />
	</http>
 
	<authentication-manager>
	  <authentication-provider>
	    <user-service>
		<user name="mtz" password="123" authorities="ROLE_USER" />
	    </user-service>
	  </authentication-provider>
	</authentication-manager>
 
</beans:beans>
the idea here is that we are securing every URL, with:
username:mtz
password:123

Test it

deploy the project and you should see the following page
and you are done, thanks :)
download the full example

27 comments:

MooseyMersa said...

Thank you for a great tutorial. Took quite a while for me to get it to work, but this was more to do with running MySql on a non-default port (to do this you need to use a later version of the mysql-connector than provided in the download/repository and place it in a web-inf/lib folder).
In addition to make the logging work properly (to help solve the above problem) I needed to put the logging.properties and log4j.properties files in a web-inf/classes folder.

prathap kumar said...

Great Article

Hibernate Training
Hibernate Online Training
Hibernate Training Courses
Java J2EE Training Institutes in Chennai
Java Training in Chennai

Java Training




Hibernate Dialect
Hibernate Interview Questions

Nikshitha S said...

Hibernate is the most popular framework for java environments which is based on the object relational mapping.
hibernate training in chennai | hibernate training

John Alert said...

Hibernate Online Training Hibernate Online Training Hibernate Training in Chennai Hibernate Training in Chennai Java Online Training Java Online Training Hibernate Training Institutes in ChennaiHibernate Training Institutes in Chennai

John Alert said...

Great step by step solution, thanks for the help!

Spring Hibernate Online Training | Hibernate Training in Chennai Java Training Institutes


Hibernate Online Training | Java Online Training | Java EE Online Training

sunitha vishnu said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
Android Training in Chennai
Ios Training in Chennai

unknown said...

we will go through the Spring Security setup & common features, when and where to apply, different authentication methods, securing password with encoding schemes, & integrating Spring Security in Spring MVC 4 and Hibernate based applications, exploring them with help of fully-working examples.spring security training in chennai

Mahesh said...

This is an awesome post. Really very informative and creative contents. This concept is a good way to enhance the knowledge.Like it and help me to development very well. Thank you for this brief explanation and very nice information. Well got good knowledge.
Java Training in Gurgaon





vijay antony said...

Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

Best Java Training Institute Chennai


Java Training Institute Bangalore


mithra R said...

Thanks for sharing a great thing.I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here.
uipath training in bangalore

subha a said...

I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
Best selenium training Institute in chennai

owen morris said...

Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

DevOps Training in Bangalore

gowsalya said...

Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. You clearly know what you are working on, youve insured so many corners.thanks
Digital Marketing Training in Chennai

Digital Marketing Training in Bangalore

digital marketing training in tambaram

digital marketing training in annanagar

johnsy sai said...

Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
Digital Marketing online training

full stack developer training in pune

full stack developer training in annanagar

full stack developer training in tambaram

pooja saravanan said...

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
Hadoop Training in Chennai

Hadoop Training in Bangalore

Big data training in tambaram

Big data training in Sholinganallur

Big data training in annanagar

Big data training in Velachery

Big data training in Marathahalli

Anexas Europe said...


It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.

Digital Marketing Training in Mumbai

Six Sigma Training in Dubai

Six Sigma Abu Dhabi

sai said...

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
python training institute in chennai
python training in Bangalore
python training in pune

johnsy sai said...

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
Devops Training in Chennai

Devops Training in Bangalore

Devops Training in pune

amala jst said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

rpa training in Chennai

rpa training in anna nagar | rpa training in marathahalli

rpa training in btm | rpa training in kalyan nagar

rpa training in electronic city | rpa training in chennai

rpa online training | selenium training in training

Mouni yoga said...

I likable the posts and offbeat format you've got here! I’d wish many thanks for sharing your expertise and also the time it took to post!!
python training in OMR
python training in chennai

Nila shri said...

Wow, it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and I got more information from your blog.

Data Science training in Chennai
Data science training in bangalore
Data science online training
Data science training in pune

Unknown said...

Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
java online training | java training in pune

java training in chennai | java training in bangalore

Anexas Europe said...

Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
Good discussion. Thank you.
Anexas
Six Sigma Training in Abu Dhabi
Six Sigma Training in Dammam
Six Sigma Training in Riyadh

Rohil singh said...

Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
Good discussion. Thank you.
Anexas
Six Sigma Training in Abu Dhabi
Six Sigma Training in Dammam
Six Sigma Training in Riyadh

simbu said...

Read all the information that i've given in above article. It'll give u the whole idea about it.

java training in chennai | java training in bangalore

java online training | java training in pune

nivatha said...

After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.

Data science course in tambaram | Data Science course in anna nagar
Data Science course in chennai | Data science course in Bangalore
Data Science course in marathahalli | Data Science course in btm

Revathy A said...

Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
angularjs-Training in pune

angularjs-Training in chennai

angularjs Training in chennai

angularjs-Training in tambaram

angularjs-Training in sholinganallur