【问题标题】:Spring Security-flow after authentication entry point身份验证入口点后的 Spring Security-flow
【发布时间】:2015-05-11 11:52:34
【问题描述】:

我正在尝试使用 spring security 保护我的 REST 服务。我的问题是,我卡在身份验证入口点。即使我配置了 UsernamePasswordAuthenticationFilter,执行流程也无法到达那里。 下面是 XML 配置

<sec:http create-session="stateless" auto-config="false"
                authentication-manager-ref="authenticationManager"
                entry-point-ref="http403EntryPoint"
                >

        <sec:form-login
            login-processing-url="/login"
            password-parameter="password"
            username-parameter="username"
            />

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

        <sec:intercept-url pattern="/**" 
                       method="POST"
                       access="ROLE_USER" 
                       />
    </sec:http>

    <sec:authentication-manager alias="authenticationManager">
            <sec:authentication-provider user-service-ref="authenticatorDAO">
            </sec:authentication-provider>
    </sec:authentication-manager>

<bean id="http403EntryPoint"
        class="com.app.login.RestAuthenticationEntryPoint" />

AuthenticationEntryPoint 的代码如下。

public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint{

   @Override
   public void commence( HttpServletRequest request, HttpServletResponse response, 
    AuthenticationException authException ) throws IOException{
       System.out.println("in RestAuthenticationEntrypoint\n--------------------------------------\n");
      response.sendError( HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized" );
   }
}

谁能告诉我我在这里做错了什么?

【问题讨论】:

    标签: rest spring-security


    【解决方案1】:

    抱歉,无法发布 cmets,因此将其发布为答案。

    检查是否在您的现有配置中调用了 ExceptionTranslationFilter。

    你是否在 ExceptionTranslationFilter 中注入了 http403EntryPoint?

     <bean id="etf" class="org.springframework.security.web.access.ExceptionTranslationFilter">
            <property name="authenticationEntryPoint" ref="http403EntryPoint"/>
     </bean
    

    >

    【讨论】:

    • 不,我没有注入入口点引用。而且我在错误跟踪中也没有异常。开始方法完成后,流程无处可去
    • 如果我添加一个自定义过滤器代替form_login_filter,用户获得身份验证但AuthenticationEntryPoint抛出“需要身份验证”错误。我的问题是,为什么在用户成功通过身份验证后执行authenticationentrypoint?跨度>
    猜你喜欢
    • 2013-06-20
    • 1970-01-01
    • 2022-01-15
    • 2014-02-26
    • 1970-01-01
    • 2013-01-15
    • 2019-08-25
    • 2013-10-30
    • 2014-04-07
    相关资源
    最近更新 更多