我正在使用apache karaf容器以及jetty,spring和cxf。 在使用spring security进行身份验证时发现了很多警告。
试图在网上找到这些信息,但找不到多少。 任何人都有类似的问题。为何会出现此类警告?它会影响吗?
代码段
public void prepareSecurityContext(ServletRequest request,
ServletResponse response, FilterChain chain, MeetingRef user,
String username, String token) throws IOException, ServletException {
// Build an Authentication object with the user's info
AbstractAuthenticationToken auth = new UserTokenAuthentication(
username, token, getAuthorities(user));
auth.setDetails(new WebAuthenticationDetailsSource()
.buildDetails((HttpServletRequest) request));
// Set the authentication into the SecurityContext
SecurityContextHolder.getContext().setAuthentication(auth);
// Continue through the filter chain
chain.doFilter(request, response);
}
// Build an Authentication object with the user's info
AbstractAuthenticationToken auth = new UserTokenAuthentication(
username, token, getAuthorities(user));
auth.setDetails(new WebAuthenticationDetailsSource()
.buildDetails((HttpServletRequest) request));
// Set the authentication into the SecurityContext
SecurityContextHolder.getContext().setAuthentication(auth);
// Continue through the filter chain
chain.doFilter(request, response);
}
以下是异常堆栈跟踪的片段:
2015-07-23T09:37:42.0 localhost.localdomain org.apache.cxf.interceptor.Fault: [warning] org.eclipse.jetty.io.EofException: timeout
2015-07-23T09:37:42.0 localhost.localdomain at [warning] org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1243)
2015-07-23T09:37:42.0 localhost.localdomain at [warning] org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:782)
2015-07-23T09:37:42.0 localhost.localdomain at [warning] org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:741)
......................................................
答案 0 :(得分:0)
请尝试以这种方式手动设置身份验证:
// Below gets the object from the database for the user which you want to authenticate.
Person person1 = this.personService.findPersonByUsername(username);
Collection<GrantedAuthority> authorities = new ArrayList<>();
// Add the role of the user
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
Authentication authentication = new UsernamePasswordAuthenticationToken(person1, null, authorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
试试这个,请用正确的格式更准确地发布日志,因为现在只能看到警告,并且流程是不可理解的。 Lemme知道这是否有帮助。