Tôi đang sử dụng bảo mật mùa xuân với Xác thực cơ bản HTTP để bảo mật ứng dụng web java. Trong webapp của tôi, tôi cần lấy tên người dùng và mật khẩu của người dùng hiện tại để xác thực thêm họ với một dịch vụ khác. Tôi có thể giữ tên người dùng, nhưng không phải mật khẩu.Truy xuất mật khẩu của người dùng hiện tại từ bảo mật mùa xuân
Tôi đã thử sử dụng SecurityContextHolder.getContext().getAuthentication()
để truy cập thông tin này như được đề xuất ở đây How can I get plaintext password from spring-security? nhưng mật khẩu được trả lại là null
.
Tôi có thể giữ mật khẩu bằng cách nào?
Cảm ơn.
Đây là tôi applicationContext-security.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security" 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">
<sec:http authentication-manager-ref='authenticationManager'>
<sec:intercept-url pattern="/spring/**" access="ROLE_USER" />
<sec:http-basic />
</sec: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="Announcements Rest Realm" />
</bean>
<bean id="authenticationManager"
class="org.springframework.security.authentication.ProviderManager">
<property name="providers">
<list>
<ref local="authProvider" />
</list>
</property>
</bean>
<bean id="authProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="userDetailsService" />
</bean>
<bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
<constructor-arg>
<list>
<sec:filter-chain pattern="/spring/**" filters="basicAuthenticationFilter" />
</list>
</constructor-arg>
</bean>
<sec:user-service id="userDetailsService">
<sec:user name="admin" password="**" authorities="ROLE_USER, ROLE_ADMIN" />
<sec:user name="user" password="**" authorities="ROLE_USER" />
</sec:user-service>
Tôi không sử dụng ghi nhớ tôi, chạy hoặc chuyển người dùng theo như tôi biết (trừ khi chúng được bật theo mặc định ? Tôi không sử dụng tự động cấu hình). Ngoài ra tôi không thể sử dụng xác thực biểu mẫu vì webapp của tôi là dịch vụ web. – ssloan
ok, vậy làm thế nào để bạn thông báo cho SI rằng người dùng đã được xác thực thành công? Nếu bạn sử dụng SecurityContextHolder.getContext(). SetAuthentication (...), thì bạn sẽ vượt qua loại mã thông báo nào? –
Tôi không gọi trực tiếp setAuthentication() - nó phải xảy ra ở một trong những bean tôi đã cấu hình. Tôi sẽ cập nhật bài đăng của mình với trường hợp applicationContext-security.xml của tôi. – ssloan