powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Spring Security custom filter problems
3 сообщений из 3, страница 1 из 1
Spring Security custom filter problems
    #37820968
Usik
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Пишу свой фильтр CustomAuthenticationProcessingFilter,во код


Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
public class CustomAuthenticationProcessingFilter extends AbstractAuthenticationProcessingFilter {

    private String usernameHeader = "j_username";
    private String passwordHeader = "j_password";


    protected CustomAuthenticationProcessingFilter() {
        super("/j_spring_security_filter");
    }

    @Override
    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
            throws AuthenticationException,
            IOException, ServletException {
        String username = request.getHeader(usernameHeader);
        String password = request.getHeader(passwordHeader);
        UsernamePasswordAuthenticationToken authenticationToken=new UsernamePasswordAuthenticationToken(username,password);         
        Authentication authentication=getAuthenticationManager().authenticate(authenticationToken);
       //some my actions
        return authentication;
    }
}



Далее описываю это дело в секурити конф. файле.

Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
<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.0.3.xsd">

    <http auto-config="true" use-expressions="true">
        <custom-filter ref="customFilter" before="FORM_LOGIN_FILTER"/>
        <intercept-url pattern="/login" access="permitAll"/>
        <form-login login-page="/login" authentication-failure-url="/loginfailed" default-target-url="/"/>
        <remember-me key="jbcpPetStore"/>
        <logout invalidate-session="true" logout-success-url="/" logout-url="/logout"/>
    </http>

    <beans:bean id="userDetailsServiceImpl" class="entities.user.UserDetailsServiceImpl"/>

    <beans:bean id="customFilter" class="entities.user.CustomAuthenticationProcessingFilter">
        <beans:property name="authenticationManager" ref="authenticationManager"/>
    </beans:bean>

    <authentication-manager alias="authenticationManager">
        <authentication-provider user-service-ref="userDetailsServiceImpl"/>
    </authentication-manager>
</beans:beans>



Захожу на логин страницу, заполняю данные на форме, сабмичу, ставлю бряки в authenticationManager и CustomAuthenticationProcessingFilter.В результате в authenticationManager я попадаю, а вот в CustomAuthenticationProcessingFilter нет, и метод attemptAuthentication не вызывается. Что нужно сделать чтобы по сабиту формы логина я попадал в метод attemptAuthentication .
...
Рейтинг: 0 / 0
Spring Security custom filter problems
    #37821452
IDVsbruck
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Похоже, что auto-config="true" мешает поместить твой фильтр в цепочку фильтров. Без него не заработало?
...
Рейтинг: 0 / 0
Spring Security custom filter problems
    #37821593
Usik
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Ок, спс, приду запущу ,проверю,отпишусь.
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Spring Security custom filter problems
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]