【发布时间】:2014-03-11 03:35:55
【问题描述】:
你好 Stackoverflower,
我遇到了 Spring Security 的问题。在您继续使用您的应用程序之前应该出现的登录框不会出现,我无需任何身份验证即可访问我的应用程序。我不知道为什么会这样。 知道为什么不询问用户和密码是非常重要的。
我使用 RESTCLient Add on for firefox 测试我的应用程序。
web.xml 中的重要条目如下所示:
<!-- Security Configuration -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
<!-- Spring Json Init -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>json</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>json</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
我的 spring-security 是:
<!-- Security Propertie Configuration -->
<security:http use-expressions="true">
<security:http-basic/>
</security:http>
<security:authentication-manager>
<security:authentication-provider
ref="springUserService" />
</security:authentication-manager>
springUserService 看起来像这样:
@组件 公共类 springUserService 实现 AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
List<GrantedAuthority> grantedAuths = new ArrayList<>();
return new UsernamePasswordAuthenticationToken(name, password, grantedAuths);
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}
我非常感谢每一个提示或答案。
【问题讨论】:
标签: java spring authentication spring-security basic-authentication