Преобразование свойств spring-security и web.xml в аннотации Java - PullRequest
0 голосов
/ 05 сентября 2018

У меня есть два файла (web.xml и SpringSecurityApp-servlet.xml) с несколькими свойствами в рабочем приложении, и я хотел бы переместить оба свойства xml в java-аннотации. Как будет преобразование? С уважением.

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"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     version="2.5">
<display-name>Project Name</display-name>
<welcome-file-list>
    <welcome-file></welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>SpringSecurityApp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>SpringSecurityApp</servlet-name>
    <url-pattern>/services/*</url-pattern>
</servlet-mapping>


<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/SpringSecurityApp-servlet.xml</param-value>
</context-param>

<!-- Enable Spring Security -->
<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>

и SpringSecurityApp-servlet.xml:

   <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:security="http://www.springframework.org/schema/security"

   xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/security
            http://www.springframework.org/schema/security/spring- 
           security.xsd">

          <context:component-scan base-package="com.myPackage.security"/>

    <bean         
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/views/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

<!-- Application entry point which will redirect to login if user is not authenticated -->
    <bean id="appAuthenticationEntryPoint" 
      class="com.myPackage.security.entrypoint.AppAuthenticationEntryPoint">
      <constructor-arg name="loginFormUrl" value="/services/login"/>
    </bean>

<!-- if user authentication is successful then AppSuccessHandler will redirect to page based on role-->
   <bean id="successHandler" 
   class="com.myPackage.security.handler.AppSuccessHandler"/>

<bean id="failureHandler"    

класс = "org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">

<security:http pattern="/services/login" security="none"/>
<security:http pattern="/services/accessdenied" security="none"/>
<security:http auto-config="true" use-expressions="true" entry-point-ref="appAuthenticationEntryPoint">
    <!-- Interceptor urls -->
    <security:intercept-url pattern="/" access="isAuthenticated()"/>
    <security:intercept-url pattern="/**" access="isAuthenticated()"/>
    <security:intercept-url pattern="/user**" access="hasRole('USER')" />
    <security:intercept-url pattern="/admin**" access="hasRole('ADMIN')" />

    <security:form-login login-page="/login"
                         login-processing-url="/j_spring_security_check"
                         authentication-success-handler-ref="successHandler"
                         authentication-failure-handler-ref="failureHandler"
                         username-parameter="username"
                         password-parameter="password"
            />

    <!-- disabling csrf protection -->
    <security:csrf disabled="true"/>
</security:http>


<security:authentication-manager alias="authenticationManager">
    <security:authentication-provider ref="customAuthenticationProvider"/>
</security:authentication-manager>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...