Advertisement
Guest User

Untitled

a guest
Sep 14th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  3. <display-name>Spring MVC Application</display-name>
  4. <servlet>
  5. <servlet-name>mvc-dispatcher</servlet-name>
  6. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  7. <load-on-startup>1</load-on-startup>
  8. </servlet>
  9. <servlet-mapping>
  10. <servlet-name>mvc-dispatcher</servlet-name>
  11. <url-pattern>/</url-pattern>
  12. </servlet-mapping>
  13. <listener>
  14. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  15. </listener>
  16. <context-param>
  17. <param-name>contextConfigLocation</param-name>
  18. <param-value>
  19. /WEB-INF/mvc-dispatcher-servlet.xml,
  20. /WEB-INF/spring-security.xml
  21. </param-value>
  22. </context-param>
  23. <filter>
  24. <filter-name>springSecurityFilterChain</filter-name>
  25. <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  26. </filter>
  27. <filter-mapping>
  28. <filter-name>springSecurityFilterChain</filter-name>
  29. <url-pattern>/*</url-pattern>
  30. </filter-mapping>
  31. </web-app>
  32.  
  33. <beans:beans xmlns="http://www.springframework.org/schema/security"
  34. xmlns:beans="http://www.springframework.org/schema/beans"
  35. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  36. xsi:schemaLocation="http://www.springframework.org/schema/beans
  37. http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
  38. http://www.springframework.org/schema/security
  39. http://www.springframework.org/schema/security/spring-security-4.0.xsd">
  40.  
  41. <!-- <http>
  42. <intercept-url pattern ="/welcome*" access="ROLE-USER"/>
  43. <http-basic/>
  44. </http> -->
  45.  
  46. <http>
  47. <intercept-url pattern ="/welcome*" access="ROLE_USER"/>
  48. <form-login/>
  49. <logout logout-success-url="/home"/>
  50. </http>
  51. <authentication-manager>
  52. <authentication-provider>
  53. <user-service>
  54. <user name="rahul" password="123" authorities="ROLE_USER"/>
  55. <user name="rohit" password="567" authorities="ROLE_USER"/>
  56. </user-service>
  57. </authentication-provider>
  58. </authentication-manager>
  59. </beans:beans>
  60.  
  61. <beans xmlns="http://www.springframework.org/schema/beans"
  62. xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
  63. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64. xsi:schemaLocation="
  65. http://www.springframework.org/schema/beans
  66. http://www.springframework.org/schema/beans/spring-beans.xsd
  67. http://www.springframework.org/schema/mvc
  68. http://www.springframework.org/schema/mvc/spring-mvc.xsd
  69. http://www.springframework.org/schema/context
  70. http://www.springframework.org/schema/context/spring-context.xsd">
  71. <context:component-scan base-package="com.springtraining.security.controller"/>
  72. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  73. <property name="prefix">
  74. <value>/WEB-INF/pages/</value>
  75. </property>
  76. <property name="suffix">
  77. <value>.jsp</value>
  78. </property>
  79. </bean>
  80. </beans>
  81.  
  82. package com.springtraining.security.controller;
  83.  
  84. import java.security.Principal;
  85.  
  86. import org.springframework.stereotype.Controller;
  87. import org.springframework.ui.ModelMap;
  88. import org.springframework.web.bind.annotation.RequestMapping;
  89. import org.springframework.web.bind.annotation.RequestMethod;
  90.  
  91. @Controller
  92. public class LoginController
  93. {
  94. public LoginController()
  95. {
  96. System.out.println("LoginController constructor is called ");
  97. }
  98. @RequestMapping(value="/welcome", method=RequestMethod.GET)
  99. public String printWelcome(ModelMap model,Principal principal)
  100. {
  101. System.out.println("**********Login Controller is Called********");
  102.  
  103. String name= principal.getName();
  104. model.addAttribute("username", name);
  105. model.addAttribute("message", "Spring Security Custom Form Example");
  106. return "hello";
  107. }
  108. @RequestMapping(value="/*",method=RequestMethod.GET)
  109. public String home(ModelMap model)
  110. {
  111.  
  112. return "home";
  113.  
  114. }
  115. @RequestMapping(value="/login",method=RequestMethod.GET)
  116. public String login(ModelMap model)
  117. {
  118. return "login";
  119. }
  120.  
  121. @RequestMapping(value="/test",method=RequestMethod.GET)
  122. public String test(ModelMap model)
  123. {
  124.  
  125. return "test";
  126.  
  127. }
  128. }
  129.  
  130. <%@ page language="java" contentType="text/html; charset=UTF-8"
  131. pageEncoding="UTF-8"%>
  132. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  133. <html>
  134. <head>
  135. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  136. <title>Insert title here</title>
  137. </head>
  138. <body>
  139. <h3>Welcome To Spring Security </h3>
  140. <a href="/SpringSecurity1-FORM/welcome"><b>Click here to logon</b></a>
  141.  
  142. </body>
  143. </html>
  144.  
  145. <%@ page language="java" contentType="text/html; charset=UTF-8"
  146. pageEncoding="UTF-8"%>
  147. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  148. <html>
  149. <head>
  150. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  151. <title>Insert title here</title>
  152. </head>
  153. <body>
  154. <h3>Message : ${message}</h3>
  155. <h3>Username : ${username}</h3>
  156. <a href="<c:url value="/j_spring_security_logout" />" >Logout</a>
  157. </body>
  158. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement