Guest User

Untitled

a guest
Jul 31st, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.45 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.     xmlns:security="http://www.springframework.org/schema/security"
  5.  xsi:schemaLocation="http://www.springframework.org/schema/beans
  6.      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  7.   http://www.springframework.org/schema/security
  8.   http://www.springframework.org/schema/security/spring-security-3.1.xsd">
  9.  
  10.  <!-- This is where we configure Spring-Security  -->
  11.  <security:http auto-config="true" use-expressions="true" access-denied-page="/loginfail" >
  12.  
  13.   <security:intercept-url pattern="/login**" access="permitAll"/>
  14. <!--  <security:intercept-url pattern="/krams/main/admin" access="hasRole('ROLE_ADMIN')"/>-->
  15.   <security:intercept-url pattern="/tem/*" access="hasRole('ROLE_USER')"/>
  16.  
  17.    
  18.   <security:form-login
  19.     login-page="/login"
  20.     authentication-failure-url="/loginfail?error=true"
  21.     default-target-url="/index"/>
  22.    
  23.   <security:logout
  24.     invalidate-session="true"
  25.     logout-success-url="/logout"
  26.     logout-url="/logout"/>
  27.  
  28.  </security:http>
  29.  
  30.  <!-- Declare an authentication-manager to use a custom userDetailsService -->
  31.  <security:authentication-manager>
  32.          <security:authentication-provider user-service-ref="customUserDetailsService">
  33.   <!--         <security:password-encoder ref="passwordEncoder"/>-->
  34.          </security:authentication-provider>
  35.  </security:authentication-manager>
  36.  
  37.  <!-- Use a Md5 encoder since the user's passwords are stored as Md5 in the database
  38. <bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/>
  39. -->
  40. <!-- A custom service where Spring will retrieve users and their corresponding access levels  -->
  41. <bean id="customUserDetailsService" class="web.service.common.CustomUserDetailsService"/>
  42.  
  43.  
  44.            
  45.  
  46.  
  47. </beans>
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. ==================
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. <?xml version="1.0" encoding="UTF-8"?>
  66. <beans xmlns="http://www.springframework.org/schema/beans"
  67.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  68.  xmlns:mvc="http://www.springframework.org/schema/mvc"
  69.  xmlns:context="http://www.springframework.org/schema/context"
  70.  xmlns:tx="http://www.springframework.org/schema/tx"
  71.  xsi:schemaLocation="
  72.        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
  73.        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  74.        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
  75.        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"
  76. >
  77.  
  78.    
  79.    <context:component-scan base-package="web" >
  80.     <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"       />
  81.         <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"    />
  82.    </context:component-scan>
  83.  <mvc:annotation-driven />
  84. <!--  <context:annotation-config />-->
  85.    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
  86.  
  87.    <!--
  88.    Most controllers will use the ControllerClassNameHandlerMapping above, but
  89.    for the index controller we are using ParameterizableViewController, so we must
  90.    define an explicit mapping for it.
  91.    -->
  92.    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  93.        <property name="mappings">
  94.            <props>
  95.                <prop key="index.htm">indexController</prop>
  96.            </props>
  97.        </property>
  98.    </bean>
  99.  
  100.    <bean id="viewResolver"
  101.                class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  102. <!--          class="org.springframework.web.servlet.view.InternalResourceViewResolver">-->
  103.        
  104. <!--             class="org.springframework.web.servlet.view.UrlBasedViewResolver" >-->
  105.          <property name="prefix" value="/WEB-INF/view/jsp/" />
  106.            <property name="suffix" value=".jsp" />
  107.    </bean>        
  108.  
  109.    <!--
  110.    The index controller.
  111.    -->
  112.    <bean name="indexController"
  113.          class="org.springframework.web.servlet.mvc.ParameterizableViewController">
  114.          <property name="viewName" value="index" />
  115.    </bean>
  116.    
  117.    
  118.    
  119.     <!---
  120.     ##########################################################################
  121.    Hibernate
  122.    
  123.    -->
  124. <!--    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  125.        <property name="driverClassName" value="org.postgresql.Driver" />
  126.        <property name="url" value="${jdbc.url}jdbc:postgresql://localhost:5432/postgres" />
  127.        <property name="username" value="postgres" />
  128.        <property name="password" value="abc" />
  129.    </bean>
  130.  
  131.    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  132.        <property name="dataSource" ref="dataSource"/>
  133.        <property name="packagesToScan" value="web.entity" />
  134.        </property>
  135.        <property name="hibernateProperties">
  136.            <props>
  137.                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
  138.                <prop key="hibernate.show_sql">true</prop>
  139.                <prop key="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</prop>
  140.            </props>
  141.  
  142.        </property>
  143.    </bean>
  144.  
  145.    <tx:annotation-driven transaction-manager="transactionManager"/>
  146.  
  147.    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  148.        <property name="sessionFactory" ref="sessionFactory"/>
  149.    </bean>
  150.    
  151.    ###########################################################
  152.    -->
  153.  
  154.    
  155. <!--
  156.  
  157.    JPA based instead of hibernate
  158.    
  159. -->
  160.        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
  161. <!--
  162.         This configures the EntityManagerFactory object used for JPA/Spring managed persistent objects.
  163.      -->
  164.     <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  165.         <property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
  166.         <property name="persistenceUnitName" value="persistence-unit-demo" />
  167.         <property name="dataSource" ref="dataSource" />
  168.                <property name="packagesToScan" value="web.entity" />
  169.         <property name="jpaVendorAdapter">
  170.             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
  171.                                <property name="database" value="POSTGRESQL" />
  172. <!--    giving errors       <property name="databasePlatorm" value="org.hibernate.dialect.PostgreSQLDialect"/>-->
  173. <!--                                <property name="database" value="HSQL" />-->
  174.                 <property name="showSql" value="true" />
  175.                 <property name="generateDdl" value="true" />                       
  176.             </bean>
  177.         </property>  
  178.                <property name="jpaProperties">
  179.                    <props>
  180.                        <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
  181.                    </props>
  182.                 </property>                        
  183.     </bean>
  184.     <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
  185.     <!-- Pulls database connection from the tomcat container's context database pool via JNDI -->
  186. <!--    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/mssqlserver" resource-ref="true"/>-->
  187.  
  188.         <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
  189.             <property name="driverClassName" value="org.postgresql.Driver" />
  190.             <property name="url" value="jdbc:postgresql://localhost:5432/postgres" />
  191.             <property name="username" value="postgres" />
  192.             <property name="password" value="abc" />
  193.         </bean>
  194.    
  195.    
  196.    
  197.     <!--
  198.         Sets up our transaction manager.
  199.      -->
  200.     <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  201.         <property name="entityManagerFactory" ref="entityManagerFactory" />
  202.         <property name="jpaDialect" ref="jpaDialect" />
  203.         <property name="dataSource" ref="dataSource" />
  204. <!-- giving errors               <property name="loadTimeWeaver">
  205.                     <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
  206.                 </property>-->
  207.     </bean>
  208.    
  209.         <!--
  210.         Defines our transaction manager for Transactional annotations.
  211.      -->
  212.     <tx:annotation-driven transaction-manager="transactionManager" />
  213.      
  214.     <bean id="sessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory" />
  215.              
  216.    
  217.        
  218.        
  219.        
  220. </beans>
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233. ============================
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. <?xml version="1.0" encoding="UTF-8"?>
  245. <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  246.     <filter>
  247.         <filter-name>springSecurityFilterChain</filter-name>
  248.         <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  249.     </filter>
  250.  
  251.     <filter-mapping>
  252.         <filter-name>springSecurityFilterChain</filter-name>
  253.         <url-pattern>/*</url-pattern>
  254.     </filter-mapping>
  255.    
  256.     <context-param>
  257.         <param-name>contextConfigLocation</param-name>
  258.         <param-value>
  259.             /WEB-INF/spring-security.xml
  260.             /WEB-INF/applicationContext.xml
  261.         </param-value>
  262.     </context-param>
  263.     <listener>
  264.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  265.     </listener>
  266.     <servlet>
  267.         <servlet-name>springDispatcher</servlet-name>
  268.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  269.         <load-on-startup>1</load-on-startup>
  270.     </servlet>
  271.     <servlet-mapping>
  272.         <servlet-name>springDispatcher</servlet-name>
  273.         <url-pattern>/</url-pattern>
  274.     </servlet-mapping>
  275.     <session-config>
  276.         <session-timeout>
  277.             30
  278.         </session-timeout>
  279.     </session-config>
  280.     <welcome-file-list>
  281.         <welcome-file>redirect.jsp</welcome-file>
  282.     </welcome-file-list>
  283. </web-app>
Advertisement
Add Comment
Please, Sign In to add comment