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

48 comments:

  1. 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.

    ReplyDelete
  2. 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

    ReplyDelete
  3. 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





    ReplyDelete
  4. 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


    ReplyDelete
  5. 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

    ReplyDelete
  6. 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

    ReplyDelete
  7. 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

    ReplyDelete
  8. 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

    ReplyDelete
  9. 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

    ReplyDelete
  10. 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

    ReplyDelete
  11. 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

    ReplyDelete
  12. 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

    ReplyDelete
  13. 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

    ReplyDelete
  14. 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

    ReplyDelete
  15. 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

    ReplyDelete
  16. 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

    ReplyDelete
  17. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  18. Nice blog, good post, informative and helpful post and you are obviously very knowledgeable in this field. Very useful and solid content. Thanks for sharing


    ExcelR Data Science in Bangalore

    ReplyDelete
  19. It’s very informative and you are obviously very knowledgeable in this area. You have opened my eyes to varying views on this topic with interesting and solid content.
    date analytics certification training courses
    data science courses training

    ReplyDelete
  20. You know your projects stand out of the herd. There is something special about them. It seems to me all of them are really brilliant!
    machine learning course malaysia

    ReplyDelete

  21. I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more.

    Data Science Course

    ReplyDelete
  22. I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.



    data science course malaysia

    ReplyDelete
  23. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!digital marketing course in singapore

    ReplyDelete
  24. So luck to come across your excellent blog. Your blog brings me a great deal of fun.. Good luck with the site.
    pmp certification malaysia

    ReplyDelete
  25. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.

    digital marketing courses mumbai

    ReplyDelete
  26. Unlike data science, machine learning is a set of techniques that allow computers to make decisions based on the given data. machine learning courses in hyderabad

    ReplyDelete

  27. Nice article and thanks for sharing with us. Its very informative





    AI Training in Hyderabad

    ReplyDelete
  28. I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon…
    machine learning courses in bangalore

    ReplyDelete
  29. I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more.
    data scientist training and placement

    ReplyDelete
  30. Wonderful blog post. This is absolute magic from you! I have never seen a more wonderful post than this one. You've really made my day today with this. I hope you keep this up!
    data scientist training and placement in hyderabad

    ReplyDelete
  31. Nice blog. I finally found great post here Very interesting to read this article and very pleased to find this site. Great work!
    Data Science Training in Hyderabad
    Data Science Course in Hyderabad

    ReplyDelete
  32. It is imperative that we read blog post very carefully. I am already done it and find that this post is really amazing. data science course in surat

    ReplyDelete
  33. Informative blog and knowledgeable content. Keep posting more blogs with us.
    Data Science Training Institute in Hyderabad

    ReplyDelete
  34. Excellent post. Thank you for providing such an informative blog.

    SkillUp Online provides Courses like Artificial Intelligence CoursesPython for Data Science CourseCloud Computing CoursesIBM coursesCybersecurity ProgramPower BI CertificationMicrosoft Azure Architect DesignGoogle Cloud Architect Certification and so on. To learn more about SkillUp Online IT certifications online Courses visit our website.

    ReplyDelete