繁体   English   中英

基于Spring 3安全性的登录表单

[英]Login form based spring 3 security

我正在使用Spring Security进行身份验证登录。 我想在名称和密码中传递动态值,但是我不想使用服务层,为此我在控制器中使用了Web服务调用。

这是我的代码:

        <?xml version="1.0" encoding="UTF-8"?>
         <beans:beans xmlns="http://www.springframework.org/schema/security"
            xmlns:beans="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                                http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">    

                <global-method-security pre-post-annotations="enabled" />
                 <http pattern="/auth/logout.html" security="none"/>
                 <http pattern="/css/**" security="none" />
                 <http pattern="/js/**" security="none" /> 

                <http auto-config="true"  use-expressions="true">
                <intercept-url pattern="/login" access="permitAll" />
                <intercept-url pattern="/logout" access="permitAll" />
                <intercept-url pattern="/accessdenied" access="permitAll" />
                <intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
                <form-login login-page="/login" default-target-url="/suburb_analyser" authentication-failure-url="/accessdenied" />
                <logout logout-success-url="/logout" />
            </http>

            <authentication-manager alias="authenticationManager">
                <authentication-provider>
                    <user-service>
                        <user name="j@hotsal.com.au" password="mor55eover" authorities="ROLE_USER" />
                    </user-service>
                </authentication-provider>
            </authentication-manager>

        </beans:beans>

如果要在名称和密码中传递动态值。 您需要声明一个实现UserDetailsS​​ervice接口的bean。 然后将您的xml修改为:

<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="yourServiceBeanName">
    </authentication-provider>
</authentication-manager>

您可以使用JDBC,文件系统或内存在服务中动态生成您的名称和密码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM