使用Spring Security时,移动设备和桌面的不同登录页面 [英] Different Login pages for mobile and desktop while using Spring Security

查看:315
本文介绍了使用Spring Security时,移动设备和桌面的不同登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有spring-mvc的spring-security web身份验证,到目前为止一切都很好,但现在我正在开发我的应用程序的移动版本,我为移动网站设计了一组不同的页面,其中包括不同的登录页面。现在我的配置有问题

I'm using spring-security web authentication with spring-mvc, all is well so far, but now i am developing a mobile version of my application for that i have designed a different set of pages for mobile site which includes a different login page. now my i have problems configuring that

这里是我的applicationContext-security.xml

here's my applicationContext-security.xml

    <?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    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.0.xsd">

    <http auto-config="true" lowercase-comparisons="false">
        <intercept-url pattern="/images/**" filters="none" />
        <intercept-url pattern="/Stylesheets/**" filters="none" />
        <intercept-url pattern="/JavaScript/**" filters="none" />
        <intercept-url pattern="/scripts/**" filters="none" />
        <intercept-url pattern="/favicon.ico" access="ROLE_ANONYMOUS" />
        <intercept-url pattern="/**" access="ROLE_USER,ROLE_ADMIN"/>
        <intercept-url pattern="/mobile/**" access="ROLE_USER,ROLE_ADMIN"/>
        <form-login login-page="/login.htm" authentication-success-handler-ref="customHandler"
            authentication-failure-url="/login.htm?error=true" default-target-url="/home.htm"
            login-processing-url="/j_security_check"  />
         <remember-me user-service-ref="userDAO" key="e37f4b31-0c46-11dd-bd0b-0800200c9a66"/>
    </http>

    <beans:bean id="customHandler" class="com.example.auth.AuthenticationHandler">
    </beans:bean>

    <authentication-manager>
        <authentication-provider user-service-ref="userDAO">
            <!--
            TODO skipped to allow password emailing instead of password change and security
            TODO question hell..
          -->
           <!--  <password-encoder ref="passwordEncoder"/>  -->
        </authentication-provider>
    </authentication-manager>

</beans:beans>

现在我如何根据不同的请求拥有多个登录页面,我的意思是如果移动页面文件夹比用户应该显示移动登录页面。
i在stackoverflow上看到了类似的问题,但那些是根据不同角色的登录页面,但在我的情况下我想要不同页面的diff登录。

now how can i have multiple login pages according to the different request, i mean if the pages of mobile folder than the user should be shown the mobile login page. i have seen similar questions on stackoverflow but those were login pages according to different roles, but in my case i want diff login for different pages.

谢谢对于解决方案,它似乎对我来说很好。我现在已经切换到spring security 3.1但它给了我一个例外。你可以帮我解决这个问题。

thanks for the solution it seems that it will work fine for me. i have now switched to spring security 3.1 but it is giving me an exception. can you please help me resolve this.

Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#4' while setting bean property 'sourceList' with key [4]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#4': Cannot create inner bean '(inner bean)' of type [org.springframework.security.web.authentication.logout.LogoutFilter] while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#6': Cannot resolve reference to bean 'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0': Cannot create inner bean '(inner bean)' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#7': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Property 'sessionFactory' is required for bean '(inner bean)#7'


推荐答案

如果你有能力切换弹簧安全3.1,你可以简单地定义2个http元素 1 。如果无法切换,则无法通过命名空间完全配置,但必须注册entry-point-ref和somd < sec:custom-filter> 元素。

If you have the posibility to switch t spring security 3.1, you can simply define 2 http elements 1. If you can not switch, you can not configure it fully via the namespace, but have to register an entry-point-ref and somd <sec:custom-filter> elements.

这篇关于使用Spring Security时,移动设备和桌面的不同登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