// 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/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();
// }


import java.security.SecureRandom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.codec.Base64;
import org.springframework.security.web.authentication.rememberme.InvalidCookieException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import security.entity.AuthToken;
import security.service.base.AuthTokenGeneratorService;
import security.service.base.AuthTokenService;
package security.service.impl;




/**
 * @author abidk
 *
 */
@Service
public class AuthTokenGeneratorServiceImpl implements AuthTokenGeneratorService {

	private static final String DELIMITER = ":";

	private SecureRandom random = new SecureRandom();

	public static final int DEFAULT_SERIES_LENGTH = 16;
	public static final int DEFAULT_TOKEN_LENGTH = 16;

	private final int seriesLength = DEFAULT_SERIES_LENGTH;
	private final int tokenLength = DEFAULT_TOKEN_LENGTH;

	@Autowired
	private AuthTokenService authTokenService;

	@Transactional
	@Override
	public String generateToken(Authentication authentication) {

		security.bean.User user = null;

		if (authentication == null) {
			return null;
		}

		if (authentication.getPrincipal() instanceof security.bean.User) {
			user = (security.bean.User) authentication.getPrincipal();

		}

		final String token = generateToken();
		final String series = generateSeries();

// 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/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/AuthTokenGeneratorServiceImpl.java
import java.security.SecureRandom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.codec.Base64;
import org.springframework.security.web.authentication.rememberme.InvalidCookieException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import security.entity.AuthToken;
import security.service.base.AuthTokenGeneratorService;
import security.service.base.AuthTokenService;

package security.service.impl;




/**
 * @author abidk
 *
 */
@Service
public class AuthTokenGeneratorServiceImpl implements AuthTokenGeneratorService {

	private static final String DELIMITER = ":";

	private SecureRandom random = new SecureRandom();

	public static final int DEFAULT_SERIES_LENGTH = 16;
	public static final int DEFAULT_TOKEN_LENGTH = 16;

	private final int seriesLength = DEFAULT_SERIES_LENGTH;
	private final int tokenLength = DEFAULT_TOKEN_LENGTH;

	@Autowired
	private AuthTokenService authTokenService;

	@Transactional
	@Override
	public String generateToken(Authentication authentication) {

		security.bean.User user = null;

		if (authentication == null) {
			return null;
		}

		if (authentication.getPrincipal() instanceof security.bean.User) {
			user = (security.bean.User) authentication.getPrincipal();

		}

		final String token = generateToken();
		final String series = generateSeries();

		AuthToken authToken = new AuthToken();