如何将MD5哈希添加到spring安全性中

时间:2013-08-28 01:12:30

标签: java spring-security md5

我想将md5哈希添加到springsecuritycontext.xml中,我仍然不知道如何告诉Spring连接我的数据库并哈希我的密码,我怎么能告诉他必须比较清楚密码和哈希值一个为了连接到应用程序!

这是我的springsecuritycontext.xml和我的web.xml我需要一步一步地解释。

我的web.xml:

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                                 -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <!--       Spring-Security is mapped to all URLs       -->
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern></url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>
            org.springframework.security.ui.session.HttpSessionEventPublisher</listener-class>
    </listener>
    <!--  END SPRING-Security -->

  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext-db.xml,
            classpath:applicationContext-hibernate.xml,
            /WEB-INF/SpringSecurityContext.xml
        </param-value>
    </context-param>

    <!--  START SPRING -->
    <listener>
        <display-name>Spring Context Loader</display-name>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>
            org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <!-- END Spring  -->

  <context-param>
    <description>Report resources(design files or document files) directory for preview. Default to ${Context Root}</description>
    <param-name>BIRT_VIEWER_WORKING_FOLDER</param-name>
    <param-value />
  </context-param>
  <context-param>
    <description>Report engine log level.( ALL|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST|OFF )</description>
    <param-name>BIRT_VIEWER_LOG_LEVEL</param-name>
    <param-value>WARNING</param-value>
  </context-param>
  <context-param>
    <description>Directory to store all birt report script libraries (JARs). Default to ${Context Root}/scriptlib</description>
    <param-name>BIRT_VIEWER_SCRIPTLIB_DIR</param-name>
    <param-value>WEB-INF/report-engine/scriptlib</param-value>
  </context-param>
  <context-param>
    <description>If force optimized HTML output.Default to true</description>
    <param-name>HTML_ENABLE_AGENTSTYLE_ENGINE</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <description>Report Engine logs directory. Default to ${Context Root}/logs</description>
    <param-name>BIRT_VIEWER_LOG_DIR</param-name>
    <param-value>WEB-INF/report-engine/logs</param-value>
  </context-param>
  <context-param>
    <description>Resource location directory(library files, images files or others). Default to ${Context Root}</description>
    <param-name>BIRT_RESOURCE_PATH</param-name>
    <param-value />
  </context-param>
  <context-param>
    <description>Output images/charts directory. Default to ${Context Root}/report/images</description>
    <param-name>BIRT_VIEWER_IMAGE_DIR</param-name>
    <param-value>WEB-INF/report-engine/images</param-value>
  </context-param>
  <context-param>
    <description>BIRT viewer extended configuration file</description>
    <param-name>BIRT_VIEWER_CONFIG_FILE</param-name>
    <param-value>WEB-INF/report-engine/viewer.properties</param-value>
  </context-param>
  <context-param>
    <description>If always overwrite generated document file. Default to true</description>
    <param-name>BIRT_OVERWRITE_DOCUMENT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <description>Dataset rows limited when preview report. Default to return all rows</description>
    <param-name>BIRT_VIEWER_MAX_ROWS</param-name>
    <param-value />
  </context-param>
  <context-param>
    <description>The generated document files directory. Default to ${Context Root}/documents</description>
    <param-name>BIRT_VIEWER_DOCUMENT_FOLDER</param-name>
    <param-value>WEB-INF/report-engine/documents</param-value>
  </context-param>
  <context-param>
    <description>If turn on the function that supports print on the server side(ON|OFF).Default to on.</description>
    <param-name>BIRT_VIEWER_PRINT_SERVERSIDE</param-name>
    <param-value>ON</param-value>
  </context-param>
  <context-param>
    <description>Default locale setting</description>
    <param-name>BIRT_VIEWER_LOCALE</param-name>
    <param-value>en-US</param-value>
  </context-param>
  <context-param>
    <description>If usr can only access the reprot resources under working folder. Default is false</description>
    <param-name>WORKING_FOLDER_ACCESS_ONLY</param-name>
    <param-value>false</param-value>
  </context-param>
  <listener>
    <listener-class>org.eclipse.birt.report.listener.ViewerHttpSessionListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.eclipse.birt.report.listener.ViewerServletContextListener</listener-class>
  </listener>

  <listener>
    <listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.zkoss.jsp.spec.JspFactoryContextListener</listener-class>
  </listener>
   <servlet>
    <servlet-name>zkLoader</servlet-name>
    <servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
    <init-param>
      <param-name>update-uri</param-name>
      <param-value>/zkau</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>auEngine</servlet-name>
    <servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
  </servlet>
 <!-- <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  --><servlet>
    <servlet-name>EngineServlet</servlet-name>
    <servlet-class>org.eclipse.birt.report.servlet.BirtEngineServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>ViewerServlet</servlet-name>
    <servlet-class>org.eclipse.birt.report.servlet.ViewerServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>

