
Originally Posted by
karldmoore
Glad I'm not alone on this one

.
I post my solution.
Code:
public class CustomAuthenticationProcessingFilter extends AuthenticationProcessingFilter {
private Logger logger = Logger.getLogger(getClass());
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
if (!(request instanceof HttpServletRequest)) {
throw new ServletException("Can only process HttpServletRequest");
}
if (!(response instanceof HttpServletResponse)) {
throw new ServletException("Can only process HttpServletResponse");
}
HttpServletRequest httpRequest = ((HttpServletRequest) request);
HttpServletResponse httpResponse = ((HttpServletResponse) response);
if (httpRequest.getParameterMap().containsKey("myParamKey") &&
httpRequest.getSession().getId() != null) {
httpRequest.getSession().setAttribute("myParamKey", "myParamKey");
if (logger.isDebugEnabled()) {
logger.debug("Request is to process authentication");
}
Cookie[] cookies = ((HttpServletRequest) request).getCookies();
Cookie mycookie = null;
for (Cookie c : cookies) {
if (c.getName().equalsIgnoreCase("MyCustomCookie") &&
c.getMaxAge() < 0) {
mycookie = c;
}
}
if (mycookie != null ) {
CustomAuthenticationToken authRequest = null;
try {
onPreAuthentication(httpRequest, httpResponse);
authRequest = new CustomAuthenticationToken(httpRequest.getParameter("myParamKey"), httpRequest.getParameter("myParamKey"));
authRequest.setInfo(mycookie.getValue());
authRequest.setDetails(new WebAuthenticationDetails(httpRequest));
setDetails(httpRequest, authRequest);
Authentication auth = this.getAuthenticationManager().authenticate(authRequest);
SecurityContextHolder.getContext().setAuthentication(auth);
successfulAuthentication(httpRequest, httpResponse, auth);
} catch (AuthenticationException authenticationException) {
if (logger.isDebugEnabled()) {
logger.debug("my message", authenticationException);
}
unsuccessfulAuthentication(((HttpServletRequest) request), ((HttpServletResponse) response), authenticationException);
}
return;
} else {
new myParamKeyFault("Cookie not valid");
}
}
super.doFilter(request, response, filterChain);
}
}
thanks a lot.