将spring-security.xml配置移动到基于java的spring Boot 配置

arknldoa  于 2023-01-24  发布在  Spring
关注(0)|答案(1)|浏览(185)

我有一个在Spring中实现的现有项目,现在我将此项目移动到Sping Boot 。现有项目包含spring-security.xml

<b:beans xmlns="http://www.springframework.org/schema/security"
         xmlns:b="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd">

    <http auto-config="true" pattern="/dashboard*" use-expressions="true" >
        <intercept-url pattern="/dashboard*" access="hasRole('ROLE_NORMAL_USER')"  />
        <form-login  login-page="/logout" default-target-url="/dashboard" 
            authentication-failure-url="/loginerrorpage"  />
        <session-management>
            <concurrency-control  max-sessions="12" expired-url="/logout"/>
        </session-management>
        
        <custom-filter after="LOGIN_PAGE_FILTER" ref="LoginFilter" />
        
        <logout invalidate-session="true" logout-success-url="/logout"   logout-url="/j_spring_security_logout"/>
        <csrf  disabled="true" />
    </http>
    
    <http auto-config="true">
        <intercept-url pattern="/entrance" access="hasRole('ROLE_NORMAL_USER')"  />
        <form-login  login-page="/login" default-target-url="/entrance" 
            authentication-failure-url="/loginerrorpage" />
        <session-management>
            <concurrency-control  max-sessions="12" expired-url="/logout"/>
        </session-management>
        
        <logout invalidate-session="true" logout-success-url="/logout"   logout-url="/j_spring_security_logout"/>
        <csrf  disabled="true" />
    </http>

    
    <authentication-manager>
        <authentication-provider>
             <user-service>
                <user name="user1" password="password1" authorities="ROLE_NORMAL_USER" /> 
                <user name="user2" password="password2" authorities="ROLE_NORMAL_USER" />       
        </user-service>
    </authentication-provider>
        
    </authentication-manager>
    
    <beans:bean id="LoginFilter" class="com.codemaster.LoginFilter"/>

</b:beans>

是否有人知道如何将上述配置转换为 Spring Boot 配置

bxjv4tth

bxjv4tth1#

只需将流类添加到项目中。

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@ImportResource("classpath:spring-security.xml")
public class SecurityConfig {
}

相关问题