// Path: src/main/java/security/constant/Constant.java
// public interface Constant {
// 
// 	String HEADER_SECURITY_TOKEN = "X-AuthToken";
// }
// 
// Path: src/main/java/security/entity/AuthToken.java
// @Entity
// @Table(name = "auth_token")
// public class AuthToken extends AbstractAuditableEntity {
// 
// 	private static final long serialVersionUID = -9001508296580395084L;
// 
// 	private String token;
// 
// 	private String series;
// 
// 	@ManyToOne(fetch = FetchType.EAGER)
// 	@JoinColumn(name = "user", nullable = false)
// 	private User user;
// 
// 	public String getToken() {
// 		return token;
// 	}
// 
// 	public void setToken(String token) {
// 		this.token = token;
// 	}
// 
// 	public String getSeries() {
// 		return series;
// 	}
// 
// 	public void setSeries(String series) {
// 		this.series = series;
// 	}
// 
// 	public User getUser() {
// 		return user;
// 	}
// 
// 	public void setUser(User user) {
// 		this.user = user;
// 	}
// 
// }
// 
// Path: src/main/java/security/handler/TokenBasedAuthenticationSuccessHandlerImpl.java
// public class TokenBasedAuthenticationSuccessHandlerImpl extends
// 		SimpleUrlAuthenticationSuccessHandler {
// 
// 	@Override
// 	public void onAuthenticationSuccess(HttpServletRequest request,
// 			HttpServletResponse response, Authentication authentication)
// 			throws IOException, ServletException {
// 
// 		String context = request.getContextPath();
// 		String fullURL = request.getRequestURI();
// 		String url = fullURL.substring(fullURL.indexOf(context)
// 				+ context.length());
// 
// 		request.getRequestDispatcher(url).forward(request, response);
// 	}
// 
// }
// 
// Path: src/main/java/security/service/base/AuthTokenGeneratorService.java
// public interface AuthTokenGeneratorService {
// 
// 	String generateToken(Authentication authentication);
// 
// 	public String[] decode(String token);
// }
// 
// Path: src/main/java/security/service/base/AuthTokenService.java
// public interface AuthTokenService {
// 
// 	AuthToken create(AuthToken authToken);
// 
// 	AuthToken update(AuthToken authToken);
// 
// 	AuthToken findUserByTokenAndSeries(final String token, final String series);
// 
// 	void deleteByTokenAndSeries(final String token, final String series);
// 
// 	void deleteExpiredTokens();
// }
// 
// Path: src/main/java/security/service/impl/NoOpAuthenticationManager.java
// public class NoOpAuthenticationManager implements AuthenticationManager {
// 
// 	@Override
// 	public Authentication authenticate(Authentication authentication)
// 			throws AuthenticationException {
// 		return authentication;
// 	}
// 
// }


import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import security.constant.Constant;
import security.entity.AuthToken;
import security.handler.TokenBasedAuthenticationSuccessHandlerImpl;
import security.service.base.AuthTokenGeneratorService;
import security.service.base.AuthTokenService;
import security.service.impl.NoOpAuthenticationManager;
package security.filter;





/**
 * @author abidk
 * 
 */
