第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

將Spring Security 3.x配置為具有多個(gè)入口點(diǎn)

將Spring Security 3.x配置為具有多個(gè)入口點(diǎn)

寶慕林4294392 2019-10-25 10:06:33
我一直在使用Spring Security 3.x來(lái)為我的項(xiàng)目處理用戶(hù)身份驗(yàn)證,到目前為止,它已經(jīng)完美地工作了。我最近收到了一個(gè)新項(xiàng)目的要求。在此項(xiàng)目中,需要兩套用戶(hù)身份驗(yàn)證:一套用于根據(jù)LDAP驗(yàn)證員工,另一套用于根據(jù)數(shù)據(jù)庫(kù)驗(yàn)證客戶(hù)。我對(duì)如何在Spring Security中進(jìn)行配置感到有些困惑。我最初的想法是創(chuàng)建一個(gè)具有以下字段的登錄屏幕:?jiǎn)芜x按鈕字段-供用戶(hù)選擇是員工還是客戶(hù)。j_username 用戶(hù)字段。j_password 密碼字段。如果用戶(hù)選擇“雇員”,那么我希望Spring Security根據(jù)LDAP對(duì)他們進(jìn)行身份驗(yàn)證,否則,將根據(jù)數(shù)據(jù)庫(kù)對(duì)憑據(jù)進(jìn)行身份驗(yàn)證。但是,問(wèn)題在于表單將被提交到,/j_spring_security_check并且我無(wú)法將單選按鈕字段發(fā)送給實(shí)現(xiàn)的自定義身份驗(yàn)證提供程序。我最初的想法是,我可能需要兩個(gè)表單提交URL,而不是依賴(lài)默認(rèn)URL /j_spring_security_check。每個(gè)URL將由不同的身份驗(yàn)證提供程序處理,但是我不確定如何在Spring Security中進(jìn)行配置。我知道在Spring Security中,我可以配置回退身份驗(yàn)證,例如,如果LDAP身份驗(yàn)證失敗,則它將回退至數(shù)據(jù)庫(kù)身份驗(yàn)證,但這不是我在這個(gè)新項(xiàng)目中要解決的問(wèn)題。有人可以分享我在Spring Security 3.x中應(yīng)該如何配置它嗎?謝謝。
查看完整描述

3 回答

?
天涯盡頭無(wú)女友

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊

好的,我設(shè)法使@Ritesh的方法非常接近我想要的工作。我有一個(gè)單選按鈕,可讓用戶(hù)選擇他們是客戶(hù)還是員工??磥?lái)這種方法運(yùn)作良好,有一個(gè)問(wèn)題...


如果員工使用正確的憑據(jù)登錄,則可以在...中按預(yù)期工作。

如果員工使用錯(cuò)誤的憑據(jù)登錄,則不允許他們?cè)?..中工作。

如果客戶(hù)使用正確的憑據(jù)登錄,則可以在...中按預(yù)期工作。

如果顧客有錯(cuò)憑據(jù)登錄,認(rèn)證回落到員工的認(rèn)證...... 不起作用。這是有風(fēng)險(xiǎn)的,因?yàn)槿绻疫x擇客戶(hù)身份驗(yàn)證并將其打入員工證書(shū),它將也允許用戶(hù)進(jìn)入,這不是我想要的。

    <sec:http auto-config="false" entry-point-ref="loginUrlAuthenticationEntryPoint">

        <sec:logout logout-success-url="/login.jsp"/>

        <sec:intercept-url pattern="/employee/**" access="ROLE_EMPLOYEE"/>

        <sec:intercept-url pattern="/customer/**" access="ROLE_CUSTOMER"/>

        <sec:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>


        <sec:custom-filter position="FORM_LOGIN_FILTER" ref="myAuthenticationFilter"/>

    </sec:http>



    <bean id="myAuthenticationFilter" class="ss.MyAuthenticationFilter">

        <property name="authenticationManager" ref="authenticationManager"/>

        <property name="authenticationFailureHandler" ref="failureHandler"/>

        <property name="authenticationSuccessHandler" ref="successHandler"/>

    </bean>


    <bean id="loginUrlAuthenticationEntryPoint"

          class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">

        <property name="loginFormUrl" value="/login.jsp"/>

    </bean>


    <bean id="successHandler"

          class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">

        <property name="defaultTargetUrl" value="/welcome.jsp"/>

        <property name="alwaysUseDefaultTargetUrl" value="true"/>

    </bean>


    <bean id="failureHandler"

          class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">

        <property name="defaultFailureUrl" value="/login.jsp?login_error=1"/>

    </bean>



    <bean id="employeeCustomAuthenticationProvider" class="ss.EmployeeCustomAuthenticationProvider">

        <property name="userDetailsService">

            <bean class="ss.EmployeeUserDetailsService"/>

        </property>

    </bean>


    <bean id="customerCustomAuthenticationProvider" class="ss.CustomerCustomAuthenticationProvider">

        <property name="userDetailsService">

            <bean class="ss.CustomerUserDetailsService"/>

        </property>

    </bean>



    <sec:authentication-manager alias="authenticationManager">

        <sec:authentication-provider ref="customerCustomAuthenticationProvider"/>

        <sec:authentication-provider ref="employeeCustomAuthenticationProvider"/>

    </sec:authentication-manager>

</beans>

這是我更新的配置。我必須做一些非常小的調(diào)整,以防止身份驗(yàn)證回退,但我現(xiàn)在似乎無(wú)法弄清楚。


謝謝。


查看完整回答
反對(duì) 回復(fù) 2019-10-25
?
一只名叫tom的貓

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊

好吧,我想我已經(jīng)解決了這個(gè)問(wèn)題。無(wú)需EmployeeCustomAuthenticationProvider依賴(lài)默認(rèn)值UsernamePasswordAuthenticationToken,我EmployeeUsernamePasswordAuthenticationToken為它創(chuàng)建了它,就像為它創(chuàng)建CustomerUsernamePasswordAuthenticationToken的那樣CustomerCustomAuthenticationProvider。這些提供者將覆蓋supports():-


CustomerCustomAuthenticationProvider類(lèi)


@Override

public boolean supports(Class<? extends Object> authentication) {

    return (CustomerUsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));

}

EmployeeCustomAuthenticationProvider類(lèi)


@Override

public boolean supports(Class<? extends Object> authentication) {

    return (EmployeeUsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));

}

MyAuthenticationFilter類(lèi)


public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {


    ...


    UsernamePasswordAuthenticationToken authRequest = null;


    if ("customer".equals(request.getParameter("radioAuthenticationType"))) {

        authRequest = new CustomerUsernamePasswordAuthenticationToken(username, password);


    }

    else {

        authRequest = new EmployeeUsernamePasswordAuthenticationToken(username, password);

    }


    setDetails(request, authRequest);


    return super.getAuthenticationManager().authenticate(authRequest);

}

...還有WALAA!經(jīng)過(guò)幾天的挫敗,它現(xiàn)在可以正常工作!


希望這篇文章能夠?qū)εc我在這里做同樣事情的人有所幫助。


查看完整回答
反對(duì) 回復(fù) 2019-10-25
  • 3 回答
  • 0 關(guān)注
  • 848 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)