![](/img/trans.png)
[英]Spring security login form does not work when there is servlet Url: localhost: 8080 / nameWeb / login
[英]Spring Security Servlet Login
我有一個Spring安全性涵蓋的現有Web應用程序。 我需要添加一個以這種方式工作的servlet(或通用端點):
我已經閱讀了有關Spring安全性的文檔( http://docs.spring.io/spring-security/site/docs/3.0.x/reference/springsecurity.html ),但是我對如何以及在何處實現感到困惑我的代碼。 我在考慮在階段4中使用自定義過濾器: UsernamePasswordAuthenticationFilter
。 但是,我不確定,因為如果我正確地理解了框架,則過濾器將應用於每個請求,並且我只需要登錄一次,然后就可以被身份驗證。
過濾器是正確的方法還是有更好的方法?
編寫Web服務時,最好對客戶端的每個請求都重新授權。 這意味着客戶端必須每次都傳遞其憑據(用戶名/密碼)。
順便說一句,如果您正在編寫Web服務,則最好在ssl上使用BasicAuthenticationEntryPoint而不是UsernamePasswordAuthenticaitonFilter。
但是,為了完全回答您的問題,我們使用了安全性/ http模式匹配器來解決問題。
<security:http pattern="/api/**" create-session="stateless" access-decision-manager-ref="unanimousBased" entry-point-ref="authenticationEntryPoint" >
<security:intercept-url pattern="/api/**" access="IS_AUTHENTICATED_FULLY,group_User_role_default" />
<security:custom-filter ref="basicAuthenticationFilter" after="BASIC_AUTH_FILTER" />
</security:http>
<bean id="basicAuthenticationFilter" class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter">
<property name="authenticationManager" ref="authenticationManager" />
<property name="authenticationEntryPoint" ref="authenticationEntryPoint" />
</bean>
<bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint">
<property name="realmName" value="api" />
</bean>
最后,通常最好在處理數據之前先進行授權。 數據將被處理,然后檢查授權以查看是否可以發送響應,這似乎很奇怪,但這也許就是我自己。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.