<servlet>
        <servlet-name>CommonsFileUploadServlet</servlet-name>
        <servlet-class>com.dam.objets.CommonsFileUploadServlet</servlet-class>
    </servlet>

    <servlet>
    <servlet-name>Chapter2Servlet</servlet-name>
    <servlet-class>com.dam.objets.Chapter2Servlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Chapter2Servlet</servlet-name>
    <url-pattern>/report</url-pattern>
    </servlet-mapping>

    <servlet>
    <servlet-name>UploadServlet</servlet-name>
    <servlet-class>com.dam.objets.UploadServlet</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>UploadServlet</servlet-name>
    <url-pattern>/Upload</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>CommonsFileUploadServlet</servlet-name>
        <url-pattern>/Commonsfileuploadservlet</url-pattern>
    </servlet-mapping>

<servlet-mapping>
    <servlet-name>zkLoader</servlet-name>
    <url-pattern>*.zul</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>zkLoader</servlet-name>
    <url-pattern>*.zhtml</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>auEngine</servlet-name>
    <url-pattern>/zkau/*</url-pattern>
  </servlet-mapping>
<!--<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  --><servlet-mapping>
    <servlet-name>EngineServlet</servlet-name>
    <url-pattern>/download</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>EngineServlet</servlet-name>
    <url-pattern>/preview</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ViewerServlet</servlet-name>
    <url-pattern>/frameset</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>EngineServlet</servlet-name>
    <url-pattern>/parameter</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ViewerServlet</servlet-name>
    <url-pattern>/run</url-pattern>
  </servlet-mapping>


  <welcome-file-list>
    <welcome-file>index.zul</welcome-file>
  </welcome-file-list>
  <jsp-config>
    <taglib>
      <taglib-uri>/birt.tld</taglib-uri>
      <taglib-location>/WEB-INF/report-engine/tlds/birt.tld</taglib-location>
    </taglib>
  </jsp-config>
</web-app>

Spring安全内容:

<?xml version="1.0" encoding="UTF-8"?>

    <!-- Spring namespace-based configuration -->

    <beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:zksp="http://www.zkoss.org/2008/zkspring"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd
                        http://www.springframework.org/schema/aop   
                        http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">


    <global-method-security secured-annotations="enabled" />

    <http auto-config="true">

        <form-login login-page="/index.zul" 

            authentication-failure-url="/index.zul?login_error=1"
            default-target-url="/AccueilIntranet.zul" />


        <logout logout-url="/j_spring_logout" logout-success-url="/index.zul" />


        <intercept-url pattern="/pages/**" access="IS_AUTHENTICATED_REMEMBERED" filters="none" />
        <intercept-url pattern="/WEB-INF/pages/**" access="IS_AUTHENTICATED_REMEMBERED" filters="none"/>


        <intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" filters="none"/>

        <!-- ###           Per user one session !!            ### -->
        <concurrent-session-control max-sessions="1" />
    </http>

    <authentication-provider user-service-ref="myUserDetailsService">
    </authentication-provider>

    <beans:bean id="myUserDetailsService" class="ma.dyaralmansour.zkgui.policy.PolicyManager">
        <beans:property name="userService" ref="userService" />
    </beans:bean>

    <beans:bean id="LoginLoggingPolicyService"
        class="ma.dyaralmansour.zkgui.policy.LoginLoggingPolicyService">
        <beans:property name="loginLoggingService" ref="loginLoggingService" />
    </beans:bean>

    <aop:config>
        <aop:aspect id="LoginLoggingAspect" ref="LoginLoggingPolicyService">
            <aop:pointcut id="authPointcut"
                expression="execution(public org.springframework.security.Authentication org.springframework.security.providers.AuthenticationProvider.authenticate(org.springframework.security.Authentication))" />
            <aop:around pointcut-ref="authPointcut" method="loginLogging" />
        </aop:aspect>
    </aop:config>

</beans:beans>

0 个答案:

没有答案