【发布时间】:2015-01-31 08:53:31
【问题描述】:
我正在尝试使用 spring-security 为我的 REST-Service 实现基本身份验证,并满足以下要求:
- 授权由应用的其他部分完成(因此过滤器链中没有角色)
- 我想用普通 bean 配置所有东西,而不需要任何自动配置
让我感到困惑的是,BasicAuthenticationFilter 没有“授权”标头,因此有效地允许访问没有该标头的所有请求。 我排除了此类抛出异常的请求,而不是重定向到 authenticationEntryPoint 。
我的代码如下:
<bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
<constructor-arg>
<list>
<security:filter-chain pattern="/rest/**" filters="basicAuthenticationFilter,exceptionTranslationFilter" />
</list>
</constructor-arg>
</bean>
<bean id="basicAuthenticationFilter" class="authentication.MyBasicAuthenticationFilter">
<property name="authenticationManager" ref="myAuthenticationManager" />
<property name="authenticationEntryPoint" ref="authenticationEntryPoint" />
</bean>
<bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint">
<property name="realmName" value="myRealm" />
</bean>
我的假设是,我可能需要一个 filterSecurityInterceptor 并且在它之后还需要一个 accessDecisionManager。我不想使用那些,因为在我看来他们关心授权(与身份验证相反),而且我在我的应用程序的这一点上没有任何角色。
我只想检查正确的用户名/密码组合 并做出相应的反应(401 或 403)。
我想我遗漏了一些非常基本的东西,因此非常感谢任何提示或帮助。
【问题讨论】:
标签: spring-security basic-authentication