public class TokenBasedAuthenticationFilter extends
		AbstractAuthenticationProcessingFilter {

	protected final Log logger = LogFactory.getLog(getClass());

	private final String TOKEN_FILTER_APPLIED = "TOKEN_FILTER_APPLIED";
	private AuthTokenGeneratorService authTokenGeneratorService;
	private AuthTokenService authTokenService;

	public TokenBasedAuthenticationFilter(String defaultFilterProcessesUrl,
			AuthTokenGeneratorService authTokenGeneratorService,
			AuthTokenService authTokenService) {
		super(defaultFilterProcessesUrl);
		super.setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher(
				defaultFilterProcessesUrl));
// Path: src/main/java/security/constant/Constant.java
// public interface Constant {
// 
// 	String HEADER_SECURITY_TOKEN = "X-AuthToken";
// }
// 
// Path: src/main/java/security/entity/AuthToken.java
// @Entity
// @Table(name = "auth_token")
// public class AuthToken extends AbstractAuditableEntity {
// 
// 	private static final long serialVersionUID = -9001508296580395084L;
// 
// 	private String token;
// 
// 	private String series;
// 
// 	@ManyToOne(fetch = FetchType.EAGER)
// 	@JoinColumn(name = "user", nullable = false)
// 	private User user;
// 
// 	public String getToken() {
// 		return token;
// 	}
// 
// 	public void setToken(String token) {
// 		this.token = token;
// 	}
// 
// 	public String getSeries() {
// 		return series;
// 	}
// 
// 	public void setSeries(String series) {
// 		this.series = series;
// 	}
// 
// 	public User getUser() {
// 		return user;
// 	}
// 
// 	public void setUser(User user) {
// 		this.user = user;
// 	}
// 
// }
// 
// Path: src/main/java/security/handler/TokenBasedAuthenticationSuccessHandlerImpl.java
// public class TokenBasedAuthenticationSuccessHandlerImpl extends
// 		SimpleUrlAuthenticationSuccessHandler {
// 
// 	@Override
// 	public void onAuthenticationSuccess(HttpServletRequest request,
// 			HttpServletResponse response, Authentication authentication)
// 			throws IOException, ServletException {
// 
// 		String context = request.getContextPath();
// 		String fullURL = request.getRequestURI();
// 		String url = fullURL.substring(fullURL.indexOf(context)
// 				+ context.length());
// 
// 		request.getRequestDispatcher(url).forward(request, response);
// 	}
// 
// }
// 
// Path: src/main/java/security/service/base/AuthTokenGeneratorService.java
// public interface AuthTokenGeneratorService {
// 
// 	String generateToken(Authentication authentication);
// 
// 	public String[] decode(String token);
// }
// 
// Path: src/main/java/security/service/base/AuthTokenService.java
// public interface AuthTokenService {
// 
// 	AuthToken create(AuthToken authToken);
// 
// 	AuthToken update(AuthToken authToken);
// 
// 	AuthToken findUserByTokenAndSeries(final String token, final String series);
// 
// 	void deleteByTokenAndSeries(final String token, final String series);
// 
// 	void deleteExpiredTokens();
// }
// 
// Path: src/main/java/security/service/impl/NoOpAuthenticationManager.java
// public class NoOpAuthenticationManager implements AuthenticationManager {
// 
// 	@Override
// 	public Authentication authenticate(Authentication authentication)
// 			throws AuthenticationException {
// 		return authentication;
// 	}
// 
// }


// Path: src/main/java/security/filter/TokenBasedAuthenticationFilter.java
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import security.constant.Constant;
import security.entity.AuthToken;
import security.handler.TokenBasedAuthenticationSuccessHandlerImpl;
import security.service.base.AuthTokenGeneratorService;
import security.service.base.AuthTokenService;
import security.service.impl.NoOpAuthenticationManager;

package security.filter;





/**
 * @author abidk
 * 
 */
public class TokenBasedAuthenticationFilter extends
		AbstractAuthenticationProcessingFilter {

	protected final Log logger = LogFactory.getLog(getClass());

	private final String TOKEN_FILTER_APPLIED = "TOKEN_FILTER_APPLIED";
	private AuthTokenGeneratorService authTokenGeneratorService;
	private AuthTokenService authTokenService;

	public TokenBasedAuthenticationFilter(String defaultFilterProcessesUrl,
			AuthTokenGeneratorService authTokenGeneratorService,
			AuthTokenService authTokenService) {
		super(defaultFilterProcessesUrl);
		super.setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher(
				defaultFilterProcessesUrl));
		super.setAuthenticationManager(new NoOpAuthenticationManager